Conditional comments for Internet Explorer with Haml

Internet Explorer 5+ is aware of conditional comments that let you target HTML for selected versions of IE. For example the HTML below would ask users of IE 6 and IE 7 to install Firefox:

<!--[if lt IE 8]>
  <a href='http://www.mozilla.com/en-US/firefox/'>Get a real browser</a>
<![endif]-->

You might wonder how to express such a conditional comment in your favorite templating language, Haml. You might even have converted a template back to ERB just for this ...

Getting started with Puppet

When you simply want to get to know Puppet, follow puppetlabs’ Learning Puppet Docs. They give you a handy introduction inside a virtual machine they provide. You can watch the talk by Garrett Honeycutt 'Expanded Introduction to Puppet'.

Do not miss their cheatsheat and their [learn-puppet virtual machine](http://info.puppetl...

Matching line feeds with regular expressions works differently in every language

Although regular expression syntax is 99% interchangeable between languages, keep this in mind:

  • By default, the dot character (".") does not match a line feed (newline, line break, "\n") in any language.
  • Some languages allow you to modify the behavior of a regular expression by appending a modifier to the pattern expression. E.g. /foo/i makes the pattern case-insensitive in many languages. Note however that some of these modifiers may not exist or mean entirely different things in different languages.
  • Some languages have a m...

Putting static content on Cloudfront

We recently decided to put static content for HouseTrip.com to Amazon Cloudfront for a faster user experience. This happens fully automatically on deploy and is transparent in development. Together with a heavy use of sprites this sped up page load time quite nicely.

These are a couple of the problems you need to solve in order to do this:

  • There is no good way to invalidate Cloudfront cached assets, and Cloudfront will ignor...

Split an array into columns

You know that you can collect an array as groups using in_groups or in_groups_of.

Maybe you want to fetch those values in "columns" where the first value lives in the first column, the second one in the second, etc. until it wraps, so that for example the fourth value is in the first of three columns.

Put the attached file into config/initializers/ to be able to say in_columns on any Array:

>> [1, 2, 3, 4, 5, 6, 7].in_columns(3)
=> [[1, 4, 7], [2, 5], [...

Setting up Ubuntu Server as Virtual Machine in VMware

Install Ubuntu Server

  • Download an image from this site
  • Select File > New… to and follow the instructions, choose the .iso file you downloaded as image file
  • Deselect "Simple installation" – you want to configure your system yourself
  • Start the new virtual machine and follow the instructions

Install VMware Tools

  • Choose Virtual Machine > Install VMware Tools from the VMware menu, then:

^
# install required packages
sudo apt-get install build-essential psmisc

# m...

Bash script to run specs and features

Run rspec-and-cucumber from any project directory to run both RSpec and Cucumber. If available, rspec_spinner or cucumber_spinner are used.

Note that features are not run when specs fail.\
If you prefer to run them in parallel or run features regardless of the spec results, please adjust it for yourself accordingly.


This script is part of our geordi gem on github.

Nautilus File Manager slows down the system after new installation of ubuntu

After a new system installation, Ubuntu One starts automatically and seems to try to sync your complete home directory. This slows down the Nautilus File Manager extremely. To prevent this, uncheck Ubuntu One from your start programs and restart the system.

Change the hostname on Mac OS X

To set the hostname of your Mac, run the following command in Terminal:
sudo scutil --set HostName my-new-hostname.local

Check it by typing:
hostname

Using QEMU to quickly test an ISO or bootable USB drive

When you want to quickly boot from a drive or image in a virtual machine you do not need to setup up a VirtualBox machine. Often QEMU does the job well enough.

Install it:

sudo apt-get install qemu

To boot an ISO:

qemu-system-x86_64 -cdrom filename.iso

If you prepared a USB pen drive and want to test it, run it like this (/dev/sdx being your device name; you may need to sudo to access it):

qemu-system-x86_64 -hda /dev/sdx

Be aware that not everything runs smoothly in QEMU -- you might need to set up a _VirtualBox...

Vector Magic: Precision Bitmap To Vector Conversion Online

Automatically convert bitmap images like JPEGs, GIFs and PNGs to the crisp, clean, scalable vector art of EPS, SVG, and PDF with the world's best auto-tracing software.

Playing audio in a browser

If you want to play music or sounds from a browser, your choice is to use either Flash or the new <audio> tag in HTML5. Each method has issues, but depending on your requirements you might not care about all of them.

Flash

  • Works in all desktop browsers, even Internet Explorer. Does not work on iPads or iPhones.
  • Requires you to embed a Flash component into your page which will later play the audio for you.
  • Can play MP3s or Wave files. Cannot play OGG Vorbis audio.
  • Cannot reliably seek to a given position when playing VBR-enco...

Print-Friendly Images and Logos with CSS

The trick is this: send a low-resolution version of your image to the screen, and a high-resolution version to the printer.

Git Cheatsheet

Make sure you understand differences between git's areas (such as stash, workspace, upstream, etc.) and what commands affect which areas.

javan/whenever - GitHub

Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs.

Validations on associated objects

Validations that need to access an associated object may lead to some trouble. Let's exemplify that using this example:

class Project < ActiveRecord::Base
   has_one :note
end

class Note < ActiveRecord::Base
   belongs_to :project
end

Now say we need a validation that ensures that a description is set (validates_presence_of :description) within Note but only if the Project has a flag called external set to true. The following code will lead to some problems as the associated object is not present when creatin...

Speed up Capistrano deployments using a remote cached copy of repository

You can seriously speed up deployments with Capistrano when using a local git repository on the server you are deploying to.

Simply add

set :deploy_via, :remote_cache
set :copy_exclude, [ '.git' ]

to your config/deploy.rb and Capistrano will create a clone in shared/cached-copy. This will be updated using git pull when deploying which transfers less bytes and is usually much faster. If deploy_via is set to use default settings (being "export"), Capistrano will do a full clone of the repository from your git host otherwi...

Apprise - The attractive alert alternative for jQuery

An alert alternative for jQuery that looks good. Apprise is a very simple, fast, attractive, and unobtrusive way to communicate with your users. Also, this gives you complete control over style, content, position, and functionality. Apprise is, more or less, for the developer who wants an attractive alert or dialog box without having to download a massive UI framework.

Capistrano 2: Which Capistrano hooks to use for events to happen on both "cap deploy" and "cap deploy:migrations"

When deploying an application with "cap deploy" by default [1] you only deploy your code but do not run migrations. To avoid an application to be running with code which requires database changes that did not happen yet you should use cap deploy:migrations.

The problem

Let's say that you have something like that in your config/deploy.rb to create a database dump every time you deploy:
before 'deploy', 'db:dump'
This will not be called for cap deploy:migrations. The same applies to other things that are hooked s...

Why a Rails flash message is shown twice

You set a flash message and it shows up as it should. However, it is displayed again the next time you follow a link. Here is why:

You have to differentiate between a render and a redirect_to because a flash message is only deleted after a redirect. If you want a message to be seen in the next request after a redirect, use flash[]. If you want a message to be seen in the current request, use flash.now[].

Workaround for the lazy

If you cannot be bothered to decide which flash hash to use, or if the fl...

Ignore an error class with Airbrake

Airbrake (formerly Hoptoad) already ignores certain errors like InvalidAuthenticityToken by default (see Airbrake::Configuration::IGNORE_DEFAULT).\
To ignore additional classes of errors, put this into config/initializer/airbrake.rb:

Airbrake.configure do |config|
  config.ignore << 'ActiveRecord::IgnoreThisError'
end

You probably also want to ignore ActionController::MethodNotAllowed and ActionController::UnknownHttpMethod exceptions.

See the github page for more options on h...

Haml and Sass 3.1 are Released

Sass now comes with user-defined functions, keyword arguments, list manipulation. Haml and Sass are now two separate gems.

HTML5 Presentation

Awesome presentation for the new HTML5 features we will get to play with. This presentation should probably be viewed in Chrome only.

How to translate “business value” of things that are technically important

User Stories should describe what a user wants the system to do. Purely technical tasks should usually be implemented as part of a User Story. But, sometimes there are technical tasks which cannot be directly linked to customer value. Things like “Upgrade to MySQL 6.0″ or “replace magic numbers with enums” need to be done. How can you prioritize these critical chores against User Stories? How can you make the product owner aware of the importance of such tasks (and the business risks of procrastination)?