Monday, October 24, 2011

Steps to deploy changes to a RoR application to the production machine

List the differences between local (deployment) and the remote (production) Git repositories

$ git diff master <alias of the production remote repo>/master --stat


The steps to push changes to remote Git, and deploy the changes on the production server:

$ git add .
$ git commit -m "modified ... files"
$ git push < alias of the production remote repo >

If there are no database schema changes to deploy:
$ cap deploy

If there are database schema changes:
$ cap deploy:migrations

List of steps to set up GSM modem on Ubuntu

After rebooting or waking up from hibernation on Ubuntu, the GSM modem is detected as a storage device, as shown by the CD-Rom icon on the GNOME desktop.

Follow these steps to set up and verify that the modem is working
  • run "sakis3g switchonly" command. The result should be successful, with the output message "Modem switched to 1c9e:9603." The CD-Rom icon should disappear from the desktop.
  • do "ls /dev/ttyUSB*". Make sure the modem shows up as /dev/ttyUSB* devices (/dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2).
  • run "minicom -s -c on"
  • inside minicom
    • select "Exit" to exit the configuration menu, and start using minicom.
    • type "AT", press Enter make sure the response is OK.
    • type "AT+CMGF=1" to set to text mode, press Enter, the response should be OK
    • type "AT+CMGS="+1408xxxxxxx", press Enter , the prompt > should appear next
    • after the prompt >, type the SMS text
    • type Ctrl-Z to end the SMS text
    • should see the response "+CMGS: " followed by "OK"
If the SMS is received by the intended mobile phone, then the GSM modem is working.

Note: this assumes the minicom serial port configured in /etc/minicom/minirc.dfl

# Machine-generated file - use "minicom -s" to change parameters.
pu port                /dev/ttyUSB2

Type "Ctrl-A Z" and "X" to exit minicom.

No VBA

Microsoft Office for MAC 2006 doesn't support VBA (Visual Basic for Applications). That's a bummer.

I need to find another solution for calculating timesheet hours in Excel.

Friday, October 21, 2011

Use Meld as a GUI for Git diff

To diff a directory in the workspace with Git's staging area

06:24 PM ~/app_0515 $ git difftool -t meld app/views

Viewing: 'app/views/participants/index.html.erb'
Hit return to launch 'meld':

Viewing: 'app/views/sent_messages/index.html.erb'
Hit return to launch 'meld':

Viewing: 'app/views/sent_messages/show.html.erb'
Hit return to launch 'meld':


To diff between the master branch and a remote branch

07:37 PM ~/app_0515 $ git difftool -t meld home/master master

Viewing: 'app/controllers/participants_controller.rb'
Hit return to launch 'meld':


Viewing: 'app/helpers/application_helper.rb'
Hit return to launch 'meld':
Viewing: 'app/models/participant.rb'
Hit return to launch 'meld':

Viewing: 'app/views/participants/index.html.erb'
Hit return to launch 'meld':

Viewing: 'app/views/sent_messages/index.html.erb'
Hit return to launch 'meld':

Viewing: 'app/views/sent_messages/show.html.erb'
Hit return to launch 'meld':



To diff between the repository and the staging area:
12:42 PM ~/lib/rubygsm $ git difftool -t meld HEAD core.rb

Viewing: 'lib/rubygsm/core.rb'
Hit return to launch 'meld':




Getting a USB GSM modem working on Ubuntu (part II)

After getting the USB modem successfully detected as a modem on Ubuntu, the next step is to try it out, and use it to send some SMS.

I use the program Minicom.

First install Minicom
$ sudo apt-get install minicom

The installation is fast and straightforward.

Configure Minicom's serial port as root

$ sudo minicom -s -c on

The minicom's text box menu should appear with the following options:
Filenames and paths
File transfer protocols
Serial port setup
Modem and dialing
Screen and keyboard
Save setup as dfl
Save setup as..
Exit
Exit from Minicom

Select "Serial port setup". Under the setup,
A - Serial Device : dev/ttyUSB2
B - Lockfile location : /var/lock
C - Callin Program :
D - Callout Program :
E - Bps/Par/Bits : 115200 8N1
F - Hardware Flow Control : Yes
G - Software Flow Control : No

There are /dev/ttyUSB0, USB1, and USB2 associated with the modem. Selecting ttyUSB0 or ttyUSB1 causes Minicom to freeze at "initializing modem" stage, and only ttyUSB2 works.

Back to the top menu, select "Save setup as dfl" to save the serial port setup to the file "/etc/minicom/minirc.dfl". This step requires root access. and is the reason for running Minicom with sudo. Once serial port is configured, the subsequent run of minicom can be without sudo.

Select "Exit" to exit the configuration menu. Minicom should briefly show a text box that says "Initializing Modem". When initialization is done, the terminal shows:

Welcome to minicom 2.4

OPTIONS: I18n
Compiled on Jan 25 2010, 06:49:09.
Port /dev/ttyUSB2

Press CTRL-A Z for help on special keys

AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0
OK


to send an SMS using AT commands inside Minicom
Type the following AT commands:

  • type "AT+CMGF=1", press , the response should be OK
  • type "AT+CMGS="+1408xxxxxxx", press , the prompt > should appear next
  • after the prompt >, type the SMS text
  • type Ctrl-Z to end the SMS text
  • should see the response "+CMGS: " followed by "OK"

Here is how it looks like in the Minicom terminal:

AT
OK
AT+CMGF=1
OK
AT+CMGS="+1408xxxxxxx"
> test sending SMS from Ubuntu on Oct 21, 2011

+CMGS: 24

OK


Great! Now I can send SMS using the GSM modem on Ubuntu!

Getting a USB GSM modem working on Ubuntu (part I)

I have the USB GSM modem working on a MAC, and have been using it to send SMS. Now I need to get the same modem working on a Ubuntu 10.04.


When I first plug the modem into the USB port, the modem is detected as a CD-ROM device. A CD-ROM icon appears on the desktop. Ubuntu also detects the modem as a storage device, as I can tell, from issuing a few commands.
  • the device appears as /dev/sr# (# is number which varies), a byte stream device
  • the command "lsusb" output shows the device as "Bus 002 Device 005: ID 1c9e:f000." From what I read on the Internet, "f000" indicates it is a memory device.
  • the command "ls /dev/disk" shows there is disk "by-label" of "Modem", and "by-id" of usb-USBModem_Disk_1234567890ABCDEF-0:0.
So all evidences show the modem isn't detected as a modem. Via Google search, I found out it is the effect of the ZeroCD feature that the modem manufacturers have been putting in the modem. Here is a wiki description on it. Essentially, the USB modem has a bit flash storage which stores the driver of the modem. When the modem is plugged into a Windows or MAC machine, it first runs as a storage device which auto-installs the driver, the driver then switches the modem out of the storage mode into the modem mode. On a Ubuntu, the driver doesn't run and install, therefore the modem remains as a storage device.

To switch the USB modem from the storage mode and to the modem mode, I found the Sakis3G script. It is easy to run and works very well.

$ gunzip sakis3g.zip

$ sudo cp sakis3g /usr/bin

$ cd /usr/bin

$ ls -l sakis3g
-rw-r--r-- 1 root root 214619 2011-10-18 17:58 sakis3g

Change the group of sakis4g to "dialout" which has all the users who are allowed to access the modem
$ sudo chown root:dialout sakis3g

$ ls -l sakis3g
-rw-r--r-- 1 root dialout 214619 2011-10-18 17:58 sakis3g

$ sudo chmod 750 sakis3g

$ ls -l sakis3g
-rwxr-x--- 1 root dialout 214619 2011-10-18 17:58 sakis3g

I have to install a few dependencies in order to run Sakis3G
$ sudo apt-get install ppp sharutils xterm 9menu xosd-bin wget

I create a Sakis3G configuration file under /ect/sakis3g.conf, contained the following switches
--console
--sudo
--debug

These switches configures Sakis3G to run in terminal console, as root, and with detailed debug messages.

To run Sakis3G
$ sakis3g switchonly

Sakis3G spills out lots of debug messages. At the end, there should be a message like this

Modem switched to 1c9e:9603

In addition, the CD-Rom icon disappears from the desktop. Running the same set of commands again to verify the mode of the mode shows

  • the path /dev/sr1 has disappeared, and /dev/ttyUSB0, /dev/ttyUSB1, /dev/ttyUSB2, which are character stream devices, have appear. (Note sometimes, the numbering may be USB1, USB2, and USB3)
  • the command "lsusb" shows the device as "Bus 002 Device 006: ID 1c9e:9603." The device ID has changed from 1c9e:f000 to 1c9e:9603
  • the command "ls /dev/disk/by-id" still shows the disk usb-USBModem_Disk_1234567890ABCDEF-0:0, but the path "/dev/disk/by-label" no longer exists


So voila, the USB GSM modem has been successfully switched to the modem mode!

Each time the USB modem is power-cycled due to the system reboots or wakes up from hibernation, the modem returns to the initial storage mode. So the Sakis3G script must be run again to switch the mode.


Here are the model of the modem and the version of Ubuntu that I'm using:
GSM modem: Zoom 4595 3G tri-band USB modem
Ubuntu: 10.04.3 LTS

Now that the modem is running as a modem under Ubuntu, the next step is to control it and send SMS via it. That'll be Part II.

Sunday, October 16, 2011

The file type indicator in Ubuntu "ls -l" command output

The first field of the output of "ls -l" is a string of 10 character that looks like this

drwxr-xr-x

This first character indicates file type. The common indicators are:

- : a plain file
d: a directory
l: a symbolic link
c: a character device, such as /dev/tty0
b: a block device, such as /dev/sda

Wednesday, October 12, 2011

Monday, October 3, 2011

Ruby Bundler

From Gem Versioning and Bundler: Doing it Right

Key pointers from the article
  • When running an executable, ALWAYS use bundle exec [command]. Quoting from the bundler documentation: In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle. However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.
  • When you run an executable from the command line without bundle exec, this wrapper invokes Rubygems, which then uses the normal Rubygems activation mechanism to invoke the gem’s executable. This has changed in the past several months, but Rubygems will invoke the latest version of the gem installed in your system, even if your Gemfile.lock specifies a different version. In addition, it will activate the latest (compatible) installed version of dependencies of that gem, even if a different version is specified in your Gemfile.lock.
  • The only exception to the above rules is the rails executable. As of Rails 3.0, the executable simply looks for a script/rails file, and execs that file. The generated script/rails loads the local boot environment, which invokes bundler immediately.
This explains when the Gemfile specifies Rails gem of "3.0.5", and the system Rails gem is "3.1.0", typing the command "rails -v" inside and outside the application root directory gives different version value

Inside application root directory:
06:12 PM ~/Development/rails_projects/app_0515 $ rails -v
rails Rails 3.0.5

Outside application root directory:
06:21 PM ~/Development/rails_projects $ rails -v
Rails 3.1.0