Rabu, 24 Oktober 2012

Rails setup in linode

  1. Login to linode
  2. choose linux distribution (ubuntu)
  3. allocate disk space and swap
  4. boot
  5. remote access using ssh
  6. apt-get update
    apt-get upgrade --show-upgraded
  7. set hostname:
    echo "ayahirano" > /etc/hostname
    hostname -F /etc/hostname
  8. nano /etc/hosts localhost.localdomain localhost ayahirano.invalid  hirano
    2600:3c01::a123:b456:c789:d012 ayahirano.invalid hirano
  9. set timezone to UTC:
    dpkg-reconfigure tzdata
  10. install required libs:
    apt-get install build-essential zlib1g-dev libssl-dev libreadline6-dev libxslt1-dev libcurl4-openssl-dev apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev git-core
  11. install require lib for postgresql (optional):
    apt-get install postgresql postgresql-contrib libpq-dev
  12. create new user:
    adduser example_user
    usermod -a -G sudo example_user
  13. logout and relogin user the new user
  14. disable root login:
    sudo nano /etc/ssh/sshd_config
    PermitRootLogin no
  15. setup postgresql (optional):
    sudo -u postgres createuser --superuser example
    sudo -u postgres psql postgres
    \password example
    sudo nano /etc/postgresql/8.4/main/postgresql.conf:
    listen_addresses = 'localhost'
    sudo nano /etc/postgresql/8.4/main/pg_hba.conf:
    local       all        all                      md5
    sudo /etc/init.d/postgresql start
  16. install rvm:
    \curl -L https://get.rvm.io | bash -s stable
    source /home/example_user/.rvm/scripts/rvm
  17. install ruby:
    rvm install ruby
  18. disable gem documentation installation:
    nano ~/.gemrc
    gem: --no-ri --no-rdoc
  19. install passenger:
    gem install passenger
    rvmsudo passenger-install-apache2-module
  20. get your app to /var/www/example
  21. disable default virtual host:
    sudo a2dissite default
  22. create new virtual host config:
    sudo nano /etc/apache2/sites-available/example
    <VirtualHost *:80>
      ServerName ayahirano.invalid
      ServerAlias *.ayahirano.invalid
      RailsEnv production
      DocumentRoot /var/www/example/public

      <Directory /var/www/
        AllowOverride all
        # MultiViews must be turned off.
        Options -MultiViews
  23. enable it:
    sudo a2ensite example
  24. edit apache configuration file:
    sudo nano /etc/apache2/mods-available/passenger.load
    LoadModule passenger_module /home/rails/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
    sudo nano /etc/apache2/mods-available/passenger.conf
    PassengerRoot /home/rails/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17
    PassengerRuby /home/rails/.rvm/wrappers/ruby-1.9.3-p286/ruby
  25. enable passenger module:
    sudo a2enmod passenger
  26. restart apache:
    sudo service apache2 restart


Installing nodejs for js runtime (needed by assets precompile):


Creating deploy script

  1. cd $HOME
  2. nano deploy.sh
  3. #!/bin/sh
    sudo echo -n "precompile assets? (y or n) : "
    read precompile
    echo -n "bundle install? (y or n) : "
    read bundler
    cd /var/www/example
    git pull
    if [ $bundler = y -o $bundler = Y -o $bundler = yes -o $bundler = Yes -o $bundler = YES ]; then
      bundle install --without development test
    if [ $precompile = y -o $precompile = Y -o $precompile = yes -o $precompile = Yes -o $precompile = YES ]; then
      bundle exec rake assets:precompile RAILS_ENV=production
    rake db:migrate RAILS_ENV=production
    # any other thing you do when deploying...
    sudo service apache2 restart
  4. chmod 700 deploy.sh
  5. Done.. To run use: ./deploy.sh

Selasa, 18 September 2012

tcs-ruby: faster ruby for windows

As a rails developer using windows as my development machine I often getting annoyed on how much time needed to start things especially tests.
In case you're wondering why did I use windows instead of other OS-es better suited for ruby like MacOSX/linux it's because I'm comfortable with it and if you're disagree then feel free to stop reading at this point :)

Several days ago I found about this fork of ruby by TheCodeShop which will speed up things quiet significantly, I decided to try it and one of my project unit tests which needed around 45 sec to complete reduced to less than 20 sec.


This step assume you're using Win7 with pik to manage multiple ruby installation, if you don't have pik yet get it from https://github.com/vertiginous/pik

  1. Download one of ruby build from:
    (I'm using winio one)
  2. Extract it, for example to C:\Ruby-tcs193
  3. Modify Path to use ruby-tcs: go to Control Panel, System, Advanced System Settings, Environment Variables
  4. Edit Path in User variables, modify existing Ruby bin path to ruby-tcs bin (C:\Ruby-tcs193)
  5. Add new variable RUBYOPT with value: "-rfenix/replace"
  6. Next, add it to pik (you can stop here if you didn't use pik, but I recommend it in case you need to switch to standard ruby)
  7. open cmd, then enter "pik add [path to ruby-tcs bin]" for example "pik add C:\Ruby-tcs193\bin"
  8. Lastly install devkit for it, run "ruby c:\devkit\dk.rb init" then "ruby c:\devkit\dk.rb install"
  9. Done :)

Known problems

Heroku commands

heroku commands will raise error because of non existing fenix/replace, to fix simply remove RUBYOPT temporarily by entering "set RUBYOPT="

Standard ruby

same as above because standard ruby didn't use fenix so remove RUBYOPT temporarily

Kamis, 09 Agustus 2012

Web page Al Bhed translator javascript (bookmarklet)

well long time no post :D

recently I don't have much to do and rather than dying from boredom I created a simple javascript to translate a web page to Al Bhed language (from Final Fantasy X if you're wondering)

The Base translation mapping come from http://nysa.cx/albhed/ and I just converted it to javascript.

Anyway here are the script:
javascript: (function(){var f=document.createElement('script'); f.src = 'http://al-bhed-page-translator-js.googlecode.com/files/albhed.js'; document.head.appendChild(f);})();
just copy and paste it into the browser address bar in the page you want to translate. (keep in mind that newer firefox block this kind of script, and you need to use bookmarklet for that)

To translate the page back to original, simply use this script:
javascript: (function(){alTranslate(true);})();

That's it :)

Known bugs:
- html encoded character such as &nbsp; didn't translate properly, it's fixable but I'm too lazy to fix it :P
- huge page might causing the browser to freeze, also should be fixable by adding some timeout but again, I'm lazy :D

Minggu, 01 Januari 2012

using compass in rails 3.1.3

group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
  gem 'compass', '>= 0.12.alpha'

config.assets.precompile << /(^[^_]|\/[^_])[^\/]*$/

Sabtu, 31 Desember 2011

ubuntu 11.10 rails 3 passenger