Updating to Rails 2.3.11 without using html_safe

Only thing not working as expected is that the h helper did escape html_safe output, but we can fix that easily…

# make h work the same no matter if a string is safe
# ERB::Util.h("
".html_safe).should_not == "
" module ERB::Util def html_escape(s) s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] } end alias h html_escape module_function :h module_function :html_escape end

A Fresh Start with Ubuntu Natty Narwahl

A fresh install for my laptop, with some Desktop tools ans all the rails/ruby stuff I need.

  1. Enable canonical partners in synaptic package manager
  2. Unmap main menu from super key (for rubymine + gnome-do)
    sudo apt-get install compizconfig-settings-manager
    open compiz application and rebind unity laucher @ “ubuntu unity plugin”

  3. Java sudo apt-get install sun-java6-jre && sudo apt-get remove openjdk-6-jre
  4. Git: sudo apt-get install git-core git-svn
  5. System wide RVM
    sudo su
    bash <<(curl -s https://rvm.beginrescueend.com/install/rvm)
    apt-get install zlib1g-dev libssl-dev libreadline5-dev
    rvm install 1.9.2
    rvm 1.9.2
    

    add rvm script to your .bashrc and to /root/.bashrc
    set defaults via rvm use xxx –default
    Re-login (or you get permisson denied on gem install).
    rvmsudo xxx to use gems as sudo.

  6. Ruco gem install ruco
  7. copy important dotfiles + firefox history/forms/… database from .mozilla
  8. dotfiles
  9. Multi-clipboard: sudo apt-get install glipper (available after restart)
  10. Skype + add skype to startup
  11. Application laucher: sudo apt-get install gnome-do + enable skype plugin
  12. Rubymine+ choose “meta is mapped to left win” in advanced keyboard layout options
    fix multi-clipboard issues:
    echo ‘idea.use.alt.clipboard.sync=true’ >> /opt/rubymine/bin/idea.properties
  13. Mysql:
    sudo apt-get install mysql-server mysql-client libmysql-ruby libmysqlclient-dev
    sudo aa-complain /usr/sbin/mysqld # fix apparmor denied bug
  14. Redis: sudo apt-get install redis-server
  15. Memcached: sudo apt-get install memcached
  16. ImageMagic: sudo apt-get install imagemagick libmagick9-dev
  17. Arial/Verdana etc fonts: sudo apt-get install msttcorefonts
  18. VirtualBox
  19. Nginx + Passenger
  20. Restrcited codes etc: sudo apt-get install ubuntu-restricted-extras
  21. Set a shortcut for clear+reset in terminal, so the history gets removed on keypress

Config files for heroku or duostack

To get config variables to herkou / duostack simply base64 encode them and store them into the ENV.
The cfg.rb is kept very simple, so you can also load it where rails is not yet loaded.
This scales to up to 3900 characters for duostack and 10000+ for heroku. Add gzip to get even more…

# lib/cfg.rb
require 'active_support/core_ext/hash/indifferent_access'

env = defined?(Rails.env) ? Rails.env : (ENV['RAILS_ENV'] || 'development')
config = if encoded = ENV['CONFIG_YML']
  require 'base64'
  Base64.decode64(encoded)
else
  File.read('config/config.yml')
end
CFG = YAML.load(config)[env].with_indifferent_access.freeze

# config/application.rb
require File.expand_path('../../lib/cfg', __FILE__)

# script/configure_heroku.rb
#! /usr/bin/env ruby
require 'rubygems'
require 'rake'
require 'base64'

config = Base64.encode64(File.read('config/config.heroku.yml')).gsub("\n","")
sh "heroku config:add CONFIG_YML=#{config}"

Creating a EC2 Micro instance via Fog

0.03c/hour (14€/month) is pretty cheap for a small server so lets try this 🙂

Generate and download a key-pair, so you can login to the instance via ssh.

AMI-id used is a micro ebs ubuntu 10.04 instance on eu-west-1, choose your own at http://uec-images.ubuntu.com/releases/lucid/release

Be sure to add ssh port to your security group or you will get a nice “port 22: Connection timed out”

Start the servers!

require 'fog'
fog = Fog::Compute.new(
  :provider => 'AWS',
  :region=>'eu-west-1',
  :aws_access_key_id => 'yyy',
  :aws_secret_access_key => 'xxxx'
)

# start a server
server = fog.servers.create(
  :image_id=>'ami-311f2b45',
  :flavor_id=>'t1.micro',
  :key_name => 'pey-pair-name'
)

# wait for it to get online
server.wait_for { print "."; ready? }

# public address -> ec2-79-125-45-252.eu- west-1.compute.amazonaws.com -> ssh into it
server.dns_name

# instance id -> find it again
fog.servers.get(server.id)

# shutdown
server.destroy

Connect via ssh

ssh -i KEY-PAIR.pem ubuntu@SERVER-DNS-NAME