Skip to content

Instantly share code, notes, and snippets.

@eedrummer
eedrummer / gist:3933433
Created October 22, 2012 19:07
Initial pass at calculating the median for CV measures
require 'moped'
db = Moped::Session.new(["localhost:27017"])
db.use('foo')
wrapped_result = db.command(:aggregate => 'patient_cache', :pipeline => [
{'$unwind' => "$values"},
{'$group' => {'_id' => '$values', 'count' => {"$sum" => 1}}}
])
@eedrummer
eedrummer / client.rb
Created September 20, 2012 19:50
Sinatra-based OAuth 2 client (I don't remember where I found this...)
require 'sinatra'
require 'rack/oauth2'
require 'json'
require 'json/jwt'
def client
# app id, app secret, and site are all test-env specific
Rack::OAuth2::Client.new(
:identifier => 'd7633f880b4771b4f91f107a1a27835e',
:secret => '40dc03bf175980bccd15df10f9db1aa2',
@eedrummer
eedrummer / gist:3441170
Created August 23, 2012 20:19
Patch for exp not being in IdToken
diff --git a/config.ru b/config.ru
index 88a4115..d453cc6 100644
--- a/config.ru
+++ b/config.ru
@@ -7,6 +7,31 @@ require 'warden'
require 'warden_omniauth'
require 'yaml'
+module OpenIDConnect
+ class AccessToken
@eedrummer
eedrummer / gist:3436750
Created August 23, 2012 13:46
OpenID Connect RP Gateway Config
host: localhost
client_id: "4119a135-63cf-4074-bcc5-6e9619b71d55"
client_secret: "rhexrhex"
additional_properties:
authorization_endpoint: "/simpledb-openid-connect-server/authorize"
user_info_endpoint: "/simpledb-openid-connect-server/userinfo?schema=openid"
token_endpoint: "/simpledb-openid-connect-server/token"
jwk_url: "/jwk"
issuer: "http://localhost:8080/simpledb-openid-connect-server/"
scope: "openid profile"
@eedrummer
eedrummer / twitter.rb
Created April 16, 2011 20:24
Automagic Twitter client for The Compleat Rubyist
require 'rest_client'
require 'json'
class Twitter
def initialize(username)
@username = username
end
def timeline
raw_json = RestClient.get "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=#{@username}"
require 'minitest/autorun'
require 'properties'
class PropertiesTest < MiniTest::Unit::TestCase
class Foo
extend Properties
property :bar
end
def setup
@eedrummer
eedrummer / properties.rb
Created April 16, 2011 15:00
Reimplementing attr_accessor as an exercise in The Compleat Rubyist
module Properties
def property(property_name)
define_method(property_name) do
instance_variable_get("@#{property_name}".to_sym)
end
define_method("#{property_name}=".to_sym) do |value|
instance_variable_set("@#{property_name}".to_sym, value)
end
end
@eedrummer
eedrummer / gist:741573
Created December 15, 2010 03:10
Using Underscore.js with MongoDB
require 'mongo'
require 'ap'
include Mongo
# Create a connection to a local MongdDB Instance
db = Connection.new.db('underscore-demo')
# Read and eval Underscore.js
underscore = File.read('underscore-min.js')
@eedrummer
eedrummer / gist:638892
Created October 21, 2010 17:19
How to run JavaScript in Ruby via the Ruby Racer
# Install the gem, then
require 'v8'
cxt = V8::Context.new
cxt["effectiveTime"] = Time.gm(2010, 9, 19).to_i
cxt.eval("effectiveTime - (365 * 24 * 60 * 60)") #=> 1253318400
Gwibber Dispatcher: DEBUG <twitter:receive> Performing operation
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/gwibber/microblog/network.py", line 32, in __init__
self.curl.perform()
error: (6, 'name lookup timed out')
Gwibber Dispatcher: ERROR Failed to communicate with http://api.flickr.com/services/rest?username=eedrummer&api_key=36f660117e6555a9cbda4309cfaf72d0&nojsoncallback=1&method=flickr.people.findByUsername&format=json
Gwibber Dispatcher: ERROR Failed to parse the response, error was: No JSON object could be decoded
Gwibber Dispatcher: ERROR <flickr:images> Operation failed
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/gwibber/microblog/network.py", line 32, in __init__