Skip to content

Instantly share code, notes, and snippets.


Tyler Hunt tylerhunt

View GitHub Profile
tylerhunt / capitalize_headers.ex
Created Dec 1, 2021
Cowboy lowercases all the headers by default. This stream handler can be used to capitalize the headers. The implementation is in Elixir, and a configuration example showing its use in a Phoenix application is shown.
View capitalize_headers.ex
defmodule AppWeb.CapitalizeHeaders do
def init(stream_id, req, opts) do
:cowboy_stream_h.init(stream_id, req, opts)
def data(stream_id, is_fin, data, state) do, is_fin, data, state)
def info(stream_id, {:response, _status, headers, _body} = info, state) do
tylerhunt /
Last active May 14, 2021
OAuth Redirect Server for Local Development

OAuth Redirect Server for Local Development

Some OAuth providers (like Google), limit what hosts can be used for redirect URIs. This can be problematic when using a hostname-based local development server (like Pow or Invoker). This very simple redirection server can be used to work around this restriction.


tylerhunt /
Created Mar 30, 2021
Generates a 2FA QR code for Instagram.

Instagram 2FA QR Code Generator

Instagram doesn’t make it easy to enable 2FA unless you’re using Google Authenticator or Duo Security. If you want to use it with another authenticator app—like 1Password—this script will generate the QR code you need to easily set that up.


The Ruby script makes use of Bundler’s inline functionality and will automatically install the depenedncies as system gems.

ruby qr.rb
tylerhunt / visualize_specs.rb
Last active Feb 12, 2018
Visualize the state of an RSpec suite using the cached example status.
View visualize_specs.rb
require 'rspec/core'
css = %(
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 / Rakefile
Last active Dec 7, 2017
A Rakefile for trying out Citus using Docker
View Rakefile
file 'docker-compose.yml' do
`curl -L > docker-compose.yml`
namespace :citus do
desc 'Start the Citus cluster'
task :up, [:workers] => 'docker-compose.yml' do |_task, args|
tylerhunt / global_id.rb
Created Aug 7, 2015
RSpec shared context to allow testing of Active Job objects with GlobalID-compatible doubles.
View global_id.rb
RSpec.shared_context 'Global ID', :global_id do
def global_id_instance_double(doubled_class, stubs={})
instance_double(doubled_class, stubs)
.tap { |double|
unless double.respond_to?(:id)
allow(double).to receive(:id).and_return(double.object_id)
tylerhunt / rendering_helper.rb
Created Mar 20, 2015
Override Rails' #render helper to fix an issue with rendering partials based on an object within a namespace.
View rendering_helper.rb
module RenderingHelper
# Override Rails' #render helper to fix an issue with it not honoring objects
# with #to_partial_path definitions that return absolute paths, which is
# problematic when rendering partials within a namespaced controller.
def render(options={}, locals={}, &block)
return super unless options.respond_to?(:to_partial_path)
object = options
path = object.to_partial_path
tylerhunt / active_record_decorator.rb
Created Mar 19, 2015
An abstract decorator that allows decorated Active Record records to be assigned to associations without raising an ActiveRecord::AssociationTypeMismatch error.
View active_record_decorator.rb
require 'delegate'
# An abstract decorator useful for decorating Active Record objects.
class ActiveRecordDecorator < SimpleDelegator
# A proxy for the decorator class to allow the delegation of certain class
# methods to the decorated object's class.
class ClassProxy < SimpleDelegator
def initialize(decorator_class, decorated_class)
super decorator_class
self.decorated_class = decorated_class
tylerhunt / dependencies.rb
Created Feb 28, 2015
A macro to allow object dependencies to be specified at the class level with a block defining a default value. Based on attr_defaultable.
View dependencies.rb
module Dependencies
# Ensure dependencies from the superclass are inherited by the subclass.
def inherited(subclass)
if superclass.respond_to?(:dependencies)
subclass.dependencies.concat dependencies
tylerhunt / my_rack_app.rb
Created Sep 29, 2014
Rack app object with middleware
View my_rack_app.rb
class MyRackApp
def initialize(app)
stack = Rack::Buidler
# stack.use … app
@app = stack.to_app
def call(env)