Tuesday, January 11, 2011

How to update the Gem.lock file for rails 3

Inside your app directory, just type in
bundle update

Monday, December 20, 2010

Bundler for ruby applications

I just found out that Rails3 is using Bundler to manage all of the gem dependencies.

This is just an awesome idea ;-)

I use to write custom deployment script for all of the new instances that I create in the cloud.

With this, you can easily manage the dependencies for your ruby application anywhere you choose to run.

Include ruby json gem into Rails3 automatically

First, install the gem from command line.
> sudo gem install json
Then, add the following line to Gemfile
gem 'json'

How to autoload libraries from lib directory for Rails3

Inside application.rb
module ApiServer
  class Application < Rails::Application
    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)
    config.autoload_paths += %W(#{config.root}/lib) 
  end
end

Thursday, December 31, 2009

How to mimic apache's "!-f" and "!-d" in lighttpd

Just a while ago, I was still trying to write a php script to load static content and send them to browser, now that I know apache has a nice rewrite condition like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d<
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I don't have to use that script of mine any more. However, I hit the wall straight on when I was trying to port the same functionality in lighttpd, and the only thing I found was
url.rewrite-[repeat-]if-not-file
Only half of the solution, and it somehow stopped working for me after working or 2 weeks, and says
WARNING: unknown config-key: url.rewrite-if-not-file (ignored)
gerrr.....

That did it ;-) I was determined to find the right solution to finish this for good, and here is what I have found:

Using mod_magnet and a small lua script. For detail, see the following urls.

http://www.akelos.org/wiki/setting-up-akelos-on-lighttpd-in-a-mac
http://redmine.lighttpd.net/projects/lighttpd/wiki/AbsoLUAtion

Oh, if you happen to be on ubuntu, you would probably also need to do this
sudo apt-get install lighttpd-mod-magnet

Monday, December 28, 2009

ubuntu's rc management

I hate to write these down, but I have been using these so often this winter break that I can't allow myself to do another search to find the answers.

To stop apache2 for this session only:
sudo /etc/init.d/apache2 stop

To remove apache2 permanently from startup scripts:
sudo update-rc.d apache2 remove

To reinstate apache2 in the startup scripts:
sudo update-rc.d apache2 defaults

Friday, April 4, 2008

jsdIScript

I was in the process of trying to figure out how to track the stack frames in javascript through jsd, and naturally, I wanted to see what's in jsdlScript ;-) So I hooked a logging method in the script enumerator, and found out that at least in Mozilla, javascript is counted in the unit of functions. Each function is treated as a jsdlScript object. This makes a lot of sense. (Well, not that it didn't make any sense.) It also explains, if a page has javascript files from different servers, it cannot distinguish the scripts origin based on the url of the file. Well, more fun for me working with the jsd ;-)