Skip to content

Instantly share code, notes, and snippets.

Oliver Nightingale olivernn

  • Cape Town
View GitHub Profile
View gist:350531
Oliver-Nightingales-MacBook-Pro:capybara-envjs olivernightingale$ rake
(in /Users/olivernightingale/code/capybara-envjs)
warning: couldn't activate the debugging plugin, skipping
warning: couldn't activate the doofus plugin, skipping
warning: couldn't activate the git plugin, skipping
/Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:274:in `include_shared_example_group': Shared Example Group 'has_select' can not be found (RuntimeError)
from /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:66:in `it_should_behave_like'
from /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:65:in `each'
from /Library/Ruby/Gems/1.8/gems/rspec-1.2.9/lib/spec/example/example_group_methods.rb:65:in `it_should_behave_like'
from /Library/Ruby/Gems/1.8/gems/capybara-0.3.6/spec/session_spec.rb:58
View config.ru
require 'rubygems'
require 'rack'
require 'snippets'
require 'mongo'
require 'rackjson'
use Rack::JSON::Resource, :collections => [:notes], :db => Mongo::Connection.new.db("notes")
run lambda { |env| [404, {'Content-Length' => '9', 'Content-Type' => 'text/plain'}, "Not Found"] }
View gist:593354
Post('post', {}, {
validatesPresenceOf: ['title', 'body'],
validatesLengthOf: [{attr: 'title', min: 20}, { attr: 'body', max: 2000 }]
})
@olivernn
olivernn / user.js
Created Dec 1, 2010
User with validation on presence of name
View user.js
var User = Model('user', {
// class methods
validates: {
presenceOf: ['name']
}
}, {
// instance methods
})
o = new User ({name: "oliver"})
@olivernn
olivernn / active_model_errors_patch.rb
Created Jan 27, 2011
stop invalid json after calling to_json on active model errors
View active_model_errors_patch.rb
module ActiveModel
class Errors
def as_json(options=nil)
self
to_hash
end
def to_hash
hash = ActiveSupport::OrderedHash.new
each { |k, v| (hash[k] ||= []) << v }
View reports_controller.rb
class Admin::ReportsController < AdminController
respond_to :csv
def trips
respond_with TripReport.new
end
end
View ios_history_bug.rb
require 'rubygems'
require 'sinatra'
get "/" do
erb :index
end
get "/slow_network" do
sleep(2)
"Done"
View gist:1129339
<script src="http://raphaeljs.com/raphael.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
body {
background-color: black;
color: white;
font-family: helvetica;
}
#display {
@olivernn
olivernn / bill.js
Created Aug 24, 2011
js model validations
View bill.js
var Bill = Model('bill', function () {
this.use(Model.validations)
this.validatesPresenceOf(['attribute1', 'attribute2'])
this.validatesPresenceOf('another_attribute', {
'condition': function () {
// some condition if you need it
return true
}
})
View Post.js
var Post = Model('post', function () {
this.use(Model.Lunr(function () {
this.field('body')
this.field('title', {
'multiplier': 10
})
}))
})
You can’t perform that action at this time.