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
curl -u <api_key>:x -H Accept:application/json -H Content-Type:application/json https://acme.chargify.com/subscriptions.json
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 / openconnect.md
Created July 24, 2012 15:21
OpenConnect VPN on Mac OS X

Unfortunately, the Cisco AnyConnect client for Mac conflicts with Pow. And by "conflicts", I mean it causes a grey-screen-of-death kernel panic anytime you connect to the VPN and Pow is installed.

As an alternative, there is OpenConnect, a command-line client for Cisco's AnyConnect SSL VPN.

Here's how to get it set up on Mac OS X:

  1. OpenConnect can be installed via homebrew:

     brew update
    

brew install openconnect

@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)}"
@moklett
moklett / margarita.md
Last active August 31, 2020 14:13
The Perfect Margarita

The Perfect Margarita

This is my "go to" margarita because of the ease of preparation and the simplicity of ingredients.

TL;DR

1oz orange liqueur, 2oz tequila, 3oz limeade, 1/2 lime, shaken with ice.