ruby-1.9.2-p290 :010 > first = "ruby"
=> "ruby"
ruby-1.9.2-p290 :011 > second = "rails"
=> "rails"
ruby-1.9.2-p290 :012 > puts first + second
rubyrails
=> nil
ruby-1.9.2-p290 :013 > puts first, second
ruby
rails
=> nil
Wednesday, February 1, 2012
Test code inside Rails Console
11:13 AM ~/{application dir}/ $ rails console
Loading development environment (Rails 3.0.5)
ruby-1.9.2-p290 :001 > Gsm::Modem.convert_string_from_ascii_to_char("6900500068006F006E00650d0a")
=> "iPhone"
Loading development environment (Rails 3.0.5)
ruby-1.9.2-p290 :001 > Gsm::Modem.convert_string_from_ascii_to_char("6900500068006F006E00650d0a")
=> "iPhone"
Thursday, December 22, 2011
Automatically switch the GSM modem to modem mode after reboot
- copy sakis3g script from /usr/bin to /usr/local/bin. See the post http://superuser.com/questions/301922/new-udev-rule-is-ignored
- create an udev rule in a new file 10-switch-gsmmodem-to-modemmode.rules under /etc/udev/rules.d
# run sakis3g
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="1c9e", ATTR{idProduct}=="f000", RUN+="/usr/local/bin/sakis3g switchonly"
Plug in the GSM modem. The mode switch should be automatically. The udev rule mode switch operation can be monitored in /var/log/syslog.
Monday, November 21, 2011
How to comment source code in TextMate
Apple-/
Press the apple key and the forward slash, toggle comment
Alt-Apple-/
Comment a block. Also commet subset of a line
"head" tab-key
Type "head" and press tab. Insert a comment header at top of the file
Control-Shift-B
Insert a comment banner on the top of declarations, functions, etc.
"todo" tab-key
Type "todo" and press tab. Insert a todo bloack
Must enable Source and TODO in the Bundle filter list.
Friday, November 4, 2011
Cron + Whenever + Rake
Sample Rake code
To test the rake task from command line
Add the rake task to Whenever gem's schedule.rb
Whenever defaults the environment to "production", to specify a different environment to run:
Call Whenever to update the crontab
namespace :test do
desc "Pick a random participant from database"
task :pick_participant => :environment do
if Rails.env.production?
# MySQL is used as the production DB, its random function is RAND()
p = Participant.find(:first, :order => 'RAND()')
else
# sqlite3 is used as the development DB, its random function is random()
p = Participant.find(:first, :order => 'random()')
end
puts "#{Time.now}"
puts "* environment is: #{Rails.env}"
puts "* picked participant: #{p.first_name}"
end
end
To test the rake task from command line
$ bundle exec rake test:pick_participant
2011-11-04 10:49:08 -0700
* environment is: development
* picked participant: Macy
Add the rake task to Whenever gem's schedule.rb
every 1.minutes do
rake "test:pick_participant"
end
Whenever defaults the environment to "production", to specify a different environment to run:
every 1.minutes do
rake "test:pick_participant RAILS_ENV=development"
#rake "test:pick_participant"
end
Call Whenever to update the crontab
$ whenever --update-crontab app_0515
[write] crontab file updated
$ crontab -l
# Begin Whenever generated tasks for: app_0515
* * * * * /bin/bash -l -c 'cd /Users/[username]/Development/rails_projects/app_0515 && RAILS_ENV=production bundle exec rake test:pick_participant --silent'
# End Whenever generated tasks for: app_0515
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 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.
Subscribe to:
Posts (Atom)