Skip to content

Instantly share code, notes, and snippets.

View gregawoods's full-sized avatar

Greg Woods gregawoods

  • Mozilla
  • Indianapolis, IN
View GitHub Profile
@gregawoods
gregawoods / amazon.rake
Last active November 1, 2022 12:22
Recursively download XSD documents for use with Amazon MWS.
require 'nokogiri'
namespace :amazon do
desc 'Download XSD files recursively'
task xsd: :environment do
dest = download_xsd_file(
'amzn-envelope.xsd',
'https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_1_9/'
)
# Validate schema
# When inspecting a BigDecimal in the console, default to
# printing it as a float. This is purely cosmetetic and
# is easier to read compared to scientific notation.
#
# Before:
# [1] pry(main)> d = BigDecimal.new(10)
# => 0.1e2
#
# After:
# [1] pry(main)> d = BigDecimal.new(10)
@gregawoods
gregawoods / quickbooks_webhooks_controller.rb
Last active December 3, 2023 01:51
How to verify the signature of a webhook posted from the Quickbooks Online, in Ruby on Rails.
def create
digest = OpenSSL::Digest.new('sha256')
hmac = OpenSSL::HMAC.digest(digest, ENV['QUICKBOOKS_VERIFIER'], request.body.read)
base64 = Base64.encode64(hmac).strip
if base64 == request.headers['intuit-signature']
# valid!
render nothing: true, status: 201
else
# not valid!
render text: 'Invalid signature', status: 400
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.mysql</string>
<key>ProgramArguments</key>
<array>
@gregawoods
gregawoods / development.conf
Last active September 30, 2015 13:44
newsyslog development config
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/Users/gregwoods/Source/*/*/log/*.log 644 3 256 * G
/Users/gregwoods/Source/*/*/spec/dummy/log/*.log 644 3 256 * G
/Users/gregwoods/.rvm/*/*/*.log gregwoods:staff 644 1 10 * G
@gregawoods
gregawoods / git_sync.rake
Last active August 29, 2015 14:10
Just some experimental rake tasks. The goal here is to simplify the process of pushing or pulling assets stored in the public/system directory of a Rails project.
namespace :git_sync do
namespace :push do
desc 'Push public/system files to staging'
task :staging => :environment do
do_rsync_push('staging')
end
desc 'Push public/system files to production'
task :production => :environment do
do_rsync_push('production')
@gregawoods
gregawoods / WeakDelegate.swift
Created July 2, 2014 03:01
Demonstrate an EXC_BAD_ACCESS error when attempting to use optional chaining on a weak delegate variable.
// Playground - noun: a place where people can play
import Cocoa
@class_protocol protocol DownloaderDelegate {
func finishedDownloading(fileName: String)
}
class Downloader {
weak var delegate: DownloaderDelegate?
@gregawoods
gregawoods / application_controller.rb
Last active August 29, 2015 14:02
Resolve issue where Safari 7 and iOS 7 Mobile Safari incorrectly render cached pages when a 304 response is returned from the server.
class ApplicationController < ActionController::Base
before_filter :delete_if_none_match_header
private
# Encountered bug where Safari 7 would fail to render pages when ETAG-based caching kicks in
# This should prevent Safari from attempting such caching
def delete_if_none_match_header
if request.format.html? && request.headers['If-None-Match'] != nil && is_safari?()
class Foo
end
Foo.send(:define_method, "💩") do
puts "Hello, World!"
end
f = Foo.new()
f.send(:💩)
@gregawoods
gregawoods / bundle_install.sh
Created April 18, 2014 02:37
bundle install all the things
#!/bin/bash
websites=/srv/sites
cd $websites
for dir in $(find . -maxdepth 1 -type d)
do
cd $dir
pwd
bundle install --deployment
cd $websites