Coding for Fun
I really like coding, for me it’s not just something that pays my bills but it’s specially something that I enjoy and have loads of fun by doing it.
During the last year I’ve dedicated a bit of my free time to develop some ideas, proofs of concept and learn new languages by writing real code instead of just reading artificial tutorials. So, as a kick-off for this new blog I’d like to talk a little about some of my pet projects that I’ve done recently and then share some of my ideas and knowledge I’ve acquired by doing them.
Rasmus Lerdorf himself uses to say PHP is not a language for computer scientists, and indeed it’s not. It “just works”, but it also lacks in many points regarding elegancy and academic principles. Although I’ve been working with it for many years now and so I decided to check what could be done with it in terms of algorithms and data structures, so every time I remember some classic problem I try to implement in PHP and add to this repo.
What I’ve practiced/learned: I’ve remembered some classic algorithms and also took a look on PHP’s native Data Structures
As soon as I’ve heard about Node.js and all its “wonders” I’ve decided to give it a try, so this was my first code using Node and Express.
It basically gets shortened URLs, makes an HTTP GET request and fetches the Location HTTP header of the response, helping you to don’t be RickRoll’d :)
What I’ve practiced/learned: It was my first contact with Node, so it helped me get the hang of it.
It’s a quite simple project. All it does is handle the HTTP requests to calculate a hash for the URLs sent by POST (with this really simple hash function) and store it in Redis. And when a shortened URL is requested through GET, it retrieves from Redis and returns an HTTP response redirecting the user to the normal URL.
What I’ve practiced/learned: I got my first contact with two things I really started enjoying later on, and those are Sinatra and Redis. Also I’ve deployed it in Heroku and used it for some time as my personal url shortener frnb.in (no longer online)
After playing with Sinatra and really having fun doing it, in a long airplane trip I decided to make something to help time pass. So I’ve built this micro-framework that’s just a simple clone of Sinatra and all it does is map URLs to callback functions and routes the requests to execute those functions.
It’s ridiculously simple but can be a nice way to build simple REST interfaces.
What I’ve practiced/learned: It was extremely simple, nothing really new :)
Node.js is not a silver bullet as many people think, but it’s really cool for this kind of application that is meant to be fast dealing with sockets and possibly a lot of open connections. I also took the chance to have a first contact with CoffeeScript.
I’ve also started implementing a cache expiration and memory management engine using the LRU principle but it’s still not ready.
What I’ve practiced/learned: I’ve enjoyed a first contact with CoffeeScript and started thinking about efficient ways to manage memory (still in progress)
Go is the language that most caught my attention recently. It has everything I like in a programming language, but unfortunately I couldn’t dedicate more time to really learn it.
Although during one specific afternoon I’ve decided to go through its tutorial and build something on my own, so I’ve implemented this text files indexer.
I haven’t researched how Fulltext indexes work, but if they don’t do any magic there, I assume it’s not so different from what I came up with.
What I’ve practiced/learned: Go is an awesome language, I really got amazed with it and also this small project made me think about efficient ways to index content.
Looking for some brazilian news at Globo.com I noticed they were using a nice way to save bandwidth by loading low-res images in the whole site and substituting by the originals in hi-res mode only when the images are in the browser visible area.
So I came up with this implementation for the idea in CoffeeScript that is not compatible with older versions of IE, but is enough to prove the concept.
What I’ve practiced/learned: It was quite a simple project that I did in two hours or something, the new thing I’ve learned with it was mainly the DOM events I needed to handle.
And that’s all! The idea of this post was mainly show that coding in your free time is not just fun but you can also learn a lot by doing it!