About ruby on rails, hackintosh, iphone3g and etc.

Saturday, February 28, 2009

Uninstall SleepWatcher

To unistall SleepWatcher (an useful tool for sleep/wake in OSX)

uninstalling sleepwatcher:

go to terminal
sudo rm /usr/local/sbin/sleepwatcher
sudo rm /usr/local/share/man/man8/sleepwatcher.8
sudo rm /etc/rc.sleep
sudo rm /etc/rc.wakeup

go to finder delete: /Library/StartupItems/SleepWatcher

need your passwd

Thursday, February 26, 2009

SQL SUM() in Rails

In Rails, Active Record support many types of calculations. It saves us from executing SELECT SUM(x) using the query. Everything can be shorten down one line of code.

Example:
To find sum of all items in a location:

Item.sum('location_id', :conditions =>['location_id = ?', location.id])

Similar to avg and others. See ActiveRecord API for more info.

Hackintosh X61 updated to 10.5.6

Finally managed to find some time and courage to update the Thinkpad X61 to 10.5.6.


Everything is ok now after initial problem with keyboard and pointing stick. I used the steps below:

1. Download PC-EFI ver 9.0. Install it. Link.
2. Download DDT-Path tool and run it. Link.


3. Notebook User: Get the PS/2 fix reader. Download from here. Also, you have to get ready usb keyboard and mouse as PS/2 mouse and keyboard may not functional after the 10.5.6 update.
3. Reboot your computer to make sure everything is fine.
4. Download OSX 10.5.6 update from Apple. If update from 10.5.5 (you can use the delta update), the rest use the combo update.

5. If you encounter error like system freeze during installation, restart your computer. Remove any external monitor connected (if you are using notebook). Reapply the 10.5.6 update. Reboot again.

6. If you encounter problem like sleep image has garbaged. You can disable deep sleep and remove earlier image at this path:

Disable Safe Sleep first:

To disable safe sleep, run the two following commands in Terminal:
$ sudo pmset -a hibernatemode 0 $ sudo nvram "use-nvramrc?"=false

Fire up Terminal. Run this

cd /var/vm

There is a file name called sleepimage. Delete this file by:

sudo rm sleepimage.

7. That's all. You can run Software Update to update the rest of security patches, Safari updates or iWork 08 patches and etc which requires 10.5.6.


Sunday, February 22, 2009

Install github on Mac OSX

Github is very useful for Ruby on Rails programmers. A lot of plugins and sample codes available. To use git in Mac OSX, you will need to install github by the following link:


Download the installer for OS X. That's all.

Open Flash Chart

OpenFlashChart is an excellent flash based charting tool. It has been ported to Ruby. A very useful tutorial by pullmonkey.com http://pullmonkey.com/2008/7/25/using-a-database-to-populate-an-open-flash-chart-graph.

To install the plugin:

script/plugin install git://github.com/pullmonkey/open_flash_chart.git

Then, copy swfobject.js from the plugin's assets/ directory. 

That's all. For coding steps, please refer to the link above.

"Code below extracted from pullmonkey.com"

open_flash_chart_object()

Usage:

This method returns only the graph html:
@graph = open_flash_chart_object(....)

Arguments

  • width (required)
  • height (required)
  • url (required)
  • use_swfobject (optional and defaults to true)
  • base (optional and defaults to "/")
  • swf_file_name (optional and defaults to "open-flash-chart.swf")

Tuesday, February 10, 2009

Core of Dieter Rams' 10 principles for good design

Good design is innovative.
• Good design makes a product useful.
• Good design is aesthetic.
• Good design helps us to understand a product.
• Good design is unobtrusive.
• Good design is honest.
• Good design is durable.
• Good design is consequent to the last detail.
• Good design is concerned with the environment.
• Good design is as little design as possible

Wednesday, February 4, 2009

Changes in production database

After deploying rails into production environment, I do need to do updates on database tables and others as user requirements added on. Here is the method to do migration on production databases.

rake db:migrate RAILS_ENV="production"


Rails Validate More than 1 Primary Key

In Ruby on Rails, you can specify your model class to validate uniqueness of multiple columns (multiple primary key). Here is the command:

validates_uniqueness of :email, :scope => :name

if you want to validate uniqueness of a triplet or more

validates_uniqueness of :first_attr, :scope => [ :second_attr,
:third_attr ... ]

Monday, February 2, 2009

Connecting Rails to MS SQL Server 2000

The fasted method to connect Rails to MS SQL Server 2000 is using ODBC. Install gem plug-in using the command below:

gem update --system

gem install activerecord-sqlserver-adapter --source=http://gems.rubyonrails.org

Next steps are very important. It is very common for Windows database developer but not if you are from other platform like OSX or Linux.

Create DSN (Data Source Name) in Administrative Tools, Data Sources (ODBC).




Important!!! Make sure the default database is set to the database you wanted to use. Else it will default to Masters database.

Remember the Data Source Name.

Next is to configure your database.yml file in Rails config directory

Here is the settings:

production:
  adapter: sqlserver
  mode: odbc
  dsn: SMSdb
  username: USERNAME
  password: PASSWORD

Try using the rake migration command in my earlier post.

For DSN less configuration (means does not need to create a DSN in Data Sources (ODBC)).

database.yml settings:

development:
    adapter: sqlserver
    mode: odbc
    dsn: DRIVER=/opt/local/lib/libtdsodbc.so;TDS_Version=8.0;SERVER=sqlserver.com;DATABASE=DBNAME;Port=14330;uid=dbusername;pwd=dbpassword;