Weekly #2

Weekly round-up of Ruby and Rails related news and articles.

  • ROFLBALT - First of all, CANABALT is an awesome game (I wasn’t aware of CANABALT until I read this post and you should try it. Too bad they didn’t create it on Android) and ROLFBALT is a Ruby port of it. Reading their code makes me wonder how should I write unit tests for a game application?
  • browsernizer - Rack middleware for redirecting unsupported browser requests to “please upgrade” page. Neat.

Weekly #1

Weekly round-up of Ruby and Rails related news and articles.

  • A Chat with Nick Quaranto - Ever wonder how rubygems.org internal looks like?
  • TorqueBox - A new kind of Ruby application platform that integrates Ruby on Rails. Built upon JBoss AS Java application server. Functionality such as clustering, load-balancing and high-availability is included right out-of-the-box
  • Vim for Rails developers

One of Ruby's better-kept secrets: how to get temporary directory →

Here’s how

require 'tmpdir'
puts Dir.tmpdir

How to add working directory to $LOAD_PATH

Simply

$:.unshift File.dirname(__FILE__)

How to install rmagick gem on Ubuntu 10.04? →

Why can’t I remember this?

$ sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
$ gem install rmagick

My Ruby on Rails on Windows setup

I am not a Windows fanboy but sometime I have to use it. Here is my current Ruby on Rails environment setup on Windows 7.

Since I dealing with console (Command Prompt) a lot, so before I setup Ruby and Rails, I install these 2 nifty tools first.

Console

Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles.

Get it here.

ANSICON

I like colored console output mainly because I often dealing with log files. ANSICON is a tool that provide those colors.

Here is how I install it

  • Extract ansi140.zip to C:\bin so you have C:\bin\ansi140
  • Add C:\bin\ansi140\x86 to Path
  • Fire the Command Prompt, type and enter: ansicon -i

The last command you run will install ansicon permanently. To uninstall ansicon, simply close any programs that currently using it and run ansicon -u from the Command Prompt.

Now the Ruby part. In summary, I install the 1.8.7 version first, then pik the Ruby version manager and then the Ruby Development Kit.

Ruby 1.8.7

Download and run rubyinstaller-1.8.7-p334.exe, install Ruby in their default folder C:\Ruby187 and don’t forget to check ‘Add Ruby executables to your PATH’.

Open up a Console and execute

ruby -v 

and you should get

ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]

pik

First, you want to update your gem

gem update --system

I usually don’t need ri and rdoc from the installed gems so I disabled it by default. Create a file named .gemrc in your home directory

C:\Users\YourUserName

with the following content

gem: --no-ri --no-rdoc

Now install pik

gem install pik

Read the rest of the installation manual here

Development Kit

Installing native gem has never been easy for Windows people, until DevKit came in into the scene. Follow the detailed instruction here.

Download DevKit and extract to C:\DevKit then from a Console

cd C:\DevKit
ruby dk.rb init

Test your installation by installing rdiscount gem

gem install rdiscount --platform=ruby

rdiscount should installed correctly

ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html

you should see

<p><strong>Hello RubyInstaller</strong></p>    

XAMPP (for the MySQL)

No suprise that you will also need MySQL on your Windows setup. I use XAMPP. To connect your Rails app to MySQL you will need mysql2 gem. This is how to install mysql2 on Windows 7 using XAMPP

gem install mysql2 -- --with-mysql-include=C:\xampp\mysql\include --with-mysql-lib=C:\xampp\mysql\lib\opt

Done!

Now you are ready to build the next big thing in web application industry using Rails right from your Windows box.

Deploying WordPress with Capistrano using wp-cap

Here is the steps:

  1. Clone wp-cap to a directory, e.g. my-wordpress git clone git://github.com/adamhunter/wp-cap.git my-wordpress
  2. Copy your WordPress files to my-wordpress/public so you will have

    my-wordpress/
    ├── config
    └── public
        ├── wp-admin
        ├── wp-content
        └── wp-includes
    
  3. You want to point your WordPress domain to my-wordpress/public

  4. Move my-wordpress/public/wp-config-sample.php to my-wordpress/config/wp-config-sample.php

    my-wordpress/
    ├── Capfile
    ├── config
    │   ├── deploy.rb
    │   └── wp-config-sample.php
    ├── public
    │   ├── index.php
    │   ├── license.txt
    │   ├── readme.html
    │   ├── wp-activate.php
    │   ├── ...
    
  5. Now make sure your WordPress installation is good to go

  6. Push your changes in my-wordpress to your own Git repository
  7. Edit my-wordpress/config/deploy.rb to conform your production environment. You will need to set:

application: this is the name of your application and the folder it will reside in on your server domain: this is the domain of your app user: this is the user that will be used to SSH and copying your files to your server git_domain and git_user should be self explanatory db_name, db_user, db_pass, db_host and db_prfx are all pretty self explanatory too if you have ever read through wp-config-sample.php. If you haven’t, go do that right now.

  1. Run cap deploy:setup
  2. If everything is good, run cap deploy

I created an example of WordPress setup using the wp-cap deployment script here

Rails + SQL Server 2000 on Windows XP

Obviously they are not a perfect match, but somehow I need to get this done. I did this on Windows XP with SQL Server 2000 (PE) Service Pack 4.

  1. Install Ruby 1.9.2-p0
  2. Install DevKit
  3. Install rails gem install --version 2.3.9 rails
  4. Install ruby-odbc gem install ruby-odbc --platform=ruby
  5. Install activerecord-sqlserver-adapter gem install --version 2.3.10 activerecord-sqlserver-adapter
  6. Create an ODBC data source
  7. In config\database.yml,

adapter: sqlserver mode: odbc dsn: your_dsn_name host: localhost username: sa password: your_password database: your_database encoding: utf8

Bonus

If you wish to add some custom gem configuration , you should create .gemrc file in your home directory, mine is C:\Documents and Settings\username.

Dave Newman: Leaving .net →

We are, as software developers, in various states of alone-ness.

A company I worked at once had been operating for years under the assumption that it was OK for software to take months to integrate and deploy; they had never heard of continuous integration. They thought it was normal to rewrite…

(Source: whatupdave)