- kristeraxel on Twitter
RT all hospitals are surrounded by militia to check why ppl going in - if gun or baton injury - they arrest and beat u #Iranelection - 10 days ago.
- Krister Axel is a Ruby on Rails programmer working and living in Santa Monica. Codeboxer.com is a collection of Ruby, SQL, PHP, Linux and other code snippets that have already proven themselves useful in some way.
status codes 101
18 June 2009 | 6:47 pm by codeboxer

Ah, the old http status code. Very nice. I recently built my first pro-grade web service and had some problems figuring out the status codes. Here are some tips from my friend happyfrenchy2:
Usually I write my rest service so that a problem with the parameters (wrong ID, not enough params, etc) returns a 400 (bad request), a auth failure (wrong signature) returns a 403 (forbidden) and an internal problem (couldn’t access DB for instance) returns a 503 (server error). Return code 500 should be when the error happens before your code was even reached (like the server or web-server is down).
Very helpful. This is what that looks like, in the create method of the /installs web service:
def create
respond_to do |format|
format.xml {
install = OnInstall.new do |i|
i.ip_address = request.remote_ip
i.mac_address = params[:mac_address]
i.on_dvd_id = params[:on_dvd_id].to_i
i.on_dvd_number = params[:on_dvd_number]
i.on_dvd_set_id = params[:on_dvd_set_id].to_i
i.on_game_id = params[:on_game_id].to_i
end
ts_param = params[:redacted]
hash_to_match = params[:redacted]
begin
#FK validations
test = OnDvd.find(install.on_dvd_id)
test = OnDvdSet.find(install.on_dvd_set_id)
test = OnGame.find(install.on_game_id)
#validate md5 hash
live_matcher = "redacted"
digest = Digest::MD5.hexdigest(live_matcher)
if digest.upcase == hash_to_match.upcase
if install.save
headers['location'] = on_install_path(install.id)
render :nothing => true, :status => "201 Created"
else
render :xml => install.errors.to_xml, :status => "400 Bad Request"
end
else
render :xml => "Your s param hash did not match the POST fields.", :status => "403 Forbidden"
end
rescue Exception => e
render :xml => e.message, :status => "503 Server Error"
end
}
format.html {if current_user == :false then redirect_to home_url else super end}
end
end
sudo port command not found
1 June 2009 | 7:32 pm by codeboxer

sudo: port: command not found
are you getting this error? Add the below to your ~/.bash_profile -
export PATH=$PATH:/opt/local/bin
export MANPATH=$MANPATH:/opt/local/share/man
export INFOPATH=$INFOPATH:/opt/local/share/info
and then run
sudo port -d selfupdate
you should be fine (for Mac Leopard 10.5)
this worked for me
1 May 2009 | 11:56 am by codeboxer

recursevly remove .svn files from an existing repo.
If you need to take a project out of scm, you can run this bash script from the top folder - and it will remove all .svn folders recursively.
Works well for
- changing an svn checkout into and svn export
- switching from svn to git
find . -type d -name '.svn' -exec rm -rf {} \;
tunnel of love
23 April 2009 | 2:43 pm by codeboxer

This little puppy is my tunnel of love. Connecting to SQL databases just keeps getting more complicated. :)
ssh -L 8888:localhost:3306 rails@staging.gmgdev.railsmachina.com




