Happy New Year 2008
Rails and Leopard: A smooth upgrade
At 26th October, my leopard order arrived, I wrote about it on my other blog. I was testing it for my G5 machine, and it failed to install when I do upgrade of OS from Tiger to Leopard. Finally I found out, its not because of the bug inside the system, but it because of system conflict from some applications installed, so far I gather from some forums, these are the applications affected: ShapeShifter and Application Enhancer, both product from Unsanity. See this forum for more details. Just be prepared to uninstall all the application which you think can affect the default skin of Mac OS X. After that, get ready to back up all your file for pre-caution, so far from my experience, you do not need to do any backup if you do the upgrading of OS from Tiger to Leopard.
I have been thinking twice when I want to upgrade to leopard. Because Apple shipped Leopard with pre installed 29 gems, Ruby 1.8.6 and It run on ZFS or so called 64bits, rather than Tiger 32bits. The implication that may happen, if I do the upgrade, my current configuration and installation which installed with "make install" showed here, I afraid will be broken or overwrite by the default configuration after upgrading Leopard. Next is the Image Magick installation issue which I think will probably have some problems, memory leaked, and incompatibility issue , reason is the 64bits OS. Beside, I have a lot applications installed on my Tiger, and I have projects need to be done, I can't afford spending my time to clean install my Mac to Leopard and re-install all my applications, too much time taken. After a smooth upgrade I done for my fellow friend Hong Kiat, then only I tried out on my mac book.
After the upgrade, there are 2 installations of Ruby on Rails development kits, the first installation is from the carried over from Tiger, and the second one is from Leopard default. So there are 2 locations of Ruby on Rails Installation which is "/usr/local" because all my installation earlier is prefix to that location, and default leopard location can be found on "/usr/bin".
rubify:~ chardy$ which ruby /usr/local/bin/ruby rubify:~ chardy$ ruby -v ruby 1.8.5 (2007-03-13 patchlevel 35) [i686-darwin8.9.1] rubify:~ chardy$ rails -v Rails 1.2.5 rubify:~ chardy$ /usr/bin/ruby -v ruby 1.8.6 (2007-06-07 patchlevel 36) [universal-darwin9.0] rubify:~ chardy$ /usr/bin/rails -v Rails 1.2.3
And after the upgrade I found out, all my worry earlier can be easily solved, and I forgotten UNIX system can be set the environment, so I just point all my earlier Tiger environment to Leopard. Just copy modified ~/.profile file like below to point all my installation to /usr/local/bin. I still using ruby 1.8.5 for current development.
PATH="/bin:/sbin:/usr/bin:/usr/sbin" export PATH="$PATH:$HOME/bin" export PATH="/usr/local/bin:/usr/local/sbin:$PATH" export MANPATH="/usr/local/man:$MANPATH" export PATH="$PATH:/usr/local/mysql/bin"
I have encountered this problem when load the terminal.
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = "En_US",
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Then I inputed below to my ~/profile again:
# This setting is for the new UTF-8 terminal support export LC_CTYPE=en_US.UTF-8 export LC_ALL=en_US.UTF-8
And since I still use macport, I also added export PATH=/opt/local/bin:/opt/local/sbin:$PATH to ~/.profile
So, you can do upgrade to new Leopard operating system without a lot of worry. Just insert the DVD and upgrade. All other installation is taken care. Just restore your existing profile setting. Then roll it out :-) FYI, Leopard comes with both Apache 2.2 and 1.3, default on the Sharing control panel is boot up Apache 2.2. Have fun!
Watch out Hivelogic for his new articles about installation rails on leopard.
Rails Rumbles Just Ended
48 hours coding competition already over, I have produced an application, Please vote for me on wednesday :)

FOR

Recently, I addicted to blogging..
71%
Ruby one click installer for mac OSX Tiger
Once upon a time when I still use windows laptop as my workstation, I used to know there is a Ruby One click Installer for Windows. Just notice, another one click installer for mac is born. Visit http://rubyosx.rubyforge.org/ to download.

The good things are this package help to install basic framework to get you started with Ruby on Rails, It done the installation in UNIX way, which installed everything on /usr/local and it replaces the broken Readline library, updates to a current version of SQLite3 and prepares your OSX for Rails, which needs at least Ruby 1.8.4 to run.
After, do not forget to set your environment for /usr/local path.
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
But if you still prefer the Terminal way to install Ruby on Rails framework on OSX, I have fews good links below: (Just stick to these links, you will be fine)
Install Gem in Local User Directory for Back Up Purpose
It seems not maintainable when we have too many gems installed on your local machine gem repositories, indeed in UNIX machine, our access is granted by user group itself. How if one day, my harddisk crashes and I loss all my data, BTW, I only backup my home folder in this case. So due to this incident, I need to reinstall all my ruby gems again to get Ruby on Rails development environment ready to use. Too much work.
Try this to solve the issue, by installing all your gem inside you home folder.
$ cd ~ $ mkdir .gem $ export GEM_PATH=~/.gem $ gem install -i ~/.gem haml
You can also put this export GEM_PATH=~/.gem to your ~/.profile or ~/.bash_profile.
Whats the .gem directory look like:
$ ls ~/.gem ./ ../ bin/ cache/ doc/ gems/ source_cache specifications/
No More Angry but Piss Off
It's always going to be true. No matter what (who) she/him is.
Colorize your terminal logging.
When you running your rails application via mongrel or lighttpd by using script/console command in development mode, you can see the terminal logging running in colorize mode, come to an idea to creating the same logging output for some of my background process. Do you know what is actually made up the color on the terminal? Basically it just special character code to color the terminal, and every terminal application have slight different implementation. Last time I was playing around with hyper terminal application and found this, then implement this on mac terminal.
I have make a simple method to do this for ruby programming language:
# usage:
# format_log("This is log message", {:background => "red", :foreground => "white", :special => "reset"})
#
def format_log(str, params)
specials = {
"reset" => 0,
"bold" => 1,
"half-bright" => 2,
"underscore" => 4,
"blink" => 5,
"reverse" => 7,
"normal-bright" => 22,
"no-underline" => 24,
"blink" => 25,
"no-reverse" => 27
}
foregrounds = {
"black" => 30,
"red" => 31,
"green" => 32,
"black" => 30,
"red" => 31,
"green" => 32,
"brown" => 33,
"blue" => 34,
"magenta" => 35,
"cyan" => 36,
"white" => 37
}
backgrounds = {
"black" => 40,
"red" => 41,
"green" => 42,
"brown" => 43,
"blue" => 44,
"magenta" => 45,
"cyan" => 46,
"white" => 47,
"default" => 49
}
puts "\033[#{backgrounds[params[:background]]};#{foregrounds[params[:foreground]]}m #{str} \033[#{specials[params[:special]]}m"
end
Sample below:
It tested on mac terminal, not sure whether is running on others. When free, I will make this tiny little helper to become a more mature plugin :-)
Rake Tutorial
Nice introductory tutorial on Rake from the guys @ Rails Envy, which provides a brief history, introduces concepts such as tasks and namespaces and talks about its role within Rails.
Back From Rails Conf 2007
Back to Singapore again at 25th May 2007. Having jet lag, and get myself a good rest after that. The trip was awesome, this is my first time to travel so far. Really truly aspiring that Railsconf 2007 attendee reach 1600 people, prove that Rails Community grow rate is high. Chad Fowler bring the message about community, a call to community which every one working together, support and bring up the Rails community.
Chad introduced David to talk about Rails 2.0. According to DHH, "Rails 2.0 is not a beautiful unicorn, won't solve all your problems, and it is real. I think to myself, okay need to shoot for The Rails Way being about 2.0, perhaps even the first Rails 2.0 book? The timing might be perfect."
David's 9 things I love about Rails 2:
- Breakpoints are back AND drop-in debugging is now supported! The debugging console pops up right in the Mongrel process. Looks really good and powerful. David says, "Kent Sibilev deserves a world of thanks for getting this to work.
- HTTP performance improvements. The _include_tags now have a :cache=>true option that combines JS and CSS files together and gzips them to drastically improve performance.
- ActiveRecord QueryCache. Caches queries that have already been executed for performance boost.
- Renderers and mime types not conflated in the naming of the view templates anymore. (Refers to the new .erb and .builder extensions), Javascript and CSS packaging and zipping.
- Better config and initializer directory structure cleans up the mess of environment.rb
- Sexy migrations! Big improvement in the syntax of migration files and an example of a 3rd party plugin making it into core very quickly.
- Much better HTTP authentication support baked in.
- MIT license assumed now. Plugin generator script adds the MIT license by default.
- Spring cleaning. Improvements to basic Rails code and lots of 1.2 deprecations being moved out completely now.
____ _ __ _ __
/ __ \____ _(_) /____ (_)____ / / ____ _ _____
/ /_/ / __ `/ / / ___/ / / ___/ / / / __ \ | / / _ \
/ _, _/ /_/ / / (__ ) / (__ ) / /___/ /_/ / |/ / __/
/_/ |_|\__,_/_/_/____/ /_/____/ /_____/\____/|___/\___/
Meanwhile, I plan to blog about my thought about the RailsConf 2007 session content which I attending.
Web Developer Tool on IE
There’s a toolbar for Internet Explorer that has many of the same features as Firebug for Firefox.
Visit here to get a copy of the current beta.
To launch it, start IE7 and go to Tools -> Toolbars -> Explorer Bar -> IE DOM explorer.
You can inspect the DOM, the HTML elements, the CSS, and many more stuffs.
NB: I am using Windows XP via Parallels Virtual Machine.
Faster your mail.app
There is still another way to do it, using sqlite3 command.
How to do it?
1. Quit your Mail.app
2. Open Terminal.
3. Type the following:
rubify:~$ cd ~/Library/Mail rubify:~/Library/Mail chardy$ sqlite3 Envelope\ Index rubify:~/Library/Mail chardy$ sqlite> vacuum subjects;When the sqlite prompt returns, type Control-D to exit. Restart Mail and enjoy the extra speed. I reduced from 37.5MB of "Envelope Index" folder to 4.4MB . Quite cool.
rubify:~/Library/Mail chardy$ du -hs Envelope\ Index 4.4M Envelope Index
Cheer.
Chunked Array
# use as standalone function def chunk_array(array, pieces=2) len = array.length; mid = (len/pieces) chunks = [] start = 0 1.upto(pieces) do |i| last = start+mid last = last-1 unless len%pieces >= i chunks << array[start..last] || [] start = last+1 end chunks end # use as array.chunk class Array def chunk(pieces=2) len = self.length; mid = (len/pieces) chunks = [] start = 0 1.upto(pieces) do |i| last = start+mid last = last-1 unless len%pieces >= i chunks << self[start..last] || [] start = last+1 end chunks end end
