Skip to content

Instantly share code, notes, and snippets.

View gaffneyc's full-sized avatar

Chris Gaffney gaffneyc

  • Dead Man's Snitch
  • Holland, MI
View GitHub Profile
@gaffneyc
gaffneyc / check.rb
Created February 15, 2024 13:57
Check Fly.io standby status
require "json"
require "terminal-table"
fly_app = ARGV[0]
if fly_app.nil?
warn "Usage: check.rb [fly app name]"
exit 1
end
Machine = Struct.new(:config) do
@gaffneyc
gaffneyc / vcr_form_matcher.rb
Created November 19, 2015 16:15
VCR matcher for forms
VCR.configure do |c|
# Match the content of urlencoded forms instead of their encoded version.
# This is to address issues with different ordering of the same information.
c.register_request_matcher :form do |actual, match|
content_type = actual.headers["Content-Type"]
# Only valid for forms
if content_type.include?("application/x-www-form-urlencoded")
actual_form = Rack::Utils.parse_nested_query(actual.body)
match_form = Rack::Utils.parse_nested_query(match.body)
@gaffneyc
gaffneyc / running.sql
Last active August 29, 2015 14:16
Issues with PostgreSQL
-- We're having some really weird issues in a production application running on
-- Heroku PostgreSQL 9.3.5. We are seeing a number of long running queries
-- getting stuck inside a transaction (below). We are using PgHero to see and
-- kill the long running queries[1]. Trying to understand what could be
-- happening but we're at a loss.
-- Usually we'll see it idle out at the `UPDATE "sprockets"` line below which
-- causes further updates to that row to block. This bit of code gets run about
-- 1000x per minute for multiple sprockets.
BEGIN
@gaffneyc
gaffneyc / test.rb
Created November 19, 2014 21:41
Disable logging in the test environment
Rails.application.configure do
# Don't write output to test.log
config.logger = ::ActiveSupport::Logger.new("/dev/null")
config.logger.formatter = lambda { |*_| nil }
config.logger.level = 10 # FATAL is 4
end
@gaffneyc
gaffneyc / gist:bd15062f4cfe079c0522
Created October 1, 2014 14:20
Spammer template fail
{
{I have|I’ve} been {surfing|browsing} online
more than {three|3|2|4} hours today, yet I never
found any interesting article like yours. {It’s|It is} pretty worth enough for
me. {In my opinion|Personally|In my view}, if all {webmasters|site owners|website owners|web
owners} and bloggers made good content as you did, the {internet|net|web} will be {much more|a lot more} useful than ever
before.|
I {couldn’t|could not} {resist|refrain from} commenting.
{Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I’ll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss feed}

Keybase proof

I hereby claim:

  • I am gaffneyc on github.
  • I am gaffneyc (https://keybase.io/gaffneyc) on keybase.
  • I have a public key whose fingerprint is 16D8 FE25 1160 5118 22EC 3B48 0F56 ABBB D997 1DF8

To claim this, I am signing this object:

@gaffneyc
gaffneyc / remove_CLI.sh
Created October 28, 2013 13:55
Uninstall the buggered xcode 5.0 command line tools
RECEIPT_FILE=/var/db/receipts/com.apple.pkg.CLTools_Executables.bom
RECEIPT_PLIST=/var/db/receipts/com.apple.pkg.CLTools_Executables.plist
if [ ! -f "$RECEIPT_FILE" ]
then
echo "Command Line Tools not installed."
exit 1
fi
echo "Command Line Tools installed, removing ..."
@gaffneyc
gaffneyc / Vagrantfile
Created March 27, 2013 17:02
Vagrant Shell provisioning to replace default chef install with omnibus installer. Tested on the default precise64 boxes provided for Vagrant.
Vagrant::Config.run("2") do |config|
# Clean up the default image to remove some default puppet, chef, and ruby.
config.vm.provision :shell do |shell|
shell.inline = <<-EOF.gsub(/^ +/, "")
# Make sure vagrant always has sudo access
( cat << 'EOP'
Defaults exempt_group=vagrant
%vagrant ALL=NOPASSWD:ALL
EOP
) > /etc/sudoers.d/vagrant
@gaffneyc
gaffneyc / gist:4609767
Created January 23, 2013 16:52
Classes over methods?
# SomeClass.new("arg1", "arg2").call
class SomeClass < Struct.new(:arg1, :arg2)
def call
@arg1 + @arg2
end
end
# vs
# SomeClass.new.some_method(arg1, arg2)
@gaffneyc
gaffneyc / config.ru
Created November 19, 2012 19:47
Rack app to serve the current chef repo as a tar file
require "open3"
class TarApp
def call(env)
data = nil
status = nil
if(env["REQUEST_PATH"] !~ /(tgz|tar\.gz)/)
return [ 301, { "Location" => "/current.tgz" }, "" ]
end