published on 02.04.2006 19:56.

getting irb brackets to work on german windows

for those on windows, there’s the great ruby one-click installer which will set up a nice ruby environment on your box. asking it to take care of all possible localization issues would be asking for too much though, so if you’re on a non-english windows, chances are that irb will be severely broken – no brackets, no ruby joy. and no script/console in ruby on rails.

the reliable way

here’s how i was able to fix the issue:

  • download the file linked to in why’s poignant guide to ruby in the “windows hickups” sidebar. place the files from the zip file in ruby directories as described at why’s.
  • get the text snippet “for europeans” as well. save it to the file c:\ruby\etc\.inputrc_german. (you will have to create the etc directory first). when saving the file you might have to go through the windows shell, as the windows explorer doesn’t let you create filenames starting with a dot.
  • tell readline where to find this file. the safest bet is to directly point at the file by setting the INPUTRC environment variable. so edit c:\ruby\bin\irb.bat and insert the following after the @echo off command (line 2):
    set INPUTRC=c:\ruby\etc\.inputrc_german

the pretty way

if you don’t want to “hack around” your ruby directory and modify irb.bat, of course you can specify the environment variable somewhere else and also put the .inputrc file in another directory. these are your options (start reading from the paragraph “Readline-4.0 will look for an …”).

i fiddled with this a lot, so i came up with the first option. if you want to put the file somewhere else, be aware of the following:

  • the HOME env variable is most likely not set on windows, so readline will not search there.
  • if the path to .inputrc contains spaces (as it will when pointing to a german windows home dir - “C:\Dokumente und Einstellungen...”) readline might choke. at least it didn’t work on my box.
  • if you happen to have cygwin installed (as i do …) there’s some extra confusion, as the HOME env variable is set, but it points to some place that (at least on my system) does not exist.

Posted in ,

published on 13.03.2006 00:59.

Ruby tip of the day (2)

Comparing objects in Ruby

UPDATE: the title is a bit misleading, it should better be “sorting ruby objects” or something like that. the point is to show that ruby’s collections have several methods to compare their contents - and that the comparison rule can be given in a block.

you have a couple of objects in a collection. you want to find out which of the objects has the highest position.

class SomeFoo
  attr_reader :age
  def initialize(age)
    @age = age

list = [,,

oldest_foo =  list.max {|a,b| a.age <=> b.age}
puts oldest_foo.age
=> 45

of course this comparison works for anything you can write a block for.

Posted in ,

published on 01.03.2006 12:58.

MySql tip of the day

using regular expressions for criteria

SELECT style_number, LENGTH(style_number) 
FROM articles 
WHERE style_number REGEXP '^(89|98)[0-9]+$'

you can also use RLIKE. and it runs much faster than expected, too!

Posted in  | Tags

published on 28.02.2006 20:31.

Ruby tip of the day

EDIT (11.11.2007): Dir#glob (aliased as: Dir[]) could also be used.

find all files in a directory matching some pattern

list ='.') { |f| f =~ /_\d{2}.(jpg|gif)$/ }
=> ["11-029_42.jpg", "1209-180_32.jpg", "1210-180_32.jpg", "1218-180_32.jpg"]

=> 4

Posted in ,  | Tags

published on 28.02.2006 17:03.

Unix tip of the day ...

grep --color Gecko access_log

in der .profile oder .bashrc datei im home-verzeichnis folgendes hinterlegen, dann kann man sich die angabe von –color sparen:

alias grep='grep --color'

Posted in  | Tags ,

published on 31.01.2006 23:25.

completely useless ruby code

this chunk of code is completely useless, apart from the fact that it let me practise how ruby does arrays, objects, constants, observers and singletons. and how to pass a variable number of arguments to a function method and set defaults for arguments that weren’t passed. plus it had me thinking about “what-goes-where” and coupling in object oriented programming.

maybe not so useless after all!

# for documentation see the UML diagram at the following url
# @url <a href=""></a>
require 'observer'
require 'singleton'

class StickFigure
   MALE = 0
   FEMALE = 1   
   attr_reader :name
   def initialize(attrs)
      @name     = attrs[:name] ||= 'Anonymous Coward'
      @sex      = attrs[:sex] ||= MALE
      @is_lazy  = attrs[:is_lazy] ||= false
      @in_peril = false
   def in_peril!
      @in_peril = true
      puts @name + ' is in peril!'
   def to_s
      puts "\nHi! I'm " + @name + ' and I am ' + (@is_lazy == true ? 'a little' : 'not') + ' lazy.'
   alias :introduce_self :to_s   

class CoffeeDrinkingStickFigure < StickFigure
   def have_coffee
      puts @name + ' has a cup of coffee.'
      pot = get_coffee_pot
      if pot.needs_refill?
         make_more_coffee unless @is_lazy

   # :TODO: the stickfigure should NOT be responsible for notifying it's observer ... better solution?
   # this part is not so pretty.
   def return_to_desk
      puts @name + ' returns to ' + (@sex == FEMALE ? 'her' : 'his') + ' desk.'
      get_coffee_pot.notify_observers(get_coffee_pot, self)
   def make_more_coffee
      puts @name + ' refills the coffee pot.'
      pot = get_coffee_pot
   def get_coffee_pot

class CoffeePot
   include Singleton
   include Observable
   attr_reader :cups_left
   CUPS_WHEN_FULL = 2.5   
   def initialize
      @cups_left = 0
   def pour_coffee
      @cups_left -= 1
   def refill
      @cups_left = CUPS_WHEN_FULL
   def is_empty?
      @cups_left == 0
   def needs_refill?
      @cups_left < 1

class BigBrother
   def update(pot, who_got_coffee)
      if pot.needs_refill?
         puts 'The coffee pot needs a refill and ' + + " didn't refill it!\n"
         cup_string = pot.cups_left == 1 ? 'is 1 cup' : 'are ' + pot.cups_left.to_s + ' cups'
         puts "There #{cup_string} of coffee left."

stick_figures = [ => 'Miss Piggy', :sex => StickFigure::FEMALE), => 'Bert'), => 'Kermit', :is_lazy => true), => 'Ernie', :is_lazy => true)

stick_figures.each do |stick_figure|

Posted in , ,  | Tags , ,

published on 30.01.2006 15:53.

why we love internet explorer so much

what’s wrong with this javascript?

function showDetailInNewWindow()
   // set new window properties
   top    = 200;
   left   = 250;
   width  = 680;
   height = 300;
   // ... proceed to open new window

the error message ie gave me: “not implemented, line 26, character 7”. in _which _of the included js files, you ask? well if it gave that information out, the error would be too easy to find, wouldn’t it?! and when you finally debugged which file it was, the line number was a couple of lines off.

this error message is as useful as asking your grandma’s parrot what was wrong with the code. except the parrot’s reply would be more intelligent.

2 hours lost. talk about efficient development. i’ll consider writing my front-ends in xul.

the error was (i figure): you shouldn’t use “top” inside a function. JS has all global vars in function scope as well, and ie allows you to omit “window” in some expressions. i.e. ie thought i was trying to say “ = 200”. which it

  • should have just done
  • complained that it’s a read-only property
  • complained that the object window doesn’t have that (public) property

or maybe top is a completely reserved keyword, why didn’t it tell me???

of course i only had to resort to opening the details in a new browser window since IE first needed loads of hacks and javascript expressions to get the data table i am displaying to look it as i wanted, and then, second completely messed up the while document when dynamically embedding the detail information into the current page (“ajax”).

ie 6 is definitely web 1.0.

Posted in , ,

published on 27.01.2006 16:17.

migration to typo trunk revision

… wasn’t too hard, thanks to the rake migrate command and typo’s nice upgrading system, which slash7 had pointed to.

conversion of all mysql tables to InnoDB didn’t work at first. since i’m still on mysql 4.0 the upgrade script 15 and the ruby on rails’ create_table method failed. they both use the ENGINE keyword for specifying the table type to use. in order to get things to work, i had to replace ENGINE with TYPE.

btw. typo claims that running off the latest trunk revision is no problem thanks to the extensive test coverage. however most of those tests had some failures on my box; well, let’s see what happens - typo seems to be running fine. it _is_ a little awkward that you have to keep tests up to date with the latest code changes; maybe they just forgot.

warning: before running tests, make sure you have configured different databases for test and production environments, otherwise you production database will be gone!

Posted in ,

published on 21.01.2006 13:48.

now with 100% more chunky bacon!

the foxes

switched to typo

today i migrated my site from a home-brewn php/one-html-page solution to the ruby on rails powered weblog typo (which is not to be confused with typo3). what had to be done:

  • locally update ruby on rails to version 1.0 and install typo.
  • parse the existing html page with all the log entries, and feed the extracted posts into the ruby on rails database.
  • find a nice template and tweak the stylesheet here and there.
  • fix all image links to be absolute, convert the log entries to utf-8 (had to install the iconv library for ruby).
  • upload the locally prepared installation to the webserver, create and fill the online database.
  • compile ruby, ruby-iconv, ruby-fcgi, ruby-mysql, pcre and lighttpd on the webserver; then install ruby on rails.
  • configure apache to forward (proxy) all requests to lighttpd, configure lighttpd to embed ruby via fcgi
  • write a start/stop-script for lighttpd and make sure lighttpd is run on startup.

all of this took about twelve hours to complete. more than half of the time was spent preparing the webserver — finding out what was needed to get ruby and lighttpd work together over fcgi.

if you’d like to see conversion scripts, take a look at the extended content of this post.

(i am) happy rubying!

try ruby if you like – an interactive ruby shell that runs directly your web browser.

you could also visit why’s hilarious blog, or his poignant guide to ruby, where you’ll find many more cartoon foxes!


Posted in ,

published on 06.12.2005 00:00.

a picture tells more than a 1000 words.

and yes, i'm officially infected.

Posted in ,

Older posts: 1 ... 5 6 7 8