Skip to content

Instantly share code, notes, and snippets.

John Nunemaker jnunemaker

Block or report user

Report or block jnunemaker

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
@jnunemaker
jnunemaker / gist:468109
Created Jul 8, 2010 — forked from jseifer/gist:468075
rvm version and git branch/dirtyness in prompt
View gist:468109
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 Apr 22, 2010 — forked from technoweenie/oauth2_example.rb
oauth2, sinatra, faraday
View oauth2_example.rb
# 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 Mar 30, 2010 — forked from defunkt/gemspec
simple gemspec generator
View mg
#!/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 Mar 3, 2010 — forked from bkeepers/application.js
browser cookie timezone stuff
View application.js
jQuery(function() {
$.cookie('tz', (new Date()).getTimezoneOffset());
});
View gist:311068
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
View url_dsl.rb
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 Oct 24, 2009 — forked from lukesutton/gist:107966
example of warden with sinatra
View gist:217362
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
View Tests Is Wrong
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
View gist:214858
# 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 Oct 19, 2009 — forked from semanticart/result.txt
troubleshooting mongo mapper issue for someone
View result.txt
$ 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">>.
You can’t perform that action at this time.