Skip to content

Instantly share code, notes, and snippets.

View eugeneius's full-sized avatar

Eugene Kenny eugeneius

View GitHub Profile
@eugeneius
eugeneius / database_cleaner.rb
Created November 29, 2021 11:32
Intercom's database_cleaner setup (supports initial clean, secondary connections, non-transactional tests, and eliminates an unnecessary query)
require "database_cleaner"
require "database_cleaner/active_record/deletion"
module DatabaseCleaner
module ActiveRecord
module SelectiveTruncation
def information_schema_exists?(_connection)
true
@eugeneius
eugeneius / circle_scientist.rb
Last active March 22, 2017 11:30
Compare control and candidate build runtimes
#!/usr/bin/env ruby
require "thor"
require "net/http"
require "json"
class CircleScientist < Thor
option :circle_api_token, required: true
option :control_branch, default: "master"
option :candidate_branch, required: true
@eugeneius
eugeneius / reaper
Last active February 21, 2017 14:06
Labels and closes stale issues, modelled on the process Rails uses.
#!/usr/bin/env ruby
require "octokit"
require "netrc"
# Pass the repo to reap:
# bin/reaper username/repository
repo = ARGV[0]
# Set the FORCE environment variable to "true" to actually perform actions:
@eugeneius
eugeneius / datadog_pry.rb
Last active February 18, 2017 02:01
Open a Pry session and examine Datadog dashboard and monitors.
#!/usr/bin/env ruby
require 'thor'
require 'dogapi'
require 'pry'
class DatadogPry < Thor
DatadogDashboard = Struct.new(:name, :queries)
DatadogMonitor = Struct.new(:name, :queries)
@eugeneius
eugeneius / each_char_matching_pattern.rb
Last active November 7, 2016 22:23
Demonstrating how Ruby's lazy enumerators and enum_for work.
def each_char_matching_pattern(io, pattern)
return enum_for(:each_char_matching_pattern, io, pattern) unless block_given?
io.each_line.lazy.select do |line|
line =~ pattern
end.flat_map do |line|
line.chars
end.each do |line|
yield line
puts "\toffset: #{io.pos}"
@eugeneius
eugeneius / memoized_attributes_test.rb
Last active November 14, 2015 02:56
Demonstrates a bug in the identity_cache gem: https://github.com/Shopify/identity_cache/issues/246
require "test_helper"
class MemoizedAttributesTest < IdentityCache::TestCase
def test_memoization_should_not_break_dirty_tracking
item = Item.create!
IdentityCache.cache.with_memoization do
Item.fetch(item.id)
Item.fetch(item.id).title = "my title"
Item.fetch(item.id).update(title: "my title")
@eugeneius
eugeneius / delete_missing_instances_from_hosted_zone.sh
Created March 31, 2015 15:10
If you automatically create Route 53 DNS entries for EC2 instances on boot, and you had a bug that meant they were never removed, this gist is for you.
#!/bin/bash
hosted_zone_id=$1
hostnames=`./get_hostnames_from_hosted_zone.sh "$hosted_zone_id"`
while read hostname; do
echo "$hostname"
instance_id=`./hostname_to_instance_id.sh "$hostname"`
if [[ -z $instance_id ]]; then
echo " hostname doesn't contain instance id, skipping."
else
@eugeneius
eugeneius / Gemfile_master
Last active October 19, 2018 16:39
Benchmark for schema cache dump changes: https://github.com/rails/rails/pull/17632
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'mysql2'
gem 'benchmark-ips'
@eugeneius
eugeneius / post-commit
Created October 19, 2014 02:36
Git post-commit hook that sends an approximation of GitHub's 'push' webhook after every commit. Helpful for testing code that consumes those webhooks.
#!/usr/bin/env ruby
# Git post-commit hook that sends an approximation of GitHub's 'push' webhook
# after every commit. Helpful for testing code that consumes those webhooks.
#
# To set this up:
# 1. Create a local repo where you'll make test commits
# 2. Copy this script to .git/hooks/post-commit
# 3. Make it executable: `chmod +x .git/hooks/post-commit`
# 4. Change the `uri` variable below to where webhooks should be sent
@eugeneius
eugeneius / singleton_class_prepend.rb
Created September 1, 2014 05:32
Demonstrates how the behaviour of include and prepend on a singleton class differs between Ruby 2.0 and 2.1
module TestModule
end
class Included
class << self
include TestModule
end
end
class Prepended