March 2011 Archives
-
Internet Explorer 9 was recently launched and received an overwhelming amount of positive reviews as well as a nice welcome from the developer community.
My thoughts about it remind me of a story I heard many years ago.A child's obnoxious behavior upsets his father on a daily basis. The afflicted parent would sometimes hammer a nail onto a door. After a while the curious child asked about the nails - "I've put a nail every time you made a bad deed", his father sorrowly answered. Later on, somewhat troubled, the child told his father "Look, I've thought about it and I don't want to upset you again, but for each day I behave you will take out a nail." The two were in agreement and as the days passed the parent would remove one nail after the other. One day the boy noticed that the nails were all gone. Happy, he called out his father "Look, I made it, the door doesn't have any more nails". "You're right", his father answered, "but what about the holes?"
While it's really nice that IE is once again a good browser, it's just not going to give me back all the nights I lost hacking layouts for the better half of the last decade. -
I can honestly say that the main reason for helping others is selfishness, because you see there's a certain feeling of accomplishment when helping someone with an issue that eluded me as well.
A few years ago I found my self spending quite some time on various forums. While it was mostly procrastinating I had the distinct feeling that I was actually contributing to something. After moving out from my parents house, on to the big city I met some very cool people, that had a lesser interest in an online presence and more of a hands on approach to tackle real problems. I was now reading the source code rather then browsing outdated blog posts.
One day, having a project with a tighter deadline and a long commute I was working from the comfort of my home trying to finish up. I was almost there, just needed to implement a pure javascript survey module by detecting the most common element in an array. Not a difficult task per se, but once you begin to feel tired, lousy code doesn't look that bad anymore. I took a short nap to rejuvenate my strength, but before doing so also asked a question on this new website popping up in the results all the time, named StackOverflow. Upon waking up I found a few answers, but most importantly they worked. It almost felt like cheating.
Since then I answered other people questions on SO every now and then. Reward points are being granted by doing so which feel quite nice. What didn't felt so nice was that answers to difficult questions were more unlikely to be voted up, probably because few had the knowledge to understand them, while easier common day issues would get way more attention. Suffice to say that the very system that made it so great was also its greatest fault. As post quality dropped, so did my interest.
Granted, I found many gems there, but it's time to walk away and wait for the "next thing". -
I recently worked on a project that generated some custom images using RMagick. There were several texts involved with some spanning over multiple rows. While RMagick does provide a caption method that wraps the text, I found it rather limiting. So instead I used the more powerful annotate method which allowed me to set my own font and text position.
Having just a canvas (an RMagick image for background), I started by creating a new drawing object:drawing = Magick::Draw.new
I then used a method for splitting the text into rows (stolen from a rails helper):def word_wrap(text, columns = 80)
text.split("\n").collect do |line|
line.length > columns ? line.gsub(/(.{1,#{columns}})(\s+|$)/, "\\1\n").strip : line
end * "\n"
end
Writing the actual text was easier than I initially thought.position = 80
word_wrap(my_long_text, 90).split(\n).each do |row|
drawing.annotate(canvas, 0, 0, 200, position += 20, row)
end
The text is being added at the 200, 100 coordinates, with a line height of 20. That's it.