Skip to content

Instantly share code, notes, and snippets.

View moklett's full-sized avatar

Michael Klett moklett

  • Chargify.com
  • Cary, NC
View GitHub Profile
@moklett
moklett / keybase.md
Created August 18, 2014 15:06
Keybase Proof

Keybase proof

I hereby claim:

  • I am moklett on github.
  • I am moklett (https://keybase.io/moklett) on keybase.
  • I have a public key whose fingerprint is 365F 3A48 6DAA 9246 139F B2E5 3DE2 CF72 91C8 AE79

To claim this, I am signing this object:

require 'rubygems'
require 'chargify_api_ares'
require 'cgi'
Chargify.configure do |c|
c.subdomain = 'acme'
c.api_key = 'x'
end
email = "foo+bar@gmail.com"
@moklett
moklett / chargify_api_steps.rb
Created September 9, 2010 20:13
A sample of the step definitions used in the Chargify API documentation (i.e. http://docs.chargify.com/api-subscriptions)
Given /^I (?:send and )?accept (.*?)(?: responses)?$/ do |format|
@format = format.downcase.to_sym
header('Content-Type', content_type_for(@format))
http_accept(@format)
end
Given /^the requester accepts (.*) responses$/ do |format|
Given "I accept #{format} responses"
end
Scenario: Clear site data for a test site
Given my site is in test mode
And I have 2 products
And I have 4 subscriptions
When I send a POST request to https://[@subdomain].chargify.com/sites/clear_data.json
Then the response status should be "200 OK"
And I should have 0 products
And I should have 0 subscriptions
Scenario: Attempt to clear site data for a production site
@moklett
moklett / address_spec.rb
Created March 8, 2012 02:33
Toying around with an RSpec DSL for permutations. My real use case is more complex than this example - the large numbers of inputs and outputs makes it more concise to "demonstrate" correctness and expectations than to "spec" it out with traditional, one
describe Address do
permute "validations" do
cases [
[:address, :address_2, :city, :state, :zip, :country, :valid, :errors_on],
[ nil, nil, nil, nil, nil, nil, false, ['address', 'city', 'state', 'zip', 'country']],
['123 Main St', 'Apt 100', 'Pleasantville', 'NC', '12345', 'US', true, []],
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' nil, false ['country']]
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' 'U', false ['country']]
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' 'USA', false ['country']]
]
@moklett
moklett / times.md
Created November 5, 2012 16:15
Date/Time Formats from Unix Timestamp

Unix Timestamp (Seconds since epoch)

Generating from Ruby

t = Time.now
# => 2012-11-05 11:12:25 -0500
t.to_i
# => 1352131945
tu = t.utc
@moklett
moklett / proposal.md
Created August 14, 2013 13:26
A tool to analyze ruby web app acceptance test coverage

Goals

  • For any given page/route, view a listing of the acceptance tests that exercise the page
  • Given a routes file, view a listing of routes which are unexercised by acceptance tests

Features

  • Runs as a rake task (can be run as a part of CI or a local test run)
@moklett
moklett / chargify-webhook-reflector.rb
Created November 13, 2013 20:55
Chargify Webhook Reflector. Sinatra app I use in dev to get warm fuzzies as the webhooks fly by. Since Chargify will only post to ports 80 or 443 in production, you'll need to run this on a web accessible box on one of those ports. http://docs.chargify.com/webhooks
require 'sinatra'
require 'openssl'
require 'json'
post '/' do
body = request.body.read
puts "Time : #{Time.now}"
puts "Actual Signature : #{request.env['HTTP_X_CHARGIFY_WEBHOOK_SIGNATURE_HMAC_SHA_256']}"
puts "Computed Signature: #{signature(body)}"
curl -u <api_key>:x -H Accept:application/json -H Content-Type:application/json https://acme.chargify.com/subscriptions.json
@moklett
moklett / doublesplat.rb
Last active October 4, 2017 16:18
Ruby Double Splat is a bit like Javascript Spread
a = { a: "a" }
b = { b: "b" }
{ **a, **b }
#=> {:a=>"a", :b=>"b"}
{ z: "z", **a, **b }
#=> {:z=>"z", :a=>"a", :b=>"b"}
{ a: "AAA", **a, **b }