Wednesday, January 14, 2009

Git: restoring accidentaly deleted files

To view a list of deleted files:
git ls-files --deleted

To restore a deleted file (assuming the D is not yet commited)
git checkout where/the/file/was.ext

Wednesday, December 3, 2008

custom assert_select_rjs matcher

Background:
I wanted to test rjs redirection:


Problem:
ActionController::Assertions::SelectorAssertions#assert_select_rjs don't know about :redirect_to

Solution:
I don't know if this is the right solution but I added this at the end of my test_helper.rb then I can assert by :redirect_to now


Tuesday, November 18, 2008

Application Controller

The file application.rb had just been officially renamed to application_controller.rb; and the special case in the code for checking it removed. I'm not even OC but this was also bothering me since I used rails.

The commit: fcce1f1

Thursday, October 30, 2008

reverse_sql_order

I just found this while browsing through AR Base's source code. It seems very useful.

Wednesday, October 29, 2008

"Only get, head, post, put, and delete requests are allowed." Ruby on Rails error

Only get, head, post, put, and delete requests are allowed.
If you get this while/after editing your routes, then you'll need to restart your local server. Thanks to this guy.

Friday, October 24, 2008

Using custom column type in Rails migrations

It seems if the type you gave to a column definition in a migration is not listed in native_database_types, Rails will just use what you gave it.

Therefore this will work:

Wednesday, October 8, 2008

Obi-Wan vs Yoda

I just realized this the other night while watching The Amazing Race though it seems to have been talked about since Episode 3 was released.

Obi-Wan:
Only a Sith deal in absolutes

Yoda:
Do, or do not. There is no try.


Friday, September 12, 2008

Rubyforge gem problem

Problem:

starting the server and you get:
 can't activate rubyforge (= 0.4.5), already activated rubyforge-1.0.0] (Gem::Exception)

Solution:
remove old versions of rubyforge gem
jorrel@helen ~ $ sudo gem uninstall rubyforge

Select gem to uninstall:
1. rubyforge-0.4.4
2. rubyforge-0.4.5
3. rubyforge-1.0.0
4. All versions
> 1
Successfully uninstalled rubyforge-0.4.4
jorrel@helen ~ $ sudo gem uninstall rubyforge

Select gem to uninstall:
1. rubyforge-0.4.5
2. rubyforge-1.0.0
3. All versions
> 1
Successfully uninstalled rubyforge-0.4.5
jorrel@helen ~ $ gem list | grep rubyforge
rubyforge (1.0.0)

Tuesday, June 17, 2008

Undo uncommitted changes in git

It seems that 'git revert' does not work the way that 'svn revert' does (reverting all uncommitted changes). I don't know if this is the proper way, but I 'reverted' my changes using 'git stash':


git stash
git stash clear

Update:

git reset --hard

Monday, April 28, 2008

Ubuntu Hardy + Firefox + Firebug

The old firebug is not working for firefox 3 beta 5 in Ubuntu Hardy; and so firebug 1.1 from the official site.

Solution: get the 'firebug' package from apt. :)

Tuesday, April 22, 2008

mod_rails + edge rails

Based on a recent conversation at phusion passenger google group, there is a bug wherein mod_rails fails to start its spawner for an application that uses edge rails.

Basically, you'll get this error (complaining about a failed 'to_constant_name' somewhere):

  Framework that failed to load:
Vendor directory: /path/to/vendor/rails
Error message:
Anonymous modules have no name to be referenced by
Exception class:
ArgumentError

More info about the bug can be found in the bug report filed by hongli


update: This seems to be fixed in edge rails + git passenger (though I havn't tried yet), as hongli's comment below says.

Monday, April 14, 2008

mod_rails + rails 2.0

I you encounter a "500 Internal Server Error" after setting up mod_rails in a recent (rails 2.0) application, you need to delete 'public/.htaccess'.

Monday, January 28, 2008

Detecting the googlebot

Detecting the googlebot as your site's visitor is easy by just checking user agent. Googlebot uses this user agent:
Googlebot/2.1 (+http://www.googlebot.com/bot.html)

And in the app, we can just check:
request.user_agent =~ /googlebot/i

Friday, January 25, 2008

Planned Music Purchases

Purchase albums:

and/or

once available and not too lazy to go to the mall.

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'
end
Edge rails has its own HttpAuthentication::Basic module:
class ApplicationController < ActionController::Base
USERNAME, PASSWORD = 'username', 'secret'
before_filter :basic_http_authentication
private
def basic_http_authentication
authenticate_or_request_with_http_basic do |username, password|
username == USERNAME and password == PASSWORD
end
end
end


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.