Skip to content

Instantly share code, notes, and snippets.

@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
require 'minitest/autorun'
require 'properties'
class PropertiesTest < MiniTest::Unit::TestCase
class Foo
extend Properties
property :bar
end
def setup
@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}"
@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 / 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 / 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: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 / pre-commit
Created November 19, 2012 20:19
Git pre-commit hook to detect the presence of pry related statements
#!/bin/sh
#
# To enable this hook, rename this file to "pre-commit".
PRY_PATTERN="require.+[\'\"]pry[\'\"]|binding\.pry"
# Redirect output to stderr.
exec 1>&2
if git diff --cached | grep '^\+' | grep -q -E $PRY_PATTERN; then
echo "ERROR: There is left over pry stuff in this commit"
@eedrummer
eedrummer / gist:4532257
Last active December 11, 2015 02:38
Copy files out of an MS Access database and load it into Postgres using mdb-tools
mdb-schema current_lmrp.mdb postgres | psql lcd
mdb-tables -1 current_lmrp.mdb | xargs -Itable sh -c "mdb-export -H current_lmrp.mdb table > newcsv/table.csv"
ls newcsv | xargs -I{} sh -c "echo {} | cut -d'.' -f1" | xargs -I{} psql -c "COPY {} from '/Users/andrewg/Downloads/current_lmrp/newcsv/{}.csv' DELIMITER ',' CSV;" lcd
http://rxnav.nlm.nih.gov/REST/Ndfrt/properties/nui=N0000178444&propertyName=VUID