Wednesday, July 29, 2009

SCP files with spaces in filenames

I wanted to transfer a custom ringtone to my iPhone.

Joy Ride.mp3

Doing the following Secure FTP command from my iPhone will fail.

scp jasonong@192.168.1.2:working/Joy\ Ride.mp3 .

Even this will fail.

scp jasonong@192.168.1.2:working/"Joy Ride.mp3" .

Finally,

scp jasonong@192.168.1.2:working/"Joy\ Ride.mp3" .

Transfered!

Easy command line search with grep and find

I've been using grep and find for searches on command line.

Examples:

# Search recursively for 'User' in file contents under current directory
grep -r 'User' .

# Search recursively for 'User' in file contents under current directory and display 2 lines before and after
grep -r -2 'User' .

# Search recursively for 'User' in file contents under current directory and display 2 lines before and after with color
grep -r -2 --color 'User' .

# Search for filenames that contains user.
find . -name 'user.*'


Combine them together:

grep -r -2 --color 'User' $(find . -name 'user.*')

How to change Tilda font size & open URL links

I used to love YaKuake, the "Quake" like drop-down console that you can activate at the touch of a customized button (it's F1 for me). But Yakuake relies on KDE for GUI which makes it look UGLY on Ubuntu's default Gnome desktop manager. Found an GTK alternative aptly named ~ Tilda (I remembered Counterstrike console was triggered by ~)

But Tilda's default font size's really too big. The GTK preference window didn't have any options to choose fonts & size. Mucking around .tilda folder in home directory shows 2 config files


.tilda/config_0
.tilda/config_1


Where there's a config option for font size


font="Monospace 13"


Ah that's why it's so huge! Thought changing it will be a simple act of replacing the "Monospace 13" to "Monospace 10". However after restart Tilda keeps getting to original font string. Doing tilda --help shows there's a -f option. So all I have to do to change the font is execute the following during Gnome startup


tilda -f "Monospace 10"

Update

tilda config files should only be edited with tilda closed. Else it will save the settings that before tilda was edited!

To open URL links, use "CTRL + Left click"

Monday, July 27, 2009

Webrat's fill_in method on cucumber

Consider the following:

In feature:

And I fill in "Telephone (Home)" with "61234567"

In webrat steps:

When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
fill_in
(field, :with => value)
end

The error encountered:

Could not find field: "Telephone (Home)" (Webrat::NotFoundError)

At first I thought the regex couldn't parse "(Home)" properly as "(" & ")" are control characters in regex. Turns out it's because the way webrat's fill_in method looks for the field. I had to use the following instead for the nested form field.


And I fill in "enrollment_addresses_attributes_0_telephone_home" with "61234567"

Super easy and fast cd ripping using abcde on the command line

Am ripping my new Pat Matheny cd to mp3 using abcde on the command line now. Just type in "abcde" and answer a few simple questions and hey presto!


~/projects/aims. Yes, my Master? abcde
Executing customizable pre-read function... done.
Getting CD track info... Querying the CD for audio tracks...
Grabbing entire CD - tracks: 01 02 03 04 05 06 07 08 09 10 11 12
Checking CDDB server status...
Querying the CDDB server...
Obtaining CDDB results...
Retrieving 1 CDDB match...done.
---- Pat Metheny Group / Letter From Home ----
1: Have You Heard
2: Every Summer Night
3: Better Days Ahead
4: Spring Ain't Here
5: 45/8
6: 5-5-7
7: Beat 70
8: Dream of the Return
9: Are We There Yet
10: Vidala
11: Slip Away
12: Letter From Home

Edit selected CDDB data? [y/n] (n):
Is the CD multi-artist? [y/n] (n):
Grabbing track 01: Have You Heard...
cdparanoia III release 10.2 (September 11, 2008)

Ripping from sector 0 (track 1 [0:00.00])
to sector 28939 (track 1 [6:25.64])

outputting to /home/jasonong/projects/aims/abcde.a20e7d0c/track01.wav
.......

Wednesday, July 22, 2009

Search for codes in your files quickly with grep

Sometimes when I do unit tests or cucumber tests I'll encounter an error that I've roughly aware of the offending code but not sure which files it resides in. That's where grep comes in useful.

Search for occurrences of ".name" in view files recursively


grep '.name' -r app/views


Get occurrences with its surrounding 2 lines before and after


grep '.name' -r -2 app/views

Monday, July 20, 2009

Error using cucumber, selenium and firefox 3

Cucumber and Webrat works great for Behaviour Driven Development (BDD). In certain situations it's better to couple Cucumber with Selenium especially when we need to test javascript or have a look at the test visually.

When I first started Cucumber and Selenium on my Ubuntu. Selenium-server throws up saying that firefox 3 path isn't defined. Thankfully a blog article by Tze Yang presents a solution.However I still get the annoying error every now and then when firefox 3.0 was upgraded. This is because of the firefox executable is a symlink to a shell script.



ls -l /usr/bin/ | grep firefox

lrwxrwxrwx 1 root root 11 2009-06-13 13:32 abrowser -> firefox-3.0
lrwxrwxrwx 1 root root 11 2009-06-13 13:32 abrowser-3.0 -> firefox-3.0
lrwxrwxrwx 1 root root 33 2009-07-21 00:34 firefox -> firefox-3.0
lrwxrwxrwx 1 root root 32 2009-06-13 13:32 firefox-3.0 -> ../lib/firefox-3.0.11/firefox.sh

lrwxrwxrwx 1 root root 31 2009-07-01 00:42 firefox-3.5 -> /home/jasonong/.firefox/firefox


The trick then is to change the firefox symlink to the actual firefox 3 executable.


sudo rm /usr/bin/firefox
sudo ln -s /usr/lib/firefox-3.0.11/firefox-3.0 firefox


That should get you some nice cucumber + selenium action.