Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
jnunemaker / gist:468109
Created July 8, 2010 14:52 — forked from jseifer/gist:468075
rvm version and git branch/dirtyness in prompt
function __git_dirty {
git diff --quiet HEAD &>/dev/null
[ $? == 1 ] && echo "!"
}
function __git_branch {
__git_ps1 "(%s)"
}
function __my_rvm_ruby_version {
@jnunemaker
jnunemaker / oauth2_example.rb
Created April 22, 2010 22:18 — forked from technoweenie/oauth2_example.rb
oauth2, sinatra, faraday
# see http://github.com/intridea/oauth2
require 'rubygems'
require 'sinatra'
require 'oauth2'
require 'json'
class ConnectionLogger < Faraday::Middleware
def call(env)
env[:response].on_complete do |env|
puts "RESULT: #{env[:status]}\n#{env[:body]}"
@jnunemaker
jnunemaker / mg
Created March 30, 2010 19:25 — forked from defunkt/gemspec
simple gemspec generator
#!/usr/bin/env ruby
# Usage: generate a blank gemspec, for defunkt
abort "pass a name" unless name = ARGV[0]
date = Time.now.strftime('%Y-%m-%d')
puts <<spec
Gem::Specification.new do |s|
s.name = "#{name}"
s.version = "0.1.0"
@jnunemaker
jnunemaker / application.js
Created March 3, 2010 18:43 — forked from bkeepers/application.js
browser cookie timezone stuff
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
@jnunemaker
jnunemaker / gist:311068
Created February 22, 2010 13:32 — forked from kamal/gist:269412
require "rack/openid"
require "warden"
use Rack::OpenID
use Warden::Manager do |manager|
Warden::Strategies.add(:openid) do
def authenticate!
if resp = env["rack.openid.response"]
case resp.status
when :success
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@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
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
# 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">>.