Skip to content

Instantly share code, notes, and snippets.

View mediocretes's full-sized avatar

Nathan D Acuff mediocretes

  • Expected Behavior
View GitHub Profile
0eNqdne1unDeShW9lod/WgN8fuZXFYGE7QiJAkQxZmd0gyL1vK1a3FLmO+zz9axBP/IRdrCryJQ+r/rz6dPf7zZfH2/unq5/+vLr9/HD/9eqn//7z6uvtL/cf757/7OmPLzdXP13dPt38dvXh6v7jb8//9Pjx9u7qrw9Xt/c/3/zf1U/5r39/uLq5f7p9ur359vf//oc//uf+998+3Twe/oXT3/z6dPi7v/z6dP034sPVl4evh7/1cP/8nzqQrlf7cPXH4X9zWn/99eE7ULFBc/0QVF3QGU5zOWd+WL/AQiMCjQssFIImt1DIWdxCIWdfYKEWgXK6wEQxKXMbxaDCjRSDXv368++P/7n5Wdqof+PsfQjjn28fbz5/+397BG0XmL6Ew+sXmD4mDfOHzhn/0BZBpwdVzNB4i/tI/Is395EQVJL3K5WLRJYrl2T4FI7ukhQfky7I8THogiQfgzqNzn7ewcrApt/x2jqx5QVowTByfuWmkxmPrSY6l4IDHP44oPbPnzkjbOHY8U9sjbCV+0i4CNfGfSQGgZWgxT80cpM6OPbdtOQI62+GGpjshanOXPNICWeo8UiJOXakKI+OJroVTDXmuflxstMLtpyf6NY4tp2f6db/8UF2/fLRFkH/dVxQ2r+6YYYLlpRwO9ouWFJi0PJBJbZg6EWbY8t5+3U7dBQ18qKeMdVwol48J5qZ+VDHu6945jvefAmOveCoEIwcqA9MdfzHD5t9nOpkONDi2GJ40HZ3tfsbdO3zJhjpn275+dePt/c6w6118s7ieOfg3ys7/Jga/HNFgKqZzOc4/dT8/qdGn2YDbNmEj0aePzrHJmNi7IBS1Mjzx8RUw/GH+51Tgd9v4vezMrefCSfl0Flnxkk55piLz+rM56e9+KhEF7n8bJhqePz0A2m/GHOt8y4/B8a+H23k83OyvPw6cYc9aOgCy109chxFI4LaS9IxNOd5p1rJPXLcMTTyqZXhOaY10uJCRWaKZn7530ZjxQ4VGqBh7Hv3j6Jqud9
@mediocretes
mediocretes / fuelsdk.diff
Created May 10, 2017 01:38
Just... so much.
diff --git a/lib/fuelsdk/http_request.rb b/lib/fuelsdk/http_request.rb
index 335d64e..f7d1510 100644
--- a/lib/fuelsdk/http_request.rb
+++ b/lib/fuelsdk/http_request.rb
@@ -42,34 +42,31 @@ module FuelSDK
class HTTPResponse < FuelSDK::Response
- def initialize raw, client, request
- super raw, client
@mediocretes
mediocretes / test_helper.rb
Created June 25, 2015 17:45
How to define a test that will test multiple versions of a thing
class ProductionTests < ActiveSupport::TestCase
class << self
alias :actually_define_test :test
def test(name, &block)
if name.include? "pdf"
VALID_PRINCE_VERSIONS.each do |version|
actually_define_test("#{name}_prince_v#{version}") do
@prince_version = version
@doc_name = "#{@prince_version}-#{name}"
instance_eval &block
@mediocretes
mediocretes / gist:a0c4ac069dec105b167e
Created June 17, 2015 18:22
How to validate a chargify webhook payload
before_filter :validate_chargify_webhook
def validate_chargify_webhook
signature = request.headers["X-Chargify-Webhook-Signature-Hmac-Sha-256"].to_s
body = request.body.read
computed_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), YOUR_CHARGIFY_SITE_KEY, body)
head :unauthorized unless signature == computed_signature
end
@mediocretes
mediocretes / gist:d74cce5d014aa9aee6ec
Last active August 29, 2015 14:23
How to use a webhook to trigger subscription data refresh
EVENTS_THAT_INCLUDE_SUBSCRIPTION_INFORMATION = ["payment_success", "billing_date_change"]
def handle_event
event = params["event"]
payload = params["payload"]
return head(:unprocessable_entity) unless if event.blank? || payload.blank?
return head(:ok) unless EVENTS_ABOUT_WHICH_WE_CARE.include?(event)
subscription_id = payload["subscription"]["id"]
@mediocretes
mediocretes / gist:ef8bfdee4e58fe1eb8b8
Last active August 29, 2015 14:23
Delegating webhook events to other methods
EVENTS_ABOUT_WHICH_WE_CARE = ["payment_success", "billing_date_change"]
def handle_event
event = params["event"]
payload = params["payload"]
return head(:unprocessable_entity) unless if event.blank? || payload.blank?
return head(:ok) unless EVENTS_ABOUT_WHICH_WE_CARE.include?(event)
self.send(event, payload)
end
@mediocretes
mediocretes / authenticating.rb
Last active August 29, 2015 14:23
Filtering webhook events in chargify
before_filter :validate_chargify_webhook
def validate_chargify_webhook
signature = request.headers["X-Chargify-Webhook-Signature-Hmac-Sha-256"].to_s
body = request.body.read
computed_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"),
YOUR_CHARGIFY_SITE_KEY,
body)
head :unauthorized unless signature == computed_signature
end
CIE Tests:
With dockerized mongo (Finished in 256.761725 seconds.):
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
20 97 28 *0 0 39|0 0 752m 1.65g 133m 0 test-retailer2:1.4% 0 0|0 0|0 50k 35k 2 11:32:10
10 79 51 *0 0 23|0 0 848m 1.84g 141m 0 test-retailer2:1.7% 0 0|0 0|0 77k 120k 2 11:33:10
19 126 44 *0 0 38|0 0 944m 2.03g 154m 1 test-retailer2:0.9% 0 0|0 0|0 47k 38k 2 11:34:10
19 165 28 *0 0 41|0 0 976m 2.09g 158m 0 test-retailer2:1.2% 0 0|0 1|0 48k 48k 2 11:35:10
4 49 5 *0 0 15|0 0 976m 2.09g 142m 0 test-retailer2:0.7% 0 0|0 0|0 11k 14k 1
@mediocretes
mediocretes / gist:4668267
Created January 29, 2013 21:52
Routing for Braintree Callbacks
scope 'callbacks' do
post "revenue" => "callbacks#revenue"
get "*callbacks" => "callbacks#verify"
end
@mediocretes
mediocretes / gist:4668238
Created January 29, 2013 21:48
Verifying BrainTree webhooks with ruby
def verify
if params[:bt_challenge]
render :text => Braintree::WebhookNotification.verify(params[:bt_challenge])
else
head :unprocessable_entity
end
end