Development

19
Nov 09

Wootsi 2.0 and Wootsi Lite Published

A new version of Wootsi has been published along with an ad-supported lite version. You can grab either of these from the Android Market.

Version 2.0 contains some bug fixes along with independently updating items. Also, you can now view items while the application is updating.

Go check it out on the Android Market. Click this link from your android phone to go directly to the app: market://search?q=wootsi

18
Sep 09

DDMS on Snow Leopard

So a new Android SDK came out a couple days ago. I tried opening up a trace file, but traceview complained that the swt version was not 64-bit compatible. I Googled around for a bit and found a semi-convoluted solution that worked for the 1.5 SDK. Here’s my simplified solution for 1.6.

Download and upzip the file below into “/tools/lib/” in your 1.6 SDK folder. That should do it.

SWT Fix (327)
21
Aug 09

Wootsi update published

I recently pushed an update to my latest Android app, Wootsi.

Wootsi goes out to woot.com and four other woot.com sub-sites to grab their “daily deal”. The app gives users an advantage to those who don’t, because they can receive periodic updates at times they choose. I have my preferences set to update every three hours starting at 7:15 AM.

Another feature is “woot off” detection, which will fetch updates at a faster rate while a woot off is happening.

The first version of the app had some major bugs, but this update fixes them and adds some new features.

Search for Wootsi on your Android phone to find out more.

8
Jul 09

SubSonic condition expressions

Let’s say I have a table called “Contacts”. I’d like to search that table for the string “michael pardo”, however, I could pass in the string “pardo michael” instead. I’d like it to work either way, so here’s what I think the query should look like:

1
2
3
4
5
6
7
8
9
10
11
12
SELECT * 
FROM Contacts
WHERE 
(
    FirstName LIKE '%michael%' 
    OR LastName LIKE '%michael%'
)
AND 
(
    FirstName LIKE '%pardo%' 
    OR LastName LIKE '%pardo%'
)

Okay, well how do I enclose those condition expressions with SubSonic? We can take advantage of the Expression syntax to make this work. Here’s the SubSonic code, broken up by query parts.

1
2
3
4
5
6
7
8
9
10
11
12
// SELECT * FROM Contacts
var q = new Select().From<Contact>();
 
// WHERE (FirstName LIKE '%michael%' OR LastName LIKE '%michael%')
q.WhereExpression(Contact.Columns.FirstName).Like("%michael%");
q.Or(Contact.Columns.LastName).Like("%michael%");
 
// AND (FirstName LIKE '%pardo%' OR LastName LIKE '%pardo%')
q.AndExpression(Contact.Columns.FirstName).Like("%pardo%");
q.Or(Contact.Columns.LastName).Like("%pardo%");
 
q.ExecuteTypedList<Contact>();

One problem I encountered with this method was with chaining. If I chain the “or” commands instead of calling them separately, SubSonic will short-change you on the constraints it passes in. Some sort of bug (or feature) maybe.

24
Jun 09

Easy Ruby on Rails Deployment with Capistrano and Passenger

Let’s start off with a few aliases that speed things up. The commands are pretty self explanatory. I’ve got my deployment down to a simple acd command, which will add and commit to svn, then deploy to the server. To add a migration before deployment I use acmd. The following commands go into your ~/.bash_login file (assuming you’re using OS X or Linux).

1
2
3
4
5
6
7
alias svna='svn add * --force'
alias svnc='svn commit . -m ""'
alias capd='cap deploy'
alias capm='cap deploy:migrate'
alias acd='svna; svnc; capd;'
alias acmd='svna; svnc; capm; capd;'
alias rors='script/server -b localhost'

If you don’t already have capistrano setup, it’s as easy as

1
$ gem install -y capistrano

When I first setup an new rails project I follow these steps

1
2
3
4
5
6
7
8
$ rails -d mysql PROJECT_NAME
$ cd PROJECT_NAME
$ capify .
$ svn import PROJECT_PATH SVN_PATH -m 'Initial import'
$ cd ..
$ rm -Rf PROJECT_PATH
$ svn co SVN_PATH
$ mate PROJECT_PATH

This initial setup process will create the rails project, setup Capistrano, add it to svn, and open it in TextMate. You can of course leave that last line out and use any IDE you wish.

Next open the config/deploy.rb file that Capistrano created for you. This is where you will put all your Capistrano instructions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
set :user, "SUDO_USER"
set :password, "SUDO_USER_PASS"
set :domain, "example.com"
server domain, :app, :web
role :db, domain, :primary => true
 
set :application, "example"
set :deploy_to, "/home/example/public_html/#{application}.sandbox.#{domain}/#{application}/"
 
default_run_options[:pty] = true
set :use_sudo, true
set :runner, :user
 
set :repository,  "http://#{domain}/svn/#{application}"
set :scm_username, "SVN_USER"
set :scm_password, "SVN_USER_PASS"
set :checkout, "export"
 
namespace :deploy do
  desc "Restart Application"
  task :restart, :roles => :app do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

Just change all the capitalized tokens to reflect your own settings. Then deploying should be as simple as typing acd in the Terminal. I created a blank file at /tmp/restart.txt and added it to svn so passenger will restart the rails app when you deploy. Also, you may not want to put your sudo password into deploy.rb.

I entountered various struggles in getting everything to work correctly. If you need help with something specific, post it in a comment. I can probably tell you what the problem is.

You can find help for Passenger here: http://www.modrails.com/ and help for Capistrano here: http://www.capify.org/