Monday, December 24, 2007

Windows + ext2/ext3 access

As of Ubuntu 7.10, we now have read/write access to NTFS drives via ntfs-3g. But what about the other way around? I just needed that ability today to get a file from my linux install. Since I'm too lazy to reboot twice; and since windows boots up very slow, I don't wan't to do this everytime I need a file from the other partition.

A bit of google searching and I found this app called the 'Ext2 Installable File System for Windows' which allowed me to mount my linux partitions to my preferred drive letter. It gives me read and write (root) access to those files - very cool.

Monday, December 10, 2007

Copying files using rsync

Use rsync to copy files to files between servers through ssh with continue option:
rsync -P --rsh=ssh from_machine:/path/to/source.file destination/path
-P is the same as '--partial --progress'

Sunday, November 18, 2007

Monaco for Ubuntu

Trying to copy the 'All Hallows Eve' textmate theme in kate, I got stuck with the Monaco font. After a little searching, I found a nice blog post which includes an instruction for adding the Monaco font to the system.

Basically, get the font and run the following code to put it in the fonts directory:
sudo mkdir /usr/share/fonts/truetype/custom
sudo mv Monaco_Linux.ttf /usr/share/fonts/truetype/custom/
sudo fc-cache -f -v

Tuesday, October 30, 2007

HTTP basic authentication

HTTP basic authentication can be done in old rails versions through this plugin.
class ApplicationController < ActionController::Base
htpasswd :user => 'username', :pass => 'secret'
Edge rails has its own HttpAuthentication::Basic module:
class ApplicationController < ActionController::Base
USERNAME, PASSWORD = 'username', 'secret'
before_filter :basic_http_authentication
def basic_http_authentication
authenticate_or_request_with_http_basic do |username, password|
username == USERNAME and password == PASSWORD

I haven't tried the edge rails version though.

Monday, October 29, 2007

Autotest and libNotify

After trying to get mumbles to work with pidgin, I gave up and just used gnome's libnotify for the notification. Fortunately, there's a pidgin-libnotify plugin which is just one apt (or synaptic) away.

I've installed and tried autotest(from the zentest gem) and it seems nice. I created my configuration file to make use of the red/green plugin and to throw notifications to libnotify. This is a great article about doing that. The red/green stuff is not that much useful/nice on my terminal however because I've set it to use the green on black color scheme.

Make sure you set the path of the ruby gems. It's somehow not automatic in my machine so I had to do it manually.

export PATH=$PATH:/var/lib/gems/1.8/bin

Thanks to google and this article.

Through ajaxian, I found a way to force Prototype to do cross site scripting. This may remove some ugly onload hacks I've done in finesay.

Saturday, October 20, 2007

Ubuntu Gutsy!

I finally installed Ubuntu Gutsy and got it working. I spent the whole night trying to move my windows xp installation from my SATA hard drive to my older IDE hard drive. I gave up by 3:30 a.m. so I just installed ubuntu on my IDE drivie.

After downloading the iso twice and burning it to a disk (also twice). I finally got the installer running but the screen was distorted (basically some of the left part of the screen was on the right, and some of the bottom part is above). I though it will be fixed once the installation went through but it didn't.

After searching the ubuntu forums, I found a similar problem and the fix: recofigure xserver.

sudo dpkg-reconfigure xserver-xorg

Don't remove hal this time.

Tuesday, October 16, 2007


Taken from my solution for a ruby quiz.

123.in_words # one hundred twenty three

module InWords
words = %w(zero one two three four five six seven eight nine)
words += %w(ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen)
%w(twenty thirty fourty fifty sixty seventy eighty ninety).each { |tens| words += [tens] + words[1..9].collect { |ones| "#{tens} #{ones}" } }
WORDS = words
MULTIPLIERS = [[100, 'hundred'], [1000, 'thousand'], [1000000, 'million'], [1000000000, 'billion']]

def in_words
if self < 100
value, text = MULTIPLIERS.reverse.detect { |value, text| self >= value }
multiplied_value, remainder = self / value, self % value
"#{multiplied_value.in_words} #{text}#{(remainder > 0) ? ' ' + remainder.in_words : ''}"
class Fixnum; include InWords; end
class Bignum; include InWords; end

if $0 == __FILE__
require 'test/unit'
class InWordsTest < Test::Unit::TestCase
def test_zero_to_nine
assert_equal 'zero' , 0.in_words
assert_equal 'one' , 1.in_words
assert_equal 'two' , 2.in_words
assert_equal 'three' , 3.in_words
assert_equal 'four' , 4.in_words
assert_equal 'five' , 5.in_words
assert_equal 'six' , 6.in_words
assert_equal 'seven' , 7.in_words
assert_equal 'eight' , 8.in_words
assert_equal 'nine' , 9.in_words

def test_ten_to_twelve
assert_equal 'ten' , 10.in_words
assert_equal 'eleven' , 11.in_words
assert_equal 'twelve' , 12.in_words

def test_teens
assert_equal 'thirteen' , 13.in_words
assert_equal 'fourteen' , 14.in_words
assert_equal 'fifteen' , 15.in_words
assert_equal 'sixteen' , 16.in_words
assert_equal 'seventeen', 17.in_words
assert_equal 'eighteen' , 18.in_words
assert_equal 'nineteen' , 19.in_words

def test_some_more
assert_equal 'twenty' , 20.in_words
assert_equal 'seventy seven', 77.in_words
assert_equal 'ninety nine' , 99.in_words

def test_hundreds
assert_equal 'one hundred' , 100.in_words
assert_equal 'three hundred', 300.in_words
assert_equal 'seven hundred seventy seven', 777.in_words
assert_equal 'eight hundred eighteen', 818.in_words
assert_equal 'five hundred twelve', 512.in_words
assert_equal 'nine hundred ninety nine', 999.in_words

def test_multipliers
assert_equal 'one thousand', 1000.in_words
assert_equal 'thirty two thousand seven hundred sixty seven', 32767.in_words
assert_equal 'ten million one', 10000001.in_words
assert_equal 'one billion two hundred thirty four million five hundred sixty seven thousand eight hundred ninety', 1234567890.in_words

Monday, October 15, 2007


Recent code I used in 2 projects. Useful but not enough to be put in active_core.

20.to_stopwatch # 00:00:20
class Numeric
def to_stopwatch
hours, remainder = (self / 3660).floor.to_i, self % 3660
minutes, seconds = (remainder / 60).floor.to_i, (remainder % 60).to_i
"#{sprintf("%02d", hours)}:#{sprintf("%02d", minutes)}:#{sprintf("%02d", seconds)}"

class NilClass
delegate :to_stopwatch, :to => 0