JetPack Summary 2011

So popped open my emails on January 1st to find an email from JetPack. JetPack being a collection of plugins from WordPress to install on Self hosted blogs, that among other things includes a stat tracker.

The email in question was something that JetPack had automatically generated as an Annual Report on views of my blog.

You can see mine here.

Quite an interesting read, and I’m not really surprised that my some of my most popular posts are from 2010, really just means I need to blog more. (Hence really the reason for writing a blog entry about it, since I do aim to post more now)

But the most interesting thing of all, is the little Fireworks jQuery plugin, which WordPress have also released as open source for others to use and play with. Included on the review page includes a nice little stats/current plugin output to show you how effective/how well its all running.

My Google Chrome is currently scoring 4%, but my iPad safari clocks in at 30% (but then I do have a lot of tabs open right now).

It’s a nice way to review your blog from the year, so it you are running JetPack, its worth a read.

But it is really just a bit of a sales gimmick when you get to the bottom and see what WordPress has planned.
Looks like its going a bit more Tumblr-y. We shall see

Facebook Credits, the Order ID, and dealing with large integers in 32 bit PHP

So, currently at work I’ve been rewriting all our Payment Gateways for Your Members. Making them more better Class based an abstracting out the common functions to a base class, to save memory footprint and code etc.

And came across a problem when rewriting the Facebook Credits handler.

The order ID that gets passed around, as well as the Application ID is too long for a 32 Bit PHP installation to handle when treating it as an Integer.

So a number like “239724439419867” was ending up as “1.7592246582797E+14” when stored/processed, or converted to a string.
Now the obvious way to process this is to convert it to a string another way, which is somewhat difficult since before you even start it is in a format that you can’t handle.

The saving grace here is the fact that data is passed to you as a JSON packet (aside from the fact the Order ID is in the $_POST variable and thus a string, so I could of used it from there).

This led to me to look at the JSON packet, which starts as a string but when decoded the large integers are still a larger integer than can be processed (whether you json_decode to a Array or to an Object, the problem persists). So I thought about how to process the raw JSON packet and make sure the order ID, and other large integers are treated as strings.

If you look at a Raw JSON packet you can easily spot whats a string, integer, object or array.

Take this example Facebook Credits JSON Packet, (wrapped for readability):

{"order_id":239724439419867,"buyer":197803678,"app":148748711865470,
"receiver":197803678,"amount":5,"update_time":1320075413,
"time_placed":1320075408,"data":"","items":[{"item_id":"<item_id>","title":"Post",
"description":"A New Purchasable Post",
"image_url":"<some url>","product_url":"<some other url>",
"price":5,"data":"<data>"}],"status":"<status>"}
  • order_id is an integer as it has no ” around it
  • status is a string as its surrounded by “
  • Items is an array as its surrounded by [, in this case containing a single object, entries/items are comma separated.

So after thinking about this I decided the best way to sort this out was to convert the integers in the raw JSON packet to strings before decoding.

In pseudo code.

Lop off the { and } from the start and end
Explode around ,
array walk each item
split on :
check if there are no " in the second bit
if none wrap in "
glue back together

Something alone the lines of:

function largeint($rawjson) {
  $rawjson = substr($rawjson, 1, -1);
  $rawjson = explode(',' , $rawjson);
  array_walk($rawjson, 'strfun');
  $rawjson = implode(',', $rawjson);
  $rawjson = '{', . $rawjson . '}';
  $json = json_decode($rawjson);
  return $json;
}

function strfun(&$entry, $key) {
  $data = explode(':', $entry);
  if (FALSE === strpos($data[1], '"')) {
    $data[1] = '"' . $data[1] . '"';
    $entry = implode(':', $data);
  }
}

I’m not sure in terms of memory footprint if its cheaper to do a substr of $data[1] and check if its a ” or not.
I suppose it could test the string length of the detected integer to see if its invalid/unable to process, but then you would be performing a string function on an integer and again the problem would arise.

But as a block of code is does the job, its obviously not ideal for all situations, since in this case I want the integer as a string, I’m not using it for math, but if I did, we probably need to do some bizarre unpack-ing or something.

Any opinions or improvements give us a comment below 😀

Thoughts on working on a different computer when your normal one is not available

So currently my Mac Book Pro is in with Clockwork Leeds getting its Hard Drive replaced as it failed/has failed/is failing.

So currently at work, I am sans my normal Development machine and find myself on the Mac Mini server that sits and does our File Server and System Monitoring.

Its quite odd having to get used to a system that for starts is the Server build of Mac OSX as well as having none of my personal preferences.
Its bringing to light how slightly useless some of the things I have setup on my Personal machine are that I thought were useful.

For example, I’m stuck with a single screen, so no dual screen lovely-ness. So I’m very restricted to the screen real estate I have available.
So not having new Terminal Windows opening to fill half the screen like on my mac is quite useful. Whereas before having the secondary screen with two terminal windows full height, half width was the norm, as well as using a little app I’ve forgotten the name of which allows me to press ctrl + ~ to get a window appear from the top, is a bit of a pain, but resolved now with having three default sized terminals and chrome open.

So far its seemed to work just about fine like that.

I also find myself using Spaces/Expose a lot less, I’m doing a lot less jumping between spaces all the time. But I also don’t have the “App only opens in space x” setup so I get a lot less forced jumping.

Finally tho I miss my music collection, so I’ve switched to plugging my headphones into my iPad and listening to Spotify. Tho I could just plug in my external drive thats in the office and have most of my older music on hand….

I’m also on a different desk which is nice.
I’m not by the door and have the window behind me and I’m in the corner.
I quite like it over here. Seems a bit more separated from everyone else. Which is a good thing and a bad thing in its own right.

I love working with the team, *can’t think of right words to express feelings will just skip to post summary*.

Summary

My Mac is in the repair shop getting fixed.
The hard drive was failing and is pending spare parts from Apple.
Clockwork are amazing for Apple Repairs.
I’m in a corner at work
I have no home machine to really play or work on. (I made my home windoze laptop blue screen just by looking at it….)

I watched last nights Torchwood on my iPad using the BBC iPlayer Application and it worked perfectly.

Finally my local dev environment is shafted as that was my Mac Book Pro. Luckily everything is in offsite repo’s and I have a Server in a Server Room down the corridor to talk to 😀

-End-

My Leeds Hack 2 Project

Thought I would write a blog post about what I built in 24 hours for Leeds Hack 2 last weekend. I kinda got distracted last week and not had the time to write this post.

You can look at all the projects that people finished over on the Leeds Hack Website.

So what did I write

I decided to write something that I had been pondering about for a while. It’s called Spotify Roulette and revolves around the idea of crowd sourcing a new artist or area of music to listen to.

Originally it started off with me posting on Twitter quite a while back asking for something new to listen to, to which @Stanton responded with Hybrid. (I can’t find the original tweet on twitter but it’s here on Spotwitfy) Which are actually quite nice to listen to and I have a nice Spotify playlist to listen to.

I was wondering if there was a way to automate this.

So thru the combination of the Twitter and Spotify Meta Data API’s, means I can post out to Twitter, await a response, parse out the Artist and then pop open Spotify with a random track by that Artist and if the requester wants a playlist can be generated, and thru a limitation in Spotify, drag and dropped into Spotify to listen further to the Artist.

In short

In short its pretty straight forward.
Just a handful of calls to a couple of different API end points to get an Artist ID from the name, then their albums and the tracks on these albums. Chuck in a little GeoIP to hopefully check the tracks are available in the requesters’ region.
Grab the first track, pop open Spotify and grab another 10 tracks to make a playlist.

Finally I used Nerf Guns to help demo! Russian Roulette stylee.

Responses

People on Twitter can either response with text, an artist which we parse out the @user and the hashtag word. Then look that up on Spotify.
Or a response can be either an HTTP open Spotify link or a Spotify protocol link. Either to the artist page, track or album.
if it’s the Artist, I can parse out the artist ID and look for albums and tracks.
Currently not playlist urls, but that’s easy to implement.

Technology

So we used,

  • Twitter API, using @Abraham Twitter oAuth Library
  • Spotify Meta Data API
  • MaxMind GeoIP
  • jQuery and jQuery UI
  • Rick Astley
  • Nerf Guns

Give it a Go

Give it a go and offer me some feedback.
Watch out for Rick Astley tho. He likes to crop up every now and again….

It’s still a little rough round the edges in terms of theme/layout.

Spotify Roulette (http://spotifyroulette.com/)

Future

Hopefully if people like it and use it I can expand further.

Perhaps use Facebook to share playlists, or another way to crowd source a new artist. And if Spotify release a HTTP API for generating and saving playlists then incorporate that too.

Jetpack by WordPress

So at work today we have this posted in our communal chat.

http://jetpack.me/

Took at look at the site. Figured out what it was. Its a nice little collection of plugins that Automattic make bundled into one plugin, the idea being that these are the plugins installed on Hosted blogs over at WordPress.com. I only used the WordPress.com site stats plugin, (since the whole package is available as separate plugins), which out of them all is the only one that needs linking to WordPress, so makes you wonder why after installing JetPack I need to link up to WordPress.com when the only plugin from the pack that needs it is already linked…..

Anywho that aside its a nice little plugin with a nice interface:

So hats off for that and the simple ness of installing. Just a shame that according to JetPack.me FAQ’s all the stand alone plugins are coming to a end and users will need to get JetPack in the future.

On a side note I tested the plugin on a separate domain and got this:

Twas nice of JetPack to deactivate the old/current WordPress.com stats plugin I had installed to stop conflicts 😀