-
How to make an URL-shortening service
Posted on June 24th, 2010 No commentsRecently I was a little bit bored. And always when I’m bored I gonna start working on small projects just to drive away boredom. What I did this time was an URL-shortening service. URL-shortening service? What’s that? I’m pretty sure, most of you have used one before. Everybody hates long addresses like http://www.example.com/this/is/a/horrible/long/url.php?id=laksdfjlkfadjoweiu - they are extremely uncomfortable, especially when you want to copy them into an email or share it on a service like Twitter. So URL-shortening services like tinyurl.com come in handy, as they shorten an address like above to something like http://tinyurl.com/AB734 (this is just an example).
These services use special algorithms to shorten URLs. Although I was using this service regularly, I was never paying attention to how it is achieved. Until yesterday. As I already mentioned I was bored. And suddenly it struck me - why not build an URL-shortening service? This can’t be so difficult, I thought. So I started to google a little bit and then started to code. And to be honest, it was not that difficult. In this blogpost I gonna show you how I wrote my URL-shortener.
-
Python-howto: converting a string into a tuple
Posted on October 6th, 2009 5 commentsRecently I had the problem to convert a string with coma-separated values into a tuple. Unlike a list a tuple is an immutable way to represent data, once it is created its values cannot be changed. Googling just brought up some really weird solutions which I either didn’t like or they did not work anyway. So I played around a little bit and came around with a single line solution that should work sufficiently.
Lets assume you have a string with coma-separated values like ‘value1, value2, value3′ and you want to convert it into a tuple (value1, value2, value3). A direct conversion from string to tuple is not possible, however there is a convenient way to create a list from a string using the .split() function. Lists can be easily converted into tuples. And this is basically the solution: convert the string into a list and then into a tuple. Putting it all together into a single line of code we end up with
s = 'bla, blub, blubber'
t = tuple(s.split(', '))
print t
# ('bla', 'blub', 'blubber')Please note that the argument for the split-method is a comma and a blank. The blank has to be added as the blanks in the string are considered as valid characters. If you just use a comma as an argument, the blanks will be part of the resulting tuples (ie. ‘ blub’ instead of ‘blub’).
So the conversion is not such a big mystery
-
Moblin - a new Linux experience?
Posted on May 24th, 2009 No commentsRecently I learned about Moblin, which is a new desktop for Linux, taylored especially for Netbooks. To be honest, what I saw looks very promising. I don’t wanna say that this could be the Linux killer-app we all were waiting for (like the tale we hear every year that this year is gonna be the year of the Linux desktop), but it could definitely make Linux accessible to a broader audience. AFAIK the Moblin project is supported by Intel, so the support of the greatest chip-manufacturer could also be very helpful.
But why not take a look at Moblin for yourself?
This is one of the most professional adds I have ever seen for Linux. Being a technical person I never underestimated the power of good marketing. And if you look at the features of Moblin it has everything a modern desktop should have: a shiny user-interface, nice graphical effects (not that they important for functionality, but they make it interesting) and it seems that it is easy to use. At the moment I’m very happy with my Macbook and I doubt that I will drop OSX for another operating system on the desktop in the next years, but I will most certainly give Moblin a try. And should I ever buy me a Netbook I’ll most definitely get me one with Moblin installed.
I’m very anxious what will happen to this project? Will it proove successful or will it fail like other projects before? We will see…
-
Grails 1.1 does not allow the classname Category
Posted on April 18th, 2009 4 commentsThere are tutorials around for older versions of Grails that use Category as a class name. However since v 1.1 this name collides with the Groovy-class groovy.lang.Category. If you use it you get the error “ERROR plugins.DefaultGrailsPlugin - Cannot generate controller logic for scaffolded class interface groovy.lang.Category. It is not a domain class!” It took me two hours to find out about that. Even googling was not very successful. As you can imagine it drove me mad. So don’t use Category, even if you want to create a category class! Use something else…


