Skip to content

Instantly share code, notes, and snippets.

Oliver Nightingale olivernn

  • Cape Town
Block or report user

Report or block olivernn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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"
@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
})
}))
})
View gist:1640750
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
}
});
@olivernn
olivernn / cart_app.js
Created May 2, 2012
multiple 'apps' within one davis app
View cart_app.js
var cartApp = function () {
this.scope('/cart', function () {
this.post('/items', function (req) {
// create an item
})
this.del('/items/:id', function (req) {
// delete a specific item from your cart
})
@olivernn
olivernn / app.js
Created Jun 25, 2012
Simple Davis.js Example
View app.js
var app = Davis(function () {
this.get('/foo', function () {
alert('you clicked on foo!')
})
})
View app.js
var app = Davis(function () {
this.configure(function () {
this.linkSelector = 'nav a'
this.formSelector = 'nav form'
})
this.get('/', function (req) {
showHomePage()
})
@olivernn
olivernn / app.js
Created Jun 26, 2012
davis with hash routing
View app.js
Davis.extend(Davis.hashRouting({ forceHashRouting: true }))
app = Davis(function () {
this.settings.handleRouteNotFound = true
this.get('#/foo', function () {
console.log('foo')
})
You can’t perform that action at this time.