Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
def new
@ps = ProductSpecification.find(params[:spec])
@product_request = ProductRequest.new(:height => @ps.height, :width => @ps.width)
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @product_request }
end
end
function parse_git_dirty {
git diff --quiet || echo "^"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)] /"
}
export PS1='\w $(parse_git_branch)\$ '
# App Template
# By Matt Polito
# Link to local copy of edge rails
rake('rails:freeze:gems')
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
# note: rack.input == the request body
>> env = { "REQUEST_METHOD" => "GET", "REQUEST_URI"=>"/events", "QUERY_STRING" => "", "rack.input" => ""}
=> {...}
>> response = EventsController.call(env)
=> #<ActionController::Response:0x22eb95c ...>
>> puts response.body
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})
// some javascript... trying to learn... syntax so weird...
var a = {
foo: function() { alert('yo mama!!'); }
};
var box = {
height: 50,
width: 200
sudo port install -u git-core +svn +bash_completion
/**
* Cheating on http://clickthatbutton.com/
*/
cheat = function() { $.post("/", {submit : {x : 193, y: 52}}, doResponse) }; setInterval(cheat, 1000);
# confusing behavior with attr_readonly
# setup - we're going to create a user with an attr_readonly attribute: "login"
~/working/$ rails -v
Rails 2.3.0
~/working $ rails rails
~/working $ cd rails
~/working/rails $ script/generate model user login:string
~/working/rails $ rake db:migrate
[Tekkub@KAKU: ~/tmp/mach_star master]$ gem install rtomayko-rack-contrib
Building native extensions. This could take a while...
ERROR: Error installing rtomayko-rack-contrib:
ERROR: Failed to build gem native extension.
c:/ruby/bin/ruby.exe extconf.rb install rtomayko-rack-contrib
creating Makefile
nmake
'nmake' is not recognized as an internal or external command,