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 / 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 }
@moklett
moklett / task1.exs
Last active May 7, 2024 09:59
Elixir Task - Crash Handling
# This demonstrates that, when using async/await, a crash in the task will crash the caller
defmodule Tasker do
def good(message) do
IO.puts message
end
def bad(message) do
IO.puts message
raise "I'm BAD!"
end
@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:

@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.

@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 / 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 / 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 / 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 / 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']]
]
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