Every now and then, I feel the urge to program something I find interesting. The success of these programs is quite varied, but I have fun making them and thats whats important to me. Most of these used to have their own posts, however as I’ve just updated my blog, there all in a list below, with links to demos and the source. However, as I switched servers, some of these projects have suffered, this is due to API keys needing updating, and slight file structure changes.
This Post is going to take a while to finish, Im going to come back to it and split it up.
Reddit Post Tagger
A while ago there was a post on reddit.com/r/iama about making it easier to search for posts and about the ability to tag posts. Well this post was made in the summer, and I didn’t have too many productive things to do at that time, so I gave it a shot.
Here it is: Warning, this is pubically accessible, and people post some weird things on reddit, so there is some ‘interesting’ content on here:
http://jonnyfairfull.co.uk/reddit/
This wasn’t too hard to make, ketralnis, a reddit admin at the time created a json dump of all the past iama posts (27MB of text) and sent it my way. I then set up a small php script to organise the data into a MySQL database so it could be indexed & searched. This is just a really simple 2 table database, a table for posts, and a table for tags. The interface is dead straight forwards as well, there is the home which allows you to do a full text search of post titles, find a random post and browse by recent tag through the tag cloud (tag searching never got implemented, more on that later). Then there is the view post page, which displays the reddit.com/r/iama post in an iframe and a bar at the top allowing you to add tags and navigate posts.
Tags are added through a simple ajax call back to the server, so you can add a bunch of tags real quick, and not have to reload the page, just type it in and hit enter and its added unfortunately this project broke down, the other Rreddit user who posted asking if this could be done, just disappeared and I moved on. Still not a bad little project.
Some simple code (not really worth putting on github):
The HTML doesn’t seem to get any formatting on paste bin, sorry about that
uHack Submission – What You Talking about, WYTA?
This really deserves a post of its own, however moving it across servers has broken it quite nicely, this is largely due to API keys expiring, however theres also an error in one of the JS files which appeared from somewhere.
This was quite a complex project, but it’s homepage has quite a good explanation:
Remember its still quite broken: http://jonnyfairfull.co.uk/uhack/
In short (as possible) WYTA is a translation proxy, you send your request to WYTA, it forwards that request to the site you want. Pulls down the whole page and parses it to make all the links absolute (so the page renders properly) . Then all the text from <p>’s is parsed and sent off to the Yahoo! Term Extraction API, this returns all the big/scary words that are to be pre-emptively translated. These are then sent off to Google to get translated into the desired language. The text of the page is then altered, so that the big/scary words are surrounded in a <span> which when clicked changes the word to its translated version. I hope that made some sense…
There is also quite a bit going on client side as well, WYTA allows users to translate entire paragraphs. To do this you double click the paragraph, which is then sent off to Google with an ajax request to be translated, when its returned, the translated paragraph is shown beside the original in an overlay, allowing the user to compare the 2, and hopefully learn something about the language (Google started doing something similar a few months after we finished, we had no influence over them, it was just cool to know we were along the right lines).
Broken bits: Single word translation has died, I’m not sure why and I’m going to look into it soon. Also the definition of single words has died. Originally when you clicked a pre-emptively translated word it would appear in the nav bar at the top. If you click the word at the top, WYTA used to send an ajax request to a YQL script to go grab the first paragraph from the associated Wikipedia article in the right language, However the API key has expired, so I will have to sort that out too.
This project was just a hack, so its not particularly solid as it was completed on limited time however I was pretty pleased with the outcome.
Try it out here: http://jonnyfairfull.co.uk/uhack/, if you want to go to a page of your choosing, just click the wire globe icon on the nav bar and type in the address.
<canvas> Experimentation
Just like a lot of folk who know how to use JavaScript, I’ve had fun messing about with the canvas tag, making silly games.First off I made a really simple side scrolling shooter, nothing spectacular, but I had fun making it
You have 5 lives, click the box to star, refresh to play again: http://jonnyfairfull.co.uk/phys/
This was just an experiment to see how simple hit detection could be implemented in JavaScript and I really like side scrollers…
I also made a little car driving thing to play with acceleration and deceleration, it uses some of the original GTA graphics which I probably shouldn’t use. Also it could really do with some optimising, the JavaScript in there is pretty sloppy (JSlint does make you cry…)
http://jonnyfairfull.co.uk/sts/
I took this idea a little further and thought ‘hey, wouldnt it be cool if you could control that with your phone…’ Turns out thats pretty hard to do with ajax polling, but I had a go.
It’s best to open these in 2 separate browser windows, and make the controls into a small window:
Game: http://jonnyfairfull.co.uk/msts/
Controls: http://jonnyfairfull.co.uk/msts/ctrl.htm The controls are really slow to respond, and its dead easy to loose the car off the side of the screen, but its still pretty cool controlling one browser window from the other.
You can just view source to get most of the code for these games (chrome developer tools are great).
More projects to add later…