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
should "accept timestamps" do | |
time = Time.now | |
Timecop.travel(time) | |
new_model = TestModel.new | |
new_model.save | |
assert_equal time, new_model.created_at | |
assert_equal time, new_model.updated_at | |
future = time + 10.minutes | |
Timecop.travel(future) | |
new_model.save |
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
[[], [["a", "b", "c"], ["d", "e", "f"]], [["g", "h", "i"]]] | |
#=> | |
[["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]] | |
#=> via | |
array.reject(&:empty?).inject([]) {|acc, array| array.each {|entry| acc << entry}; acc} |
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
[info] [<0.4586.0>] 127.0.0.1 - - 'GET' /_all_dbs 200 | |
[info] [<0.4587.0>] 127.0.0.1 - - 'PUT' /test_db 201 | |
[info] [<0.4588.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 404 | |
[info] [<0.4589.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201 | |
[info] [<0.4590.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 200 | |
[info] [<0.4591.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201 | |
[info] [<0.4592.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 200 | |
[info] [<0.4593.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201 | |
[info] [<0.4594.0>] 127.0.0.1 - - 'GET' /test_db/_design/SpatialTest%3A%3ASpatialModel 200 | |
[info] [<0.4596.0>] 127.0.0.1 - - 'PUT' /test_db/_design/SpatialTest%3A%3ASpatialModel 201 |
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 create | |
respond_to do |format| | |
if @my_model.save | |
format.json do | |
render :json => @my_model.to_json(:methods => [:owner_name]) #owner_name is a method that returns owner.display_name | |
end | |
end | |
format html { ... } | |
else | |
format.json { errors... } |
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
class UsernameConstraint | |
def matches?(request) | |
if /^\/(?<username>[a-zA-Z0-9-]+)/ =~ request.path | |
User.exists?(:conditions => {:username => username}) | |
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
(setq mac-option-key-is-meta nil) | |
(setq mac-command-key-is-meta t) | |
(setq mac-command-modifier 'meta) | |
(setq mac-option-modifier nil) | |
;; via http://www.viget.com/extend/emacs-24-rails-development-environment-from-scratch-to-productive-in-5-minu/ | |
;; emacs configuration | |
(push "/usr/local/bin" exec-path) | |
(add-to-list 'load-path "~/.emacs.d") |
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
class SpreadsheetConverter < Sinatra::Base | |
post '/convert' do | |
content_type "application/xls-or-whatever" | |
convert(params[:spreadsheet]) | |
end | |
private | |
def convert(spreadsheet) |
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
function initialize() { | |
var map = new google.maps.Map(document.getElementById("map"), { | |
center: new google.maps.LatLng(81, -158.5), | |
zoom: 3, | |
disableDoubleClickZoom: true, | |
mapTypeControlOptions: { | |
mapTypeIds: ["nw"] | |
} | |
}); | |
map.mapTypes.set('nw', nwMapType); |
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 total | |
line_items.map {|i| i.price.to_f * i.quantity.to_i }.sum * | |
(1.0 - quantity_discount) | |
end | |
def remaining_total | |
total - payments.map(&:amount).compact.sum | |
end | |
def quantity_discount |
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
From 6255dd5f7263624e36295d21b0180fc88c599621 Mon Sep 17 00:00:00 2001 | |
From: Joshua Miller <josh@joshinharrisburg.com> | |
Date: Thu, 19 May 2011 19:13:28 -0700 | |
Subject: [PATCH] Add #<=> and #casecmp to Symbol | |
--- | |
kernel/common/symbol.rb | 19 +++++++++++++++++++ | |
1 files changed, 19 insertions(+), 0 deletions(-) | |
diff --git a/kernel/common/symbol.rb b/kernel/common/symbol.rb |