Posterous theme by Cory Watilo

Ruby on Rails: Migrating with default users using restful_authentication

Whenever your web application is going to offer user management, you might want to install at least a default admin user when creating your database. I searched the web for ideas to implement this and most of them come up with adding fixtures to your migrations. That's a really good one, of course, but I bet there is no way to dynamically hash your password using a fixture. I am using restful_authentication right now and this plugin does not only hash your password using SHA1, but adds a salt too. So a fixture is not what I wanted.

Instead I included the model itself in my migration, so the hashing and validation methods are used automatically. Hope this snippet is going to help others who are seeking for the same stuff. Let me know if it came in handy for you :-)

require 'app/models/user.rb'class LoadDefaultUsers < ActiveRecord::Migration  def self.up    say "Trying to insert default user(s)..."    user = User.create( :login => 'admin', :password => 'password', :password_confirmation => 'password', :email => 'admin@site.com' )    unless user.errors.empty?      say "Could not create admin user, see errors below:"      user.errors.each do |e|        say e      end    else      say "Admin user created"    end  end  def self.down    User.delete_all  endend

To all Mac users: what applications are in your /Applications folder?

I don't do that too often, but @ulfklose posted a very interesting question:

I'll try to answer it by posting my own setup. Well, not exactly answering the question, as I tend to put paid applications into ~/Applications. I do this to have them right back at its place after restoring a backup and to remind myself to use them (they took away money, you know? lol).

Just adapting @ulfklose's posting as a template here, as my setup is quite even to his:

Operating System: Mac OS 10.6 Snow Leopard
Surfing: Apple Safari just until yesterday, today I'm trying Firefox again
Mail: Apple Mail
Word processing: Apple Pages, Google Docs via Fluid
Presentation: Apple Keynote
Spreadsheets: Apple Numbers
Adress Book: Apple Adress Book
Calendar: Apple iCal and Google Reader (for hosting some of them)
Photo library: Apple iPhoto 08
Music playback, management and purchasing: Apple iTunes
Coding: Espresso (lucky MacHeist bundle hit)
Quickstarter: Google Quicksearch Box
FTP/SCP: Cyberduck
Password management: 1Password
File sharing: Dropbox
Screenshots: cmd+Shift+4 (keep trying to accustom myself to Skitch though)
Virtualization: VMware Fusion 2.0
Messaging: iChat w/ Chax and Skype (abandoned Adium to make use of the special iChat features more often) 
Notes management: Evernote
Social networking: Tweetie (free edition)
To Do Management: Things
Image editing: Pixelmator
Backup: Apple Time Machine
Media streaming (to Xbox): Playback 
Media management: nothing (having Delicious Library 2, not using it)
Video codecs: Perian (self-compiled from recent SVN trunk, thanks to @ulfklose)
Notifications: Growl
PrefPanes: Growl and Playback as mentioned above (Blue Harvest sounds interesting though...)
Video conversion: A self-written app called "Matroska 2 MP4", written in Obj-C/Cocoa (yay)
RSS: NetNewsWire, as it is Google Reader-syncable now
YouTube downloads: Get Tube (need a better alternative)
Vector graphics: Inkscape (need a better alternative here too... or at least a native port without the need for X11)
Banking: Pecunia
"Screenshot notes": LittleSnapper
Batch jobs of every kind: Automator
Archiving: Mac OS X' builtin zip function
Unarchiving: RAReXtract (very good one)
BitTorrent: Transmission

I have two Macs. An iMac 24” (Early 2008) and a MacBook 13” (unibody, late 2008)

Citing @ulfklose again: Please write a post yourself or leave your equipment in the comments.

Why do Germans always want special treatment?

I don't get it. When taking a look at the internet culture I am always fracked by being German.

Social networking with Germans is always a pain in the ass, because they always do something special and avoid getting connected to the rest of the world this way. I know it's a matter of opinion somehow, but I can't really get the point when it comes to building up a special German clone called "MeinVZ" or "StudiVZ" instead of just using Facebook like every other person on the planet does. You may always argue that you shouldn't roll with the mainstream or you shouldn't give a single service too much power, which is perfectly right. But when just building up a German version of it these arguments don't fit in. In the end it's just the Germans being isolated from the rest of the world's and this is exactly the pain in the ass that I am talking about.

I want to do social networking with my friends and my family. There's no way around it, I'm just having too much fun doing it to just leave it. But why the heck do they need to spread over dozens of websites and tell "I don't want to be on Facebook, I'm already registered with too many websites" instead of just joining the right one? lol. Sounds like I'm doing advertising for Facebook, but I'm not. Not taking any money for it anyway, I'm just pissed. I don't want these bad clones. And they actually are bad, that's for sure. Whoever is reading this and doesn't come from Germoney, be assured: I'm envious of you about not knowing these sites and the pain they're causing.