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"
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})
/**
* Cheating on http://clickthatbutton.com/
*/
cheat = function() { $.post("/", {submit : {x : 193, y: 52}}, doResponse) }; setInterval(cheat, 1000);
[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,
class Time
# because i often times have trouble keeping these straight
# >> 1.day.ago.before? Time.now
# => true
# >> 1.day.from_now.before? Time.now
# => false
# >> 1.day.from_now.after? Time.now
# => true
# >> 1.day.ago.after? Time.now
# When a spammer wants to attack your site, they'll likely send an automated bot
# that will blindly fill out any forms it encounters. The idea of a "honeypot" is that
# you place a hidden field in a form. That's the honeypot. If this field is filled in, then
# it's almost certain to be a spammer (since a normal user wouldn't have even seen the
# field), and the contents of the form can safely be discarded.
# Normally, you would implement a "honeypot" in a Rails app with some combination of a
# special field in a particular form, and then some logic in the corresponding controller that
# would check for content in the "honeypot" field. This is somewhat of an inefficient
# approach, because it requires special code (not DRY), and bots are still going through an
class CouchRestExt::Model
class << self
def make attributes={}
new(@_blueprint_block.call.merge(attributes)).tap do |obj|
yield obj if block_given?
obj.save
end
end
# Lighter -- Campfire from the command line
# usage: ruby lighter.rb subdomain "Main Room" macournoyer@gmail
require "rubygems"
require "tinder"
require "readline"
require "highline/import"
class Lighter
def initialize(room)
@room = room