Skip to content

Instantly share code, notes, and snippets.

View olivernn's full-sized avatar

Oliver Nightingale olivernn

View GitHub Profile
@olivernn
olivernn / Post.js
Created January 10, 2012 16:47
The Plugin
var Post = Model('post', function () {
this.use(Model.Lunr(function () {
this.field('body')
this.field('title', {
'multiplier': 10
})
}))
})
@olivernn
olivernn / bill.js
Created August 24, 2011 11:22
js model validations
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
}
})
<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 {
require 'rubygems'
require 'sinatra'
get "/" do
erb :index
end
get "/slow_network" do
sleep(2)
"Done"
class Admin::ReportsController < AdminController
respond_to :csv
def trips
respond_with TripReport.new
end
end
@olivernn
olivernn / active_model_errors_patch.rb
Created January 27, 2011 13:13
stop invalid json after calling to_json on active model errors
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 }
@olivernn
olivernn / user.js
Created December 1, 2010 12:38
User with validation on presence of name
var User = Model('user', {
// class methods
validates: {
presenceOf: ['name']
}
}, {
// instance methods
})
o = new User ({name: "oliver"})
Post('post', {}, {
validatesPresenceOf: ['title', 'body'],
validatesLengthOf: [{attr: 'title', min: 20}, { attr: 'body', max: 2000 }]
})
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"] }
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