New Release: Eject Volume v0.3

Eject Volume v0.3 is out. As always, you can download it here. Besides the slight redesign, it offers three new features, namely the volume icons, support for network volumes and an “Eject All” button. It’s a major rewrite of the original code, which makes it more modular and faster. The handling of the volumes is now done via a Cocoa widget-plugin that improves speed and makes listing and ejecting of volumes more stable. Have fun with it!

1 Comment

rating_for – A context-based rating plugin for Rails

Today I’ve released my rating_for plugin for Rails. It allows to add multiple rating categories to one ActiveRecord model. For example if you’re building a hotel review website, the rating_for plugin can save you some work:

class Hotel < ActiveRecord::Base
  rating_for :room_service
  rating_for :quality
end

four_seasons = Hotel.find_by_name("Four Seasons")
four_seasons.rating_for_quality.add(10)
four_seasons.rating_for_room_service.add(9)

rating = Rating.new(:value => 7)
marriott = Hotel.find_by_name('Marriott')
marriott.rating_for_room_service << rating

hotels = Hotel.find_where_quality_has_average_rating_of(10)

For more info and installation instructions, you should take a look at the plugin’s GitHub page: http://github.com/frane/rating_for

By the way: Since we’re currently on the edge between Rails 2.3 and 3.0, I’m happy to announce that the rating_for plugin is compatible with both versions.

Any kind of feedback is welcome and if you’ve got questions, just ask!

Leave a Comment

Eject Volume v0.2

Today, I’ve released version 0.2 of my Eject Volume dashboard widget for Mac OS X. It’s a bugfix release that fixes some bugs, which I encountered lately. Since its release in February 2009, the version 0.1 of Eject Volume has been downloaded over 10.000 times and was recently even blogged about as useful utility on some other sites. Not bad for two hours of work :-) .

3 Comments

My shiny new iPhone

Today my shiny new iPhone arrived. It’s really cool and I’m really happy to finally have it. For months now I wanted replace my old cell phone and with a new one. The iPhone was my preferred choice, but I didn’t like T-Mobile’s cell phone plans for the iPhone and I was quite happy with my plan. I hat already started to look for other phones, when I got a phone call from T-Mobile. The nice lady on the phone explained that they wanted thank for being a loyal customer and that I could get a new phone if I renew my contract. When I asked if I could get an iPhone, the T-Mobile lady responded that I would have to pay a small fee but that could have it if I want. So I renewed my contract (I was going to do that anyway) and got my iPhone. It’s really funny how things sometimes sort themselves out all on their own.

Leave a Comment

Rails I18n and emails

Since version 2.2, Ruby on Rails comes with an integrated support for internationalization (I18n) which makes developing multi-language websites very easy. Here’s how it works. Recently I worked on a project where I used the I18n API to provide multi-language support. The website had a user system and the user was able to change the web-site’s language in his/her profile. Basically, there was a model “User” with an attribute “language”, which was stored in the database. Every time when a user would log in on the website, the web-site’s language would change to the user’s preset language with:

I18n.locale = current_user.language

However, there was a problem with the emails, which a user automatically received from the web-site. I used a cron-job with Rails’ “script/runner” to periodically send mails from a model like this:

class Task
  def self.send_mails
    User.all( :conditions => "want_mail = 1" ).each do |user|
        UserMailer.deliver_daily_mail(user)
    end
  end
end

The mail template was translated with the Rails I18n API like this:

<%= I18n.t 'daily_mail.hello' + @user.name %>
...

The problem was only that the mails were sent out in English because the web-sites default language (I18n.default_locale) was English and there was no “I18n.locale” set in “script/runner”. The easiest solution to that problem is to set the locale somewhere in your email setup:

class UserMailer < ActionMailer::Base
  def daily_mail(user)
    I18n.locale = user.language
    @recipients  = user.email
    @from        = "The Daily Mailer <daily_mail@example.com>"
    @subject     = I18n.t 'daily_mail.subject'
    @sent_on     = Time.now
    @body[:user] = user
  end
end

Alternatively, it’s possible to set the language in the email template:

<%= I18n.t('daily_mail.hello', :locale => @user.locale) + @user.name %>
...

It’s more a logical then a technical problem, but it shows how (logically) complicated multi-language web-sites can be.

Leave a Comment

Windows server lockout

Since there are not only unix-based servers out there in the web, I sometimes also encounter Windows servers which I have to maintain.

Usually, you connect to a Windows server using Microsoft’s “Remote Desktop Connection” (RDC) client. If you’re not running a terminal server, the number of allowed sessions on the server is limited to two sessions at a time.

Unfortunately a session isn’t ended and closed if you close your RDC client window, but only if you log off, i.e. by clicking on “Start” -> “Log Off”. So if you just close your RDC window without to log yourself really off, there’s a good chance that you lock yourself out from the server and thus get the following message “Terminal Server Has Exceeded the Maximum Number of Allowed Connections”.

If you have access to your server, you can easily log on to the server on-site and remove all “dead” sessions, but if your server is somewhere on this planet where you can’t just go over to, you should be served by using the following command:

C:\>mstsc -v:your_server_name_or_ip -admin

This command gives you access to a special session, namely the session 0 and you should be able to log in as “Administrator” and remove the dead sessions.

This two sessions at a time restriction is really annoying and it gets even more annoying if other people also use the server and don’t log off correctly. Having such stupid problems is probably one reason why many people get mad a Microsoft and their products. It’s simply a licensing issue you don’t have on Linux and *BSD systems ;-) .

Leave a Comment

Introducing Eject Volume

I’ve written my first MacOS X Dashboard widget today. It’s called Eject Volume and provides a handy way to eject volumes which are mounted on your system. More information about the widget and a download option is provided here.

Eject Volume Screenshot

2 Comments

Upgrading Debian Etch to Lenny

On last Saturday Debian 5.0 “Lenny” has been released as stable. This probably means a lot of updating work for many administrators. I was updating a couple of servers during the last days. Due to Debian’s APT system it’s a pretty easy process.

Step 1: Edit your /etc/apt/sources.list. Replace every occurrence of “etch” (I assume you’re updating from Debian “Etch”) with “lenny”. Your sources.list should now be looking roughly like that:

deb http://ftp.de.debian.org/debian/ stable main
deb-src http://ftp.de.debian.org/debian/ stable main

deb http://security.debian.org/ stable/updates main contrib
deb-src http://security.debian.org/ stable/updates main contrib

Step 2: Simply run apt-get updateand you should probably get something like this:

srv:~# apt-get update
Get:1 http://ftp.de.debian.org stable Release.gpg [386B]
Hit http://ftp.de.debian.org stable Release                                    
Get:2 http://security.debian.org stable/updates Release.gpg [189B]
Hit http://security.debian.org stable/updates Release
...
Hit http://security.debian.org stable/updates/main Sources
Hit http://security.debian.org stable/updates/contrib Sources
Fetched 2B in 0s (15B/s)
Reading package lists... Done
W: There is no public key available for the following key IDs:
4D270D06F42584E6
W: You may want to run apt-get update to correct these problems

Apparently, this means you need to get the public key for 4D270D06F42584E6. ;-) This can easily be done with the following commands.

srv:~# gpg --keyserver wwwkeys.eu.pgp.net --recv-keys 4D270D06F42584E6
gpg: directory `/root/.gnupg' created
gpg: can't open `/gnupg/options.skel': No such file or directory
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key F42584E6 from hkp server wwwkeys.eu.pgp.net
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key F42584E6: public key "Lenny Stable Release Key <debian-release@lists.debian.org>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1
srv:~# apt-key add /root/.gnupg/pubring.gpg
OK

Please note that the key ID and though the public key needed on your system can differ from this one.

Step 3 Finally, you can rerun the package-list update and run the actual upgrade.

srv:~# apt-get update
srv:~# apt-get dist-upgrade

Depending on your machine’s capacity and your internet connection speed the upgrade can take from about 15 minutes to some hours. The avarege time my updates took was 30 minutes. After that you can reboot your freshly upgraded system with the new kernel and you’re done.

1 Comment

Basic Authentication problems with Phusion Passanger (mod_rails)

Phusion Passenger aka. “mod_rails” is great! It makes Rails deployment pretty easy and time-saving. Unfortunately it has a bug in it’s current 2.0.6 version which breaks Basic Authentication. Though this bug is fixed in the unreleased 2.1 version (see here) you need to care about the problem by yourself for now. The only working solution for me was to user Rails’ Basic Authentication functionality by hacking the following into my application controller:

class ApplicationController < ActionController::Base

  before_filter :http_auth  
 
  ...

  private
 
  def http_auth
    authenticate_or_request_with_http_basic do |user_name, password|
      user_name == "JohnDoe" && password == "secret123"
    end
  end

end

At this point you can be as creative as you want with reading the user name and password form a file or database and checking hashed passwords instead of plain text. For my purposes this was just enough, so I didn’t waste any more time on it. At the end of this post be warned: Basic Authentication through Rails does only protect your application, but it does not protect the static content in your public directory.

1 Comment

Archiving Thunderbird e-mails

Looking for a smart way to archive your e-mails from Thunderbird? There are many advices like copy your “/home/(username)/.mozilla/…” directory, which (in my opinion) are not very smart. After googling quite a while, I found a very cool TB extension called SmartSave and it lives up to its name! It needed less than ten seconds to export 1900 mails with a total size of 150 MB. I like it!

Leave a Comment