Skip to content

Instantly share code, notes, and snippets.

# 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]
@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">>.
@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
/**
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
/*!
* jQuery JavaScript Library v1.3.3pre
* http://jquery.com/
*
* Copyright (c) 2009 John Resig
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* Date: 2009-07-16 03:32:39 -0400 (Thu, 16 Jul 2009)
* Revision: 6447
@jnunemaker
jnunemaker / application.js
Created August 11, 2009 16:00
Pretty output of rails errors when doing ajax requests with jQuery
// only outputs if console available and does each argument on its own line
function log() {
if (window && window.console && window.console.log) {
var i, len;
for (i=0, len=arguments.length; i<len; i++) {
console.log(arguments[i]);
}
}
}
@jnunemaker
jnunemaker / authentication.rb
Created July 15, 2009 03:33
a starting point for authentication with mongomapper and rails
# include this in application controller
module Authentication
protected
# Inclusion hook to make #current_user and #signed_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_user, :signed_in?, :authorized? if base.respond_to? :helper_method
end
# Returns true or false if the user is signed in.
@jnunemaker
jnunemaker / errors.js
Created July 14, 2009 16:40
jQuery and Rails form errors
(function($) {
// errors is an array of errors
// render :json => {:errors => @item.errors.full_messages}
function FormErrors(errors) {
var self = this,
error_count = errors.length;
this.html = function() {
var html = '';
html += '<div class="errorExplanation" id="errorExplanation">';
@jnunemaker
jnunemaker / .git-completion.sh
Created July 8, 2009 14:47
bash completion support for git
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names