This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
require 'sinatra/reloader' | |
before do | |
headers "Content-Type" => "application/octet-stream" | |
end | |
get "/" do | |
"Hello World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Please ignore this Gist and check out this instead: https://gist.github.com/913370 | |
def precompiled_preamble(locals) | |
locals.map { |k,v| "#{k} = #{v}" }.join("\n") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def precompiled_preamble(locals) | |
locals.map { |k,v| "#{k} = locals[#{k.inspect}]"}.join("\n") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final_width = 400 | |
final_height = 400 | |
for (var i = 0; i < app.documents.length; i++) { | |
crop_width_by = 0 | |
crop_height_by = 0 | |
doc = app.documents[i] | |
app.activeDocument = doc | |
landscape = (doc.height < doc.width) | |
if (landscape == true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tombstone | |
App.controller :reservation do | |
get :new do | |
@root_places = Place.with_child_count.filter(:parent_id => nil).order(:name).naked.all | |
render 'reservation/new' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEBUG -11/Feb/2012 16:18:07 RELOAD (0.0157ms) /Users/tomwardrop/Sites/Tombstone/app/controllers/reservation.rb | |
DEVEL -11/Feb/2012 16:18:07Reloading Tombstone::App | |
DEVEL -11/Feb/2012 16:18:07Removed constant: Tombstone::Role | |
DEVEL -11/Feb/2012 16:18:07Removed constant: Tombstone::ModelPermissions::InstanceMethods | |
DEVEL -11/Feb/2012 16:18:07Removed constant: Tombstone::ModelPermissions::DatasetMethods | |
DEVEL -11/Feb/2012 16:18:07Removed constant: Tombstone::ModelPermissions | |
DEVEL -11/Feb/2012 16:18:07Removed constant: Tombstone | |
DEBUG -11/Feb/2012 16:18:07 LOADING (0.0287ms) /Users/tomwardrop/Sites/Tombstone/app/lib/model_permissions.rb | |
DEBUG -11/Feb/2012 16:18:07 LOADING (0.0549ms) /Users/tomwardrop/Sites/Tombstone/app/lib/permissions.rb | |
DEBUG -11/Feb/2012 16:18:07 LOADING (0.0221ms) /Users/tomwardrop/Sites/Tombstone/app/models/base.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error do |e| | |
if response.content_type.index(mime_type(:json)) == 0 | |
halt 400, {success: false, exception: e.message}.to_json | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Current Validation Strategy | |
validates_presence :place_id | |
errors.add(:place, "must have a parent") unless place.parent_id | |
# Improved Validation Strategy | |
validates_presence :place_id | |
validates :place, "must have a parent" { place.parent_id } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Formats the given byte value into a human readable form. | |
# | |
# Accepts four optional arguments that control the output format: | |
# as_bits: If true, converts the given byte value to bits and adjusts the suffix accordingly. Defaults to false. | |
# binary: If true, calculates order of magnitude as base 2 (binary) instead of base 10 (decimal). Defaults to true. | |
# full_suffix: If true, uses full suffix names such as "Megabyte", otherwise uses abbreviations like "MB" or "Mib". Defaults to false. | |
# precision: The number of decimal points to include in the output. Trailing zero's are removed. Defaults to 2. | |
def format_bytes(bytes, as_bits: false, binary: true, full_suffix: false, precision: 2) | |
suffixes = ['', 'Kilo', 'Mega', 'Giga', 'Tera', 'Peta', 'Exa', 'Zetta', 'Yotta'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Doesn't work; needs reference to outer class object. | |
class SomeClass | |
class << self | |
extend Delegate | |
def hash | |
@hash ||= {} | |
end | |
delegate hash, :[]=, :has_key?, :each |
OlderNewer