This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function __git_dirty { | |
git diff --quiet HEAD &>/dev/null | |
[ $? == 1 ] && echo "!" | |
} | |
function __git_branch { | |
__git_ps1 "(%s)" | |
} | |
function __my_rvm_ruby_version { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function() { | |
$.cookie('tz', (new Date()).getTimezoneOffset()); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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">>. |
NewerOlder