About ruby on rails, hackintosh, iphone3g and etc.

Saturday, January 31, 2009

Uninstalling Xcode

Due to some reasons, you may want to uninstall xcode. Here is the command:

sudo /Developer/Library/uninstall-devtools --mode=all

Friday, January 30, 2009

Starting Rails in Production Environment

Once moving the database to production environment, next is to run rails in production environment. There are a few commands like:

mongrel_rails start -e production

(start mongrel server in production environment)

rake RAILS_ENV=production

Or for console testing:

ruby script/console production

Moving Rails to Production Database

After development (better during development) of rails application, it is good to move/try out the production database environment. To move to production database (e.g. from sqlite to mysql), firstly need to modify the database.yml file in /config directory of rails app.

database.yml

production:
adapter: mysql
database:
username: root
password:
socket: /path/to/your/mysql.sock

Change the database name to your database name. For mysql, create a schema that match the schema name. Enter the username and password, try to avoid root. 

In mysql terminal, create a dababase schema using this command:

mysqladmin -u root -p create

Create a user for this schema and use the username. Leave socket field as it is.

Save database.yml and execute the command below:

rake db:schema:load RAILS_ENV=production

There maybe error if mysql gem plugin is not installed, this can be resolved by this command:

gem install mysql

References:

Thursday, January 22, 2009

Using id after update/create command for rails

In rails, there is a useful method as to capture the id of a record upon successful creation of the record in database.
Example code:

@contact = Contact.new(params[:contact])

respond_to do |format|
if @contact.save

Listing above shows typical execution of creating a row in rails model. Upon save, rails will automatically populate the @contact class with the id generated from database. (@contact.id)

So we can continue to use the following:

@contact = Contact.new(params[:contact])

respond_to do |format|
if @contact.save
#create empty contact details with only contact id
@contact_details = ContactDetails.new()
@contact_details.contact_id = @contact.id
@contact_details.save

@contact.id can be used to populate foreign key of @contact_details.

Friday, January 9, 2009

My Hackintosh Desktop



Configuration:
ThinkPad X61 (Non-Tablet) with 4GB RAM & 2.2GHz Core 2 Duo using iDeneb 10.5.5
Screen Resolution: 1920x1200 with full hardware support of QE/CI




Print Screen Equivalent in OSX (Screen Capture)

In Windows, there is a key to capture screen quickly. Print Screen is the one. Or to capture an individual Window you can use ALT-Print Screen.

In Mac OSX, it is different. There is no such key. Never mind. There is a couple of short cuts which you can use.

1. CMD + SHIFT + 3 - Capture whole screen.
2. CMD + SHIFT + 4 - Gives you a crosshair cursor so you can choose which area of the screen you want to capture then write it to a PNG file on desktop.
3. CMD + CTRL + SHIFT + 4 -gives you a crosshair cursor so you can choose which area of the screen you want to capture and copies it to clipboard. You can paste it into another application like Photoshop and etc.

Have fun.

Thursday, January 8, 2009

vi QuickStart


Starting vi

From the command prompt, type vi and press the enter key. Or, to edit a specific file, type vi, then a space, then the filename, then the enter key.

Examples:
vi Starts vi with no text file name.
vi example.c Starts vi editing the file example.c. If example.c does not exist it will be created when the file is saved.

Quitting vi

From inside vi, type ZZ (shift zz) to save changes and quit. To quit vi without saving the chages type ":q!" without the quotes followed by the enter key.
ZZ save file and quit.

:wq save file and quit.
:q Quit without saving. Gives an error message if the file has been modified since its last save.
:q! Quit without saving and without a warning message that the file was changed.


Editing in vi

There are two modes in vi: command mode and edit mode. vi begins in command mode. To move the curser around use the arrow keys or the h, j, k, and l keys. To enter text from the command mode, first type "i" to insert, which is part of the text entry mode. Then, start typing to enter text before the cursor. Hit the escape key to return to the command mode.

arrow keys move cursor around in vi.
h, j, k, and l keys move cursor around in vi.
i insert at current cursor location.
a insert one character after cursor location (append mode).
A insert at end of current text line.
o creates a new line for editing below current line.
O creates a new line for editing above current line.
x delete character under cursor.
dw delete the characters to the end of the word starting from the current cursor location.
escape key IMPORTANT: returns from edit mode to command mode.
G go to line number specified by number.
G go to last line of program.
1 G go to first line of program.
/string search from current location in file to the end of the file and stop when finding the first occurance of string.
n find the next occurance of the search string specified by the previous "/string" command.
u undo the previous command.
. typing a period repeats the previous command.
:1,$ s/string1/string2/ The first occurance of string1 on each line in the program is replaced with string2.
:1,$ s/string1/string2/g Replaces all occurances of string1 are replaced by string2.

Wednesday, January 7, 2009

Using rake db:migrate

In Ruby on Rails, it is very to add new version of database tables or columns. It has built-in support in by using this command:

rake db:migrate

To revert back to the earlier version of database structures, just add VERSION= xxx to the back of the command. It becomes:

rake db:migrate VERSION=20090103162017

(this number "20090103162017" is the version number of the migration files generated by rake db:migrate. It is so simple.

else you can use

rake db:rollback

(this will rollback the last migration)

Tuesday, January 6, 2009

My current jailbreak app




Below is the list of applications on why I jailbreak the iPhone 3G:

i. Cycorder (Still no 1 in the list). Very important.
ii. biteSMS
iii. MxTube

That's all. Removed Podcaster as it is now replaced by iPod app.

I stopped using Podcaster

Related to the post below, I have stopped using Podcaster. Gone US$4.99. The reason is because with the later version of Podcaster, the UI changes makes it difficult to use and not user friendly compared to iPod app. Furthermore iPod allows downloading over the air now. So problem with earlier version of iPod resolved. Upon using, I noticed that by using Podcaster, downloading podcast directly to iPhone requires iPhone to keep running and it drains the battery juice because of WIFI. It just don't make sense now. It is better to download to iTunes on desktop and sync to iPhone. Reason is because majority video podcast size is about 100MB or more. It is painful to download directly to iPhone. Also, iPod app has a good background operation as it stops when the is incoming phone calls and resume after the call. You can still use Safari which listening to music without the need for Backgrounder app. You can do much more with iPod app in your phone.

Verdict on Podcaster: Don't buy.

Why pay US$4.99 when you get the better functions for free. Use iPod built-in to iPhone and it is free.

ThinkPad X61(non-tablet) Hackintosh

I have recently used think pad and updated OSX 10.5.5 on X61. The distribution used is iDeneb 10.5.5. This installation takes about 7GB of hard disk space.

Also successful with Kalyway 10.5.2 but the hassle to upgrade it to 10.5.5 is just taking too much time cause of the steps to update to 10.5.3 then to 10.5.4 and finally 10.5.5. Using iDeneb, you get 10.5.5 out of the box.

Installation is very smooth and VGA works out of the box. QE/CI is supported and able to run all OpenGL applications smoothly.
Time machine works well.

Things that need additional drivers (kext) is as follows:
i. LAN Card (can download the driver from here: http://techresearchinfo.blogspot.com.)
ii. Audio (Output through speaker only) can download from here: http://forum.insanelymac.com/index.php?showtopic=87574&st=190
iii. Battery meter download from here: http://forum.insanelymac.com/index.php?showtopic=114105

With these 3 things, we can have a 95% working X61 hackintosh notebook. It is more powerful than MSI Wind.

Things that are not working to date:
i. Wireless LAN card (alternative solution is to change the internal card or get a USB WIFI card)
ii. LCD Brightness - still no control of LCD Brightness. If anyone has a solution, please let me know in the comment below. Have been searching for long as it is very important to use it as notebook. Right now, I am using the X61 hackintosh with external monitor (Samsung T240) with 1920x1600 resolutions. Can watch Hulu with full HD.
iii. Sound card - audio out on headphone and mic. Still not working but can be resolved with external USB sound card.

Time differences in Windows and Mac OSX

Installing both Windows either Vista or XP on the same machine can create issue related to time cause Vista uses the PC clock as the local clock as compared to OSX which uses the local time as universal time (GMT). In order to resolve this problem, we need to tell Vista that the local time is GMT. This can be done in adding an entry to the registry. Below are the steps required:

run -> regedit

navigate to:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

click
TimeZoneInformation and look for this DWORD:

RealTimeIsUniversal

if not exist, create a new DWORD.
Set the value to 1.

That's all.