Apr 24, 2009

My Problems with Twitter

While many people claim that Twitter ate their blog, I can't really say it has eaten mine - while I have been much more quiet lately than 6 months ago, I think it more due to lack of enthusiasm/inspiration/commitment than anything else. I have several reasons why I'm not a huge fan of Twitter for "microblogging", at least compared to a lot of the other people who are on it. Don't get me wrong, it is great for small little things, but I don't think it is a great substitute for an actual blog.

Why I don't like it:
  • Lack of expressiveness - while some people could say that Twitter makes them more efficient in saying what they want to say, I think shortening your message to 140 characters really limits what you can say. A lot of the time I have stuff to say that is too short to make into a real blog entry, but I'd like to talk about in more depth than a simple tweet (perhaps I should lower my minimum blog entry length, but for some reason I don't like to write really short ones. Not sure why).
  • The Chaos - It is completely chaotic. I forget to check Twitter every day. In fact, sometimes a week goes by. What happens when I finally do remember to check is I sign on and there's absolutely no way I can see what people have said except for in the last few hours. Fortunately the good response to this was to just stop following a whole bunch of people who just spammed out tweets like there's no tomorrow, so now my timeline shows probably a day or two worth of tweets - though still no good if I haven't checked it in a week. In fact, just today I found out that several weeks ago someone sent me a "message" - not a real direct message mind you, but an @robbrit message - with a link to a cool book and I just got it today because I was messing around the Twitter Search API. If you're reading this, thanks! It is definitely interesting!
  • Level of Satisfaction - This somewhat relates to my first point, but is a bit different. I find that tweeting does not give the level of satisfaction as a good blog entry (I find it odd that I'm saying this, since I tend to tweet more than I blog these days) mainly because with a blog entry I sit down and write something that people may actually care about. While shouting out random things to my followers on Twitter may be temporarily gratifying (just got to work! sitting in my chair now!), there is a deeper feeling of satisfaction when you receive a comment on a year-old article saying how you helped someone out so much, or when someone links you on Reddit because they like what you've written - although there is an awful lot of negative attention from sites like those that really bugs me, but I suppose it is unavoidable on the Internet.
Hopefully there are others that feel the same way as I do. While I don't think that Twitter is bad, I do think that I would prefer to blog more often.

Apr 23, 2009

Jaunty and RMagick

If you're doing Ruby development under the Jaunty and you're using RMagick, make sure that after you upgrade to reinstall the libmagickwand-dev package, and then reinstall the RMagick gem:
sudo apt-get install libmagickwand-dev
sudo gem uninstall rmagick
sudo gem install rmagick --no-ri --no-rdoc
I can imagine there may be issues with other languages too, it seems like Jaunty replaces/upgrades some ImageMagick libraries, so you'll have to patch it up after you upgrade.

UPDATE(Apr. 27, 2010): The latest version of RMagick does not work with the most recent version of Imagemagick in the Ubuntu repository. To install the version of RMagick that does work, you need to use version 2.11:
sudo gem install rmagick --no-ri --no-rdoc --version=2.11

Apr 15, 2009

Installing Steam in Ubuntu

If you're like me and you enjoy video games, one thing you'll miss about Linux is the supreme lack of games for Linux (the only reason I still have a Windows partition is for games). Of course, there are a few good open-source games out there, and some games work beautifully under wine.

Turns out, so does Steam. The fonts are a little messed up, and if you run in a virtual desktop like I usually do (Compiz Fusion has issues with full-screen apps and I'm too lazy to turn it off) then the system tray is a little annoying, but whatever.

To install:
1) Download Steam from steampowered.com.
2) (UPDATE 12/12/2009: Installing wine is a bit tricky in Ubuntu 9.10, see my post for installation instructions.) Install Wine, if you don't have it installed. After it is installed or if you haven't run it before, run it real quick in a terminal (Applications->Accessories->Terminal) by typing "wine" and pressing Enter. This creates the wine folder where your settings go, it's important.
3) Put it in a Wine folder. If you don't have a wine folder, create a folder on your desktop called Wine and then run this command in a terminal :
ln -s ~/.wine/dosdevices/z: ~/Desktop/Wine
Put the Steam installer in that folder, open the folder and run the installer. It should work fine. If double-clicking it doesn't work you, right click on the file and go to "Open with Other Application". Click on "Use a custom command" and in the box that appears type msiexec. Then press Open.
4) Follow the Steam installation instructions. Usually this means you have to click Next a bunch of times.

There, you should now have Steam installed. Keep in mind that not all games work in Wine. You'll have to try different ones (that's what I'm going to do) and see what works and what doesn't, I'll try to post on here if I have to jump through a few hoops to get certain games working properly.

Apr 14, 2009

Accents in Vim

I've been working with localization for work lately, and I've had to put a lot of accents in for French. This is not a huge deal since I have this thing on my desktop PC (forgot what it is called) that lets you put RSuper+accent+key to type an accent (RSuper being the right Windows key) - so RSuper+'+e gives you é.

However on my laptop I don't have this set up and having forgotten what it is called, I can't look it up. Never fear though, Vim has a shortcut key for accents. While in insert mode (or in any mode where you can type a character to be outputted, like after pressing 'r') hit Ctrl+k, the letter to accent and then the accent. So to type a é you hit Ctrl+k, then e, then '. Nice and easy! However for some reason they don't do others as easily, è is e then !, and some others are weird like that too. Oh well.

Apr 13, 2009

Hungarian Notation in Ruby?

Way back when I was first learning to program, I was quickly introduced to the Win32 C API, which uses a lot of Hungarian notation on the variable names. This got really annoying really quickly, especially back then when there was a difference between a "long pointer" and a "short pointer", you'd get stuff like "g_lpasz_..." which means "long pointer to an array of zero-terminated strings, which happens to be a global variable". It can get nastier.
Eventually I dropped this, because in C/C++ you explicitly declare the type of a variable anyway, and the IDE that I used at the time (Visual Studio) would display the type anyway. It was both redundant and slightly verbose, so it didn't really come as a surprise that when I came to Java in university and saw that it did not use this notation that maybe it was worth ditching (it's one of the few things that Java ditched from C++ that I actually agreed with). So now I don't use it when I'm programming C++.

Most of the time these days, I'm not programming in C++. While I still like the language - probably because I haven't found a language that does what it does well better, namely execution speed with OOP/generics - most of the projects I seem to do are better suited to Ruby - there are probably better languages to use for some of the things I do (OORegress would probably be better off in Scala since it does number crunching) but whatever.

As my apps and web apps get more complex however, I'm thinking some sort of very basic type system would be in order. Since in Ruby you can never be really certain what type a variable is (I've been bitten in the ass in Rails by Hash vs. HashWithIndifferentAccess), having some sort of hint to other programmers what type the variable should be would be quite helpful. Just a thought.

Like most things, it is best to use it sparingly. If your Hungarian notation portion has more than say 5 characters in it, it's getting a little long. Plus since in Ruby a parameter may have more than one expected type - in Rails, ActiveRecord::Base#find can take an integer or a symbol for the first parameter - and lists can be heterogeneous there are situations where the system may not be comprehensive enough for what you need. However for 90% of the times, I think it would be an improvement.

Mar 30, 2009

Discovering Fractals: The Julia Set

After my post yesterday about the Mandelbrot set I started digging around a bit more. I discovered this other thing called a Julia set, which is something similar.

It still uses this formula:
zi+1 = zi + c
However where Mandelbrot set started with z0 = 0 and c as the coordinates of the pixel, the Julia set has z0 as the coordinates of the pixel and c as some number. Depending on the c that you pick, you end up with a different picture.

I also looked into colouring it a bit better than black and blue, it is now based on HSV colours instead of RGB. Then if the formula escapes your radius at iteration i, you set the hue of the pixel to (i+b) mod 360 where b is some offset you can choose to change your colour scheme. With b = 0 you get a bright orange background, but I didn't really like it so I picked b = 180 which gives a nice lightish blue background. Unfortunately I'm not completely liking the bright pink/purple of the swirls, anyone know a few things about colour theory and have suggestions?

Here it is centred at 0.35 - 0.33i, with 4x zoom and c = (φ - 2) + (φ - 1)i, φ being the golden ratio:

Mar 29, 2009

Discovering Fractals: The Mandelbrot Set

I read a blog post a while back about content generation in video games, one section of which is terrain generation. One interesting way to generate realistic terrain is using fractals. One of the most well-known and relatively basic fractals is the Mandelbrot set. After reading through this article I decided to write a simple program that generates pictures based on this set.

Here's how the set works. You take a complex number c. You then take a sequence described by the following formula:
zi+1 = zi2 + c
Where z0 = 0. If this sequence is bounded (it does not escape to infinity), then c is in the set, otherwise it is not.

You can display this using a program by taking each pixel in your window and converting it to a complex number. You then test to see if the number is in the set by iterating over it a certain number of times to see what happens. Of course you won't be 100% precise, but with enough iterations you can get a pretty good approximation.

On top of this you can make it look even prettier by tweaking the colour depending on how quickly each point escapes to infinity. If it shoots off into infinity immediately, you make it darker. If it takes a while, then you make it lighter. I used the following formula:
colour = (0, 0, i / n * 255)
Where i is the iteration that the number escaped a certain threshold where the norm of the complex number is greater than this threshold (I used 2 and 3, didn't notice a huge difference between them) and n is the number of iterations (I used 500, 1000 and 2000, 1000 made the prettiest picture). This means that the colour of each pixel ranges between black and bright blue.

Here's what I got when I calculated it centred at c = 0.38 + 0.1i, with 64x zoom (where 1x zoom is in (1 + i to -1 - i)), 1000 iterations and a threshold of 2 - unfortunately when viewing the picture in the browser (at least for me on Ubuntu with Firefox) it doesn't look as nice as if you actually download the thing so I recommend you do that to appreciate it more:


That's pretty eh?

One thing that I find neat about this set is that it is self-similar. Each one of those little blue blobs is how the picture looks if you centre at 0 + 0i and have 1x zoom. You can then zoom into each one of those and see little bumps on the side that also look exactly the same as the whole. And each of those bumps has smaller bumps on it that also look the same. Pretty cool eh?

UPDATE: I wrote a follow-up about this here.