Archive for the Code Category

Xbox Achievements

As i’m now tracking all of my Xbox achievements, see previous post*, i thought it’d be good to get some sort of viewing page going. So now on the right > you’ll see my last few achievements that I have unlocked. This is simply hardcoded into the sidebar as learning and writing a WordPress plugin was overkill for what I wanted.

Secondly i’ve added a bigger viewing page, click the link in the menu above. You’ll be greeted with a drop down, that lists every game i’ve played on the Xbox. Select a game and every achievement for that game is displayed via some ajax. I need to tweak it a bit as its a bit ugly atm, its breaking the sidebar :/.

Edit. *Realised I haven’t done a blog post on my Xbox Achievement tracking. Better get that done….

Xbox Twitter

Something I created last week was a xbox status twitter updater (I think i’m obsessed with Twitter atm), the idea was to send a tweet to my friends and me when one of us came online. A couple of hours later it was done.

Torrent Status via Twitter

I’ve been wanting to use twitter to interact with my uTorrent downloads for a while. I already have a system set up that tweets me when a download has finished, but I wanted more functionality, ideally the ability to add torrents and get the overall status of my downloads.

Thankfully uTorrent have created a nice little api that lets you do pretty much everything you would want, I used this uTorrent Python library, that lets you interact with the uTorrent api. I then made a simple c# win forms app (needs changing into a command line app really) that would make various calls to the Python library. Initially the only functionality is the current status of downloads, but now I have the basics in place I can add features fairly easily.

At the moment the application reads my latest tweets, I have already created some code todo this for my Home Automation System, and then when a tweet matches the ‘status’ command, I fire off the call to the api to get the status of every download in my client. The returned list is then parsed, and any active downloads are extracted and returned to the main method. This then processes the returned strings and replies back to my original tweet with the status of my downloads.

The next step is to add the ability to add new torrent files straight from a tweet, this should be fairly straightforward, the tweet would contain the location of the .torrent file, the system would then make the call to the uTorrent api with the location of the file to be downloaded.

Text to Voice Calling

This weekend me and @Bonxy spent some time adding some features to the Bonxy SMS site, that I posted about recently. My aim was to add in voice calling as well, so users could write out prank messages or reminders and send them to friends or family. To do this I used, they provide a cloud based SMS/call api, allowing you to make calls, receive calls, conferences and of course send text message.

text to calling

The actual integration was pretty straightforward, use their PHP library’s, set up an application and hey presto you have voice calling and answering. I’m thinking of using the service to create a cheap conference system, all users call into the local rate number, therefore using your own contract minutes.


I’m also hopefully going to transfer the technology to a few other sites, to provider reminders and wake up calls/alarms etc.

Torrent Automation

One of the main reasons for buying a server was for the ability to leave a torrent client running 24/7, now I can. With uTorrent ( and all of its advanced options ) I can now download torrents all of the time, one of the drawbacks to this is the drain of bandwidth on the rest of the network. So I’ve set uTorrent to only download at full speed during the night, and then very limited during the daytime, this was I shouldn’t notice any impact on my network.

uTorrent Schedule

Another nice feature of uTorrent is the auto download of torrents when placed in a specific directory, so this means I can quickly add a torrent file to my NAS drive and within a few seconds the torrent is downloading. This and with addition of the RSS feed feature allows me to quickly download TV and films without much effort.

File are then automatically moved to the correct directory, based on the torrents labels, so that my Boxee Box will pick up the media without me intervening.

Another idea I had (well @Bonxy suggested) was to get twitter updates when downloads have finished. I had already dealt with twitter messages when creating my home automation system for my dissertation. So it was just a quick job of copy a bit of code and creating a simple console app that took the tweet params.

Twitter Code

I then edited my uTorrent options to ‘run a program’ when a download completes, I just simply pass the twitter message with the torrent name, and within a few seconds I get a tweet (plus email and free SMS) with my download details. I then added the same call to the status changed option in uTorrent.

tweet Image

Obviously I cancelled the above download as downloading content that isn’t freely available isn’t legal. :)

Resize An Image

For the imgUp tool I had to resize an image to various different sizes, after searching on the web for a while I came accross this nice little function.

public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
            System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

            // Prevent using images internal thumbnail

            if (OnlyResizeIfWider)
                if (FullsizeImage.Width <= NewWidth)
                    NewWidth = FullsizeImage.Width;

            int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
            if (NewHeight > MaxHeight)
                // Resize with height instead
                NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
                NewHeight = MaxHeight;

            System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

            // Clear handle to original file so that we can overwrite it if necessary

            // Save resized picture

The method take several parameters, first the file location of the original file, then the location for the altered image to be saved. Then the width and height of the new image, finally you can set whether the image will be resized only if the width is larger than the resized size, this prevents the image from being stretched.

ResizeImage("c:\img1.jpg", "c:\img1-altered.jpg" , 640, 480, true);

I found this snippet here and here.