Skip to content

Instantly share code, notes, and snippets.

@bobthecow
bobthecow / match_json.rb
Created July 10, 2012 22:15
match_json
require 'json_expressions'
RSpec::Matchers.define :match_json do |expected|
unless JsonExpressions::Matcher === expected
expected = JsonExpressions::Matcher.new(expected)
end
match do |actual|
actual = JSON.parse(actual) if String === actual
expected =~ actual
@vwall
vwall / gist:1572207
Created January 6, 2012 20:14 — forked from kagemusha/gist:1444076
Install Rails 3.1 Mongoid Mongo on Heroku
Tested on: Rails 3.1.x, Heroku Cedar stack
1. Generate/develop local Rails app, add mongoid gem, bundle install etc.
2. Git the App
3. Generate Heroku Cedar App:
heroku create --stack cedar
4. Rename app
heroku rename <newname>
5. Install heroku mongoHQ or mongolab:
heroku addons:add mongohq:free
@rogerrohrbach
rogerrohrbach / nanp_validator.rb
Created June 27, 2011 14:42
Active Model North American Telephone Number validator
# == Active Model North American Telephone Number Validator
# http://en.wikipedia.org/wiki/North_American_Numbering_Plan#Current_system
# [Author] Roger Rohrbach (roger@ecstatic.com)
class NanpValidator < ActiveModel::EachValidator
def self.matcher(require_area_code) # :nodoc:
%r{
(?<country_code> \+1 ){0}
(?<trunk_prefix> 1 ){0}
(?<delimiter> ([-\.]|\ +) ){0}
# features/support/configuration.rb
Before do
Neo4j::Transaction.run do
Neo4j._all_nodes.each { |n| n.del unless n.neo_id == 0 }
end
end
# spec/support/configuration.rb
def delete_all
Neo4j::Transaction.run do
@ollyjackson
ollyjackson / Google Maps API with Cloud Made tiles.js
Created September 22, 2010 17:43
Google Maps API with Cloud Made tiles
var cloudmadeOptions = {
getTileUrl: function(coord, zoom) {
return "http://a.tile.cloudmade.com/<API KEY HERE>/<CLOUDMADE CUSTOM TILE ID>/256/" +
+ zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
isPng: true
};
var cloudmadeType = new google.maps.ImageMapType(cloudmadeOptions);
# A simple app that implements a naive session-based login, to demonstrate the problems with testing sessions in Sinatra.
require 'rubygems'
require 'sinatra/base'
class LoginApp < Sinatra::Base
enable :sessions
get '/' do