Archive for January, 2010

The Gamma of Tag Clouds

Thursday, January 21st, 2010

I was doing some work on making a good looking tag cloud. The trick is to have slightly different tag sizes, but without having a few popular tags grossly outweighing the other tags. The tag size is then set using font-size: Xem.

  @max = @tags.collect(&:frequency).collect(&:to_i).max
  @min = @tags.collect(&:frequency).collect(&:to_i).min

  def tag_size(tag)
    gamma = 1.2
    range = 1.0
    offset = 1.0

    [1.0,1.0 / (@max-@min) * (tag.frequency.to_i - @min) ** gamma].min * range + offset
  end

Command line essentials

Sunday, January 17th, 2010

When you’re using the terminal in OS X, you’re usually using BASH, the Bourne-Again Shell. I’m occasionally surprised by long time terminal users who don’t know some of the following tips:

CTRL-A
        Jump to the start of the line
CTRL-E
        Jump to the end of the line
history
        Get a list of the last 500 commands typed
history | grep ssh
        Show a list of the last ssh commands you used
!script
        Run the last command you typed that began with script… (eg script/server -p 3100 -e production). Use this one with care - !rm can be a dangerous command
`backticks`
        Commands in backticks are evaluated first, and the result of the command is inserted into their place in the command. For example:
rm -rf `find . | grep svn`
        Removes all the .svn directories from your current directory
CTRL-L
        Clear the terminal screen
OPTION-K
        Clears the  scrollback history (this is an apple terminal command)
OPTION-T
        New Tab in the t apple terminal
tail -f log/production.log
        Follow a log (like cat, except stays open and displays new lines as they are written to a file)
CTRL-Z
        Pause the current process
bg
        Put a paused process into the background (same as running ./process &)
fg
        Brings a backgrounded process into the foreground again
grep term -B 2
        Greps a file for  ”term”, then displays the matching line and the two lines before it.

And when you’re working with files directly - these commands work in most versions of less or vim:

CTRL-B
        Page down
CTRL-D
        Page up
>
        Go to end of file
<
        Go to start of file
:123
        Go to line 123
/searchterm
        Searches for said term

If you use the terminal a lot, it’s definitely worth reading the bash reference and the advanced bash scripting guide. It’s one of those cases of a half hour spent reading saving you an hour per week. :)

Nexus? Give me a 2 year old Nokia instead…

Wednesday, January 13th, 2010

I’ve been in the market for a new phone as a complement to my iphone, I wanted a normal candybar phone with T9 keys, a good camera and most importantly, an excellent GPS. I ended up getting a Nokia 6220 classic, which I found on sale for about 125€. It came with 8GB of memory, and after installing Ovi Maps 3.0 and Sportstracker, I decided to mount the phone to my bike. A quick bit of tape and a rubber sponge later and I was off for a bike ride on my local trails.

Here’s part of the map that was generated:

picture-4

The sportstracker app (a free one from Nokia) automatically generates info points for the fastest point, highest point, as well as giving you a high resolution (and very accurate) GPS track of the route. I think there are apps like this for the iphone, but certainly none that run in the background and let you record video at the same time:

Biking on youtube

I didn’t realise until later that I had the camera mounted sideways, and the video that I uploaded to youtube was downsampled a lot from the original 640×480 source video. Regardless, there’s a lot more you can do on this two-year-old nokia (the 6220 was released in 2008) that you can’t do with a new iphone 3gs. Admittedly the web browser isn’t as good on the nokia, but i’d rather have good content creation tools than a good web browser.

Anyway - as part of my work on a facebook application for places, I worked out how to sync the places I have bookmarked with my Ovi Maps account. So any places that me or my friends bookmark, will end up on my phone. Fire up maps on my phone, click on the nearest bookmark, click ‘driving directions’ and my phone will give me turn by turn driving directions.

Finally, the camera is a 5MP camera with a xenon flash, that includes the GPS co-ordinates as EXIF data in the image, so that if you upload the image to my app, or a similair service (Panoramio, Flickr) the photo is seamlessly associated with a map location.

I’m impressed Nokia, well done.

Modern FBML

Thursday, January 7th, 2010

I’ve been doing a bit of FBML lately, and I’ve been impressed with the quality of tools available for that environment. I think FBML is often underused and underappreciated. With FBJS and the Ajax loaders, you can port pretty much all of your rails functionality over to FBML, and get the benefit of ‘native-feeling’ pages and fast load times (without the weird iframe-flash that most facebook apps have). I also find the pain of getting things to work on FBML is absolutely outweighed by the fbml tags facebook provides for searching friends, inviting users or showing facebook-ish dialogs.

760.css

This is a great css framework for doing block-based layout (as made famous by blueprint.css and 960.css). It lets you create nicely structured pages with simple tags like <div class=”grid_5″></div>. It’s nice to see this framework working under FBML.

FBJquery

I’m a longtime jquery fan, and was very impressed to find this port of jquery to fbjs. It does have some bugs (next, prev and parents don’t work as they should) and some peculiarities (css doesn’t accept hashes for example) but is a great start for your facebook development. I’ve been doing some work on fbjquery, fixing various bugs and making it code-compatible with jquery-1.3.2, I’ll put my fixes up on github when they’re ready for release.

The biggest problem I’ve had so far with Facebook is that you can’t readily use the render :update functionality of rails to do dynamic page updates, since you can’t eval() the response from an ajax request.

I’ve worked around that by manually parsing and executing the returned javascript, this lets me use the normal rails code, but have it converted into something that can be executed by FBJS. It does feel a little bit like hacks on top of hacks, but my goal is to have a complete environment for working inside FBML, not a cut-down version that feels “hamstrung” compared to normal HTML.