Skip to content

Instantly share code, notes, and snippets.

/**
IMPORTANT: Requires this version of jquery
until 1.3.3 comes out http://gist.github.com/186325
ALSO: This is very dirty still and has not been
abstracted for use. It is just solving our immediate problems.
Use cases that must pass (and should be tested someday):
* Clicking on links updates layout
* Click around a bit and then use back/forward buttons
/**
IMPORTANT: Requires this version of jquery
until 1.3.3 comes out http://gist.github.com/186325
ALSO: This is very dirty still and has not been
abstracted for use. It is just solving our immediate problems.
Use cases that must pass (and should be tested someday):
* Clicking on links updates layout
* Click around a bit and then use back/forward buttons
@jnunemaker
jnunemaker / mongomapper $where examples
Created October 11, 2009 02:25 — forked from royw/mongomapper $where examples
mongo $where stuff and a bunch of db eval examples
require 'mongo_mapper'
require 'spec'
require 'log4r'
require 'versionomy'
# Logger used for logging MongoDB database commands
Log4r::Logger.new('TMP')
Log4r::Logger['TMP'].outputters = Log4r::StdoutOutputter.new(:console)
Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
Log4r::Logger['TMP'].level = Log4r::DEBUG
@jnunemaker
jnunemaker / result.txt
Created October 19, 2009 02:20 — forked from semanticart/result.txt
troubleshooting mongo mapper issue for someone
$ ruby test_custom_data.rb
Loaded suite test_custom_data
Started
.F..
Finished in 0.018501 seconds.
1) Failure:
test_creating_a_thing_with_a_foo(MyTest) [test_custom_data.rb:58]:
<"--- !ruby/object:Foo \nfirst: 1st\nsecond: 2nd\n"> expected but was
<#<Foo:0x1023a5ce8 @first="1st", @second="2nd">>.
# Example from Rick Olson's Sparklines middleware
# http://github.com/technoweenie/rack-sparklines/blob/master/lib/rack-sparklines.rb
module Rack
class Sparklines
def initialize(app, options = {})
@app, @options = app, options
end
def call(env)
if env['PATH_INFO'][@options[:prefix]] == @options[:prefix]
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
@jnunemaker
jnunemaker / gist:217362
Created October 24, 2009 04:07 — forked from lukesutton/gist:107966
example of warden with sinatra
Warden::Manager.serialize_into_session{|user| user.id }
Warden::Manager.serialize_from_session{|id| User.get(id) }
Warden::Manager.before_failure do |env,opts|
# Sinatra is very sensitive to the request method
# since authentication could fail on any type of method, we need
# to set it for the failure app so it is routed to the correct block
env['REQUEST_METHOD'] = "POST"
end
@jnunemaker
jnunemaker / application_controller.rb
Created November 8, 2009 01:11
simple auth using twitter gem and sign in with twitter
class ApplicationController < ActionController::Base
include TwitterAuth::Helpers
helper :all
protect_from_forgery
rescue_from Twitter::Unauthorized, :with => :force_sign_in
private
def force_sign_in(exception)
@jnunemaker
jnunemaker / harmony.rb
Created November 10, 2009 01:20
simple app configuration
module Harmony
# Allows accessing config variables from harmony.yml like so:
# Harmony[:domain] => harmonyapp.com
def self.[](key)
unless @config
raw_config = File.read(RAILS_ROOT + "/config/harmony.yml")
@config = YAML.load(raw_config)[RAILS_ENV].symbolize_keys
end
@config[key]
end
@jnunemaker
jnunemaker / db_eval.rb
Created November 10, 2009 15:09
db eval to search in array of hashes with mongo
require 'pp'
require 'rubygems'
require 'mongo_mapper'
require 'benchmark'
MongoMapper.database = 'testing'
class Foo
include MongoMapper::Document