Skip to content

Instantly share code, notes, and snippets.

View tylerhunt's full-sized avatar

Tyler Hunt tylerhunt

View GitHub Profile
@tylerhunt
tylerhunt / visualize_specs.rb
Last active February 12, 2018 12:42
Visualize the state of an RSpec suite using the cached example status.
require 'rspec/core'
css = %(
<style>
html { font-size: 50%; }
.unknown, .passed, .pending, .failed { display: inline-block; height: 1rem; width: 1rem; }
.unknown { background-color: #999; }
.pending { background-color: #FC0; }
.passed { background-color: #3F3; }
.failed { background-color: #F33; }
@tylerhunt
tylerhunt / Rakefile
Last active December 7, 2017 21:07
A Rakefile for trying out Citus using Docker
ENV['COMPOSE_PROJECT_NAME'] ||= 'citus'
ENV['MASTER_EXTERNAL_PORT'] ||= '5433'
file 'docker-compose.yml' do
`curl -L https://raw.githubusercontent.com/citusdata/docker/master/docker-compose.yml > docker-compose.yml`
end
namespace :citus do
desc 'Start the Citus cluster'
task :up, [:workers] => 'docker-compose.yml' do |_task, args|
@tylerhunt
tylerhunt / global_id.rb
Created August 7, 2015 18:51
RSpec shared context to allow testing of Active Job objects with GlobalID-compatible doubles.
RSpec.shared_context 'Global ID', :global_id do
def global_id_instance_double(doubled_class, stubs={})
instance_double(doubled_class, stubs)
.extend(GlobalID::Identification)
.tap { |double|
unless double.respond_to?(:id)
allow(double).to receive(:id).and_return(double.object_id)
end
}
end
@tylerhunt
tylerhunt / Gemfile
Created January 27, 2014 17:19
Fetch the most recent power meter reading from EPB.
source 'https://rubygems.org/'
gem 'capybara'
gem 'capybara-webkit'
@tylerhunt
tylerhunt / struct_to_hash.gemspec
Created December 6, 2013 03:10
Monkey patches Struct with a #to_hash method.
Gem::Specification.new do |spec|
spec.name = 'struct_to_hash'
spec.version = '0.0.1'
spec.platform = Gem::Platform::RUBY
spec.author = 'Tyler Hunt'
spec.summary = 'Struct#to_hash'
spec.description = 'Monkey patches Struct with a #to_hash method.'
spec.files = ['struct_to_hash.rb']
spec.test_file = 'struct_to_hash_spec.rb'
@tylerhunt
tylerhunt / users_controller.rb
Created June 19, 2013 19:02
Example usage of the strong_parameters gem.
class UsersController < ApplicationController
def update
current_user.update_attributes(user_params)
end
private
def user_params
params.require(:user).permit(:email, :password)
end
@tylerhunt
tylerhunt / application_controller.rb
Last active December 18, 2015 12:39
Modify Rails view binding to allow values to be explicitly exposed to the views and telling the instance variables to GTFO.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def render(*args)
options = args.extract_options!
options[:locals] ||= @_exposed
super *args, options
end
def view_assigns
@tylerhunt
tylerhunt / support.md
Last active December 17, 2015 19:58
The Noise in the Night

In which your humble narrator sends a technical support request to LaCie.

In the wee hours of the morning, I awoke to the sound of a distant, melodic clicking. I ventured downstairs to investigate the source of this noise in the night, only to find the 5big's flashing light of death casting the room in the red hue of alarm. I dutifully checked the drive LEDs on the back panel, finding one of them completely void of any illumination. Panicked at the potential for data loss and acting out of self-preservation in the interest of saving my ears from that wicked racket emanating from aluminum enclosure, I pulled up the dashboard to see that drive four was offline. I made the tough call to power it down. My data may be offline now, but I remain hopeful that, with the right part, it will come alive again with my memories intact.

@tylerhunt
tylerhunt / decorator.rb
Created February 11, 2013 21:05
Simple Decorator
class Decorator < SimpleDelegator
class Collection < SimpleDelegator
include Enumerable
def initialize(collection, decorator)
super(collection)
@decorator = decorator
end
def each
@tylerhunt
tylerhunt / deploy.sh
Created November 3, 2012 00:47
Heroku Deploy Script
#!/bin/bash
args=`getopt r:m $*`
if [ $? != 0 ]; then
echo "Usage: $0 [-r heroku] [-m]"
exit 2
fi
set -- $args