Skip to content

Instantly share code, notes, and snippets.

View gusgollings's full-sized avatar

Gus Gollings gusgollings

View GitHub Profile
ocean-2:example gus$ pwd
/Users/gus/dev/pancake/example
ocean-2:example gus$ rackup config.ru
Loading Development configuration
^Z
[1]+ Stopped rackup config.ru
ocean-2:example gus$ bg %1
[1]+ rackup config.ru &
ocean-2:example gus$ wget -S http://localhost:9292/foo
--17:13:48-- http://localhost:9292/foo
ocean:E2DesktopMacSource gus$ python setup_mac.py py2app
running py2app
creating /Users/gus/E2DesktopMacSource/build
creating /Users/gus/E2DesktopMacSource/build/bdist.macosx-10.3-i386
creating /Users/gus/E2DesktopMacSource/build/bdist.macosx-10.3-i386/python2.5-standalone
creating /Users/gus/E2DesktopMacSource/build/bdist.macosx-10.3-i386/python2.5-standalone/app
creating /Users/gus/E2DesktopMacSource/build/bdist.macosx-10.3-i386/python2.5-standalone/app/collect
creating /Users/gus/E2DesktopMacSource/build/bdist.macosx-10.3-i386/python2.5-standalone/app/temp
creating /Users/gus/E2DesktopMacSource/dist
creating build/bdist.macosx-10.3-i386/python2.5-standalone/app/lib-dynload
// only outputs if console available and does each argument on its own line
function log() {
if (window && window.console && window.console.log) {
var i, len;
for (i=0, len=arguments.length; i<len; i++) {
console.log(arguments[i]);
}
}
}
class AddAccountNotes < TableMigration
migrates :accounts, :multi_pass => false, :create_temp_table => false, :dry_run => false
schema_changes.push <<-SQL
ALTER TABLE :new_table_name
ADD COLUMN `notes` VARCHAR(255)
SQL
schema_changes.push <<-SQL
ALTER TABLE :new_table_name

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

# Make port 80 "real life" speeds
# You can also use Mongrel ports.
function slow_port {
# Set the port variable if no port inputted. Defaulted to 80 (for Passenger).
if [ -z "$1" ]
then port=80
else port=$1
fi
# Slow the ports.
require 'lib/usher'
u = Usher::Interface.for(:text) do
on('my name is :name') { |name|
puts "hey #{name}, nice to meet you"
}
on('hey :first_name( :last_name)') {|first_name, last_name|
puts last_name ?
"how are you doing #{first_name} #{last_name}?" :
class SignupController < ActionController::Base
def step_two
@signup = Signup.find(params[:id])
@signup.advance_step do |signup|
signup.attributes = params[:signup]
signup.save!
end
end
end
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return
require 'benchmark'
def explicit
return 1
end
def implicit
1
end
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'spira'
require 'rack/linkeddata'
use Rack::LinkedData::ContentNegotiation, :default => 'text/turtle'
include RDF