Community Day 2009 in Copenhagen

It has been a while since I had a good technical post on this blog, and this is will not be one either. Instead, just a few brief words on a very successful event for geeks in Copenhagen that took place last Thursday. Sponsored by Microsoft and co-presented by the Danish development community, Community Day 2009 Copenhagen delivered what it had promised: A day with free beer and food, interesting presentations and lots of networking across the usual technical boundaries. While the event, previously exclusively with a focus on Microsoft technology, was dominated by seasoned .NET developers, we, the Ruby crowd, was well represented as was the PHP programmers.

Daniel Mellgaard Frost, Developer Evangelist with Microsoft Denmark, had put together a diverse program where only two talks was devoted entirely to Microsoft technologies (Silverlight and LINQ), but six out of eight talks was about web development in some form. I did a talk on ActiveRecord, the O/RM of Ruby on Rails, and according to the many happy comment I got afterwards, it went pretty well.

Continue reading

Notes and impressions from RailsConf 2009

I’d never have guessed that the first time I’d visit Las Vegas, the gambling and the drinking, the shows and the shopping would be a minor thing, something that I’d squeeze in between what really mattered. But RailsConf 2009 had such a comprehensive and interesting program that this ended up being the case. From the casual networking at breakfast and lunch over packed keynotes and high-quality talks to late-night Birds Of a Feather sessions, RailsConf did give the attendants any reason to step out if the air-conditioned Hilton and into the sun and lights of the Strip.

We did that anyway, obviously, but mostly we were learning, tweeting, chatting, coding, emailing and taking notes at a conference where the wifi actually worked and power strips were easily available. I’m not going to reference all the talks that I went to here, but I have uploaded my notes here. Also, I’ve written a detailed summery of David Heinemeier Hansson’s keynote and a few select talks that I attended for RailsMagazine, but the free PDF-edition won’t be available for another two weeks now freely available for download … slides from all the presentations can be found here.

Continue reading

IE on Mac without Parallels/VMWare

IE6 on Mac

Benjamin Quorning gave a great tip at the Copenhagen Ruby Brigade mailing list the other day: How to run (Windows) Internet Explorer on your (Intel-based) Mac without having to boot up Parallels, VMWare, or any other kind of time-consuming PC-emulation software. This is made possible by the IEs 4 Linux project (no, that’s no IE 4 on Linux, it’s IEs for Linux, and IE 4 is not supported, just 6, 5.5 and 5) which provides a simple way to run IE on Linux and, as it turns out, OS X on Intel-based Macs.

While the article on the IEs 4 Linux provides one method for getting this up and running, I tend to like Benjamin’s more as it uses MacPorts, so I’m going to repeat it here for reference. A prerequisite for the tutorial is to have X11 installed, which is part of the optional developer tools that comes with OS X, and you also need MacPorts, which seems to be the best package system for Darwin at the moment.

To install IEs4Linux and its dependencies, execute these commands in your terminal of choice:

sudo port install cabextract wget wine
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux

The first line installs several components required to run IEs4Linux, most importantly Wine, a framework allowing many Windows applications to run on Unix-based systems, including OS X. The other lines download and start the impressively user-friendly installation of IEs4Linux. After completing the installation, Benjamin explains that to run Internet Explorer, you must startup the X11 console (/Applications/Utilities/X11.app) and execute these commands:

export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
~/bin/ie6

That’s a bit too inconvenient for my taste, since want to be able to place a link to IE directly in my Dock, or run it by executing a simple command in Quicksilver. So I have created a shell script in my home directory (you could also place it in the Applications directory if you like that better) called ie6 with the following contents:

#!/bin/sh
open-x11 .ies4linux/bin/ie6

I also need to make it executable by running chmod +x ie6 in the terminal. Now this gives me the ability to execute the shell script from terminal, to call it from Quicksilver (by writing ie6), and to drag it to the right/lower part of the Dock (the part with the trash can in it) with an ugly generic document icon. I want it in my Dock with a nice high quality Internet Explorer icon so I can start just like any other application, and for that purpose I wrapped the shell script as an application:

Download IE6 application

  • Requires IEs4Win to be installed in the default location (~/.ies4win)
  • Must be dragged to the Applications directory in your home directory (create one if you don’t have one), not to the general Applications directory (this is due to my limited shell scripting / X11 abilities, ~ didn’t seem to work as a reference to the home directory in X11).

RailsConf: The DHH keynote – Rails 2.0 update

This article summarizes some important points from David Heinemeier Hansson’s keynote at RailsConf Europe 2007 in Berlin. Last year, DHH brought us the whole REST way of thinking which I immediately named normalization, but that term didn’t really catch on.

David Heinemeier Hansson
© 2007 Pinar Ozger

This year, DHH noted that he up until now had started all his previous keynotes about Rails celebrating how “freakin’ fantastic we are”. For this keynote, he thought – with Rails being well within in its third year in existence – that it was time to perhaps be happy with what we have.

He explained that new things tend to go through certain phases: First they ignore you, then they laugh at you, then they fight you, and then you win – … and then what? “Ruby on Rails went through these phases way too fast”, DHH said, “I was having a lot of fun going through these phases; I’m kind of sad it is over.”

For the last couple of years, David and the Rails community has pushing new concepts; Convention over configuration, AJAX and REST, but these focal points were adopted very fast, so there is no big cause to fight for right now. That leaves Rails 2.0 in a really weird spot, since it won’t have any groundbreaking new concepts.

This is not a bad thing, though, DHH stressed. “Even though [the lack of a great cause] is an off-switch for me, it’s not about me anymore”, he said. “Rails are moving from big revolutions to tiny evolutions” – a statement that was underlined when David went on to demonstrate new features in Rails; features that were definitely more tiny evolutions than big revolutions.

But before we get to the Rails 2.0 code examples of the keynote, let me just mention something that was news to me: The new policy for how to get a patch into Rails, also known as Report #12. The idea is basically that you, once you have written a patch and submitted it to the Rails trac, should get three other Rails developers to check out your patch, verify that your tests run, and then add a “+1″ in a comment in trac. Once you have your three “+1″‘s, you tag your patch with the keyword “verified”, and the patch will appear in Report #12: Verified Patches. The core team should then – theoretically – be able to very fast to accept the patch into Rails.

Moving on to the, in my opinion, most interesting part of the presentation: What’s new in Rails 2.0 – show me the code! Migrations has been updated to support a new syntax known as “sexy migrations”, which basically allows even shorter and more readable migrations by grouping fields of the same type:

create_table :blogs do |t|
	t.string :title, :subtitle
	t.text :body, :description
	t.integer :category_id
	t.timestamps # Adds created_at and updated_at fields
end

Notice how another evolutionary improvement has been sneaked in: Tired of always adding created_at and updated_at timestamps to most tables, a timestamps method has been added as a shortcut. Also this new syntax, including the timestamps, is now standard in the model and scaffold generators.

A small, but to me significant improvement has also found its way to Rails 2.0: You can now create the needed databases with a rake command. By running this command, all referenced databases in your database.yml will be created:

rake db:create:all

Another interesting, and perhaps generally quite invisible improvement, is that session data are now stored in a encrypted cookie instead on each server, which makes it easy to partition applications across multiple servers without having to put session data in the database. This requires, of course, the session data to be quite compact (storing id’s, not entire objects), as a cookie can contain 4 KB of data the most.

My favourite point of DHH’s keynote was his solution to the common pattern of a resource, which you both need to display to the common user (usually index and show) and to the admin user (usually index, new, create, edit, update and destroy). The normal RESTful solution to this leaves with a problem, because we are only allowed one index action, and we need two; one for the common user and one for the admin user. Also, the admin actions will usually have a different layout than the common user actions, and they require some kind of authorization.

The solution is to used RESTful namespaced routes, referring to two different controllers with the same name, but in different namespaces. To use DHH’s eternal blog example:

./script/generate controller posts # => /controllers/posts_controller.rb
./script/generate controller admin::posts # => /controllers/admin/posts_controller.rb

Now we have two different controllers working in the same model; Post, but offering different actions, layouts, authorization and so on. This nice thing about this solution, is that it is very easy to understand and fits well into the Rails structure. The catch is that we have two controllers with the same name, so we need to explicitly express the namespace when referring to the admin controller:

form_for([:admin, post]) do |f|
	...
end

DHH also pointed out that HTTP authentication is a perfect way of doing authentication for administration pages (which I’d already realized). You don’t really need nice-looking form-authentication and remember me checkboxes for that, and it is so very easy to implement with Rails 2.0:

# In a controller or module shared between admin controllers
before_filter :ensure_administrator
def ensure_administrator
	authenticate_or_request_with_http_basic('Blog admin') do |username, password|
		username == 'dhh' && password == '123'
	end
end

A very visible change in Rails 2.0 is the naming of views. The .rhtml, .rxml etc. file endings has been discarded to replaced by the form [name].[mime-type].[renderer]. This leaves the road open for file names such as:

  • index.html.erb
  • index.xml.builder
  • index.html.liquid
  • index.iphone.erb

The last example needs a little additional configuration, since iphone is not a “real” mime-type, but we can easily make Rails treat it like such:

# In mime_types.rb:
Mime::Type.register "application/x-iphone"

# In application.rb:
before_filter :adjust_format_for_iphone
def adjust_format_for_iphone
	if request.env["HTTP_USER:AGENT"] ~= /iPhone/
		request.format = :iphone
	end
end

# In specific controllers
respond_to do |format|
	...
	format.iphone do
		render :text => 'Hello iPhone', :content_type => Mime::Html
	end
end

Notice how content_type must manually be set to Mime::Html, as the iPhone browser – as well as any other browser – doesn’t recognize our fake x-iphone mime-type, and Rails will always default to respond with the request mime-type.

My second favourite point was about the “new” debugging support in Rails 2.0. As I understood it, the well-known ruby-debugger library has been baked into Rails 2.0, so that we write debugger instead of breakpoint, and need to start the server with a --debugger prefix (./script/server --debugger) to enable these breakpoints. This debugger also support more advanced commands such as “cont” (continue), “list” (view current code) and “up” (step out).

David Heinemeier Hansson rounded off his keynote by announcing the release of a Rails 2.0 Preview Release (how Microsoft-ish does that sound?) either during or shortly after the conference.

You can download my full notes from the keynote here.

UPDATE: My other notes from RailsConf Europe 2007 are now available.

Juggling with Jaiku

Reboot just finished. Great speakers, nice people, clever geeks – as usual. I wasn’t disappointed, Mygdal and his crew did a terrific job once again. While I hope to find the find time write a longer article referencing some of my favorite talks, this post is about something else I learned of at Reboot: Jaiku.

Some might say Jaiku is another Web 2.0 fling. Others might call it a Twitter clone. To me, Jaiku is a new way of expressing yourself on the internet. Jaiku let’s you do two things:

  • Write short messages (max. 140 characters) that gets published in your stream immediately
  • Aggregate all the stuff you publish on the internet; blogs, photos, bookmarks, music, etc.

For instance; at my Jaiku page you can see my latest presence-messages (or micro blog posts or just jaikus), but you’ll also see new blog posts, Flickr photos and del.icio.us books posted by me using those services. Jaiku does this by polling RSS-feeds specified by me in my settings.

While all this is nice, I still consider casperfabricius.com my primary homepage and “me-place”, so I wanted to be able to display my latest jaikus here on my blog. I could do this by using the Jaiku WordPress plugin, but that makes a server-side call to Jaiku on each page request, slowing my site down. For this reason, I opted to use Jaikus brilliant JSON API in order to let the magic happen client-side.

I wrote this javascript, and added the following HTML to my main index and page templates:

<!-- In the <head> section -->
<script type="text/javascript" src="/js/myjaikus.js"></script>
<script type="text/javascript" src="http://[Insert your Jaiku username here].jaiku.com/feed/json?callback=MyJaikus.storeJaikus"></script>

<!-- In the menu, where I wanted the Jaikus to appear -->
<ul id="jaikus">
</ul>

This javascript will, if you remember to put in your own user name and add an empty unordered list with the id jaikus, insert the three newest of your jaikus. Neat, eh?

Jaiku ressources

Your own Mac OS XP with Parallels

Mac OS XP

Simple question: Am I running Mac OS X or Windows XP in the screenshot above? (Click to enlarge).

Simple answer: I’m running both.

Complicated answer
I’m really running Parallels with the coherence feature enabled. Parallels is an application that utilizes the Intel processors in newer Macs, allowing Windows XP to run in a virtual machine, but without the whole hassle of emulation. Without emulation, speed is greatly increased.

Coherence means that the Parallels makes the Windows desktop transparent while running the virtual machine full screen. This allows Mac and Windows applications to run side by side, without the hassle of having to switch to the virtual machine, and then selecting the Windows application you want to use. This way; Windows application really feel like any other applications on Mac.

This is cool, but it’s old news. Now, I’m using boot camp to dual-boot on my Macbook Pro. I use Windows for .NET development at work and for gaming. I use Mac OS X for everyting else. The great thing about this new beta of Parallels I’m running, is that I don’t have to create a new virtual machine and install Windows, Office, Visual Studio and so on. I can just boot my existing Windows partition directly in Parallels. How cool is that?
If you are dual-booting between OS X and Windows, I can only recommend that you try out the free 30 day trial of Parallels. It is unbelievably easy to get up and running; you just go through a wizard, select Boot Camp, and – BAM! – you have your well known Windows desktop right there next to your Dock, Mail, Safari, and so on. If you try this setup, I have one tip for you: Don’t attempt to click on anything when you boot in Parallels and Windows detects new hardware. Parallels will take care of everything, so just sit back and wait until the virtual machine is not working anymore.

And by the way: Running your Windows partition in Parallels doesn’t in any way change or harm the partition. You can always boot into Windows as usual, which is still necessary if you want to play a 3D game.

Quake-style slide-down terminal on Mac

It’s official. I’ve bought a Mac. I have never used a Mac before, and I am actually enjoying the discovery process I have to go through to get up to speed on this new platform. (Example: While writing this first paragraph, I figured out – by trial and error – that you select words in chunks with Shift+Option, not Shift+Ctrl like on Windows.)

I’ve already had several small victories in the process of customizing OS X to my needs, and since Google Analytics reports that one third of you readers are on a Mac, I’d like to share a quick tip with you. One of my main reasons to switch to Mac is the availability of the terminal; which unleashes the power of the Darwin system behind the fancy GUI. I had half expected the visual aspects of this terminal to be highly configurable, and while some options exists, it wasn’t immediately possible to get the terminal to slide down in a cool Quake-style console way like I had dreamed of for a while.

So I set out to find a way to do this, and through this forum thread I found out that I was not the only Mac user with this strange need. Some of the clever geeks taking part in the thread has been so nice as to actually write a small application that enables the terminal to slide down; called Visor. I’m quite impressed with OS X being flexible enough to provide this kind of extensibility.

The installation is quite easy – just follow the instructions and make sure you have OS 10.4 – but one thing caught me, being a complete Mac newbie, as a small frustration: I didn’t know to look for the Visor icon (which is a small black terminal) next to the clock in the upper right corner. You must configure Visor using this menu (which will appear when you (re)start Terminal after following the instructions) before the terminal is able to slide down using your selected hot key.

As a final touch I’ve also opted to make the terminal semi-transparent and added some eye candy as a background image. You do this by opening a normal shell window in Terminal, make your settings in Window Settings > Colors and restarting Terminal. Visor also supports animated backgrounds, but I haven’t tried that out.

Visor

While I’m quite happy with Visor, I still have my doubts about whether Microsoft Entourage is the right email application for me (as a heavy Outlook user through many years it seemed an obvious choice) and whether Fire is the right instant messenger. One thing that really annoys me, and that I haven’t been able to solve so far, is that OS X automatically puts the computer to sleep when I close the lid. I am aware that various heating issues can occur if it didn’t, but I’m just used to close the lid while the computer is shutting down – this will put it to sleep during the shutdown. If anyone knows of a good solution for this, I’d be happy to hear from you.

Posted in mac