Skip to content

Instantly share code, notes, and snippets.

View tylerhunt's full-sized avatar

Tyler Hunt tylerhunt

View GitHub Profile
@tylerhunt
tylerhunt / Gemfile
Last active October 11, 2023 14:44
ActiveAdmin association autocomplete without complicated plugins.
gem 'active_model_serializers'
gem 'activeadmin'
gem 'jquery-ui-rails'
@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
require 'bundler/setup'
require 'sinatra/base'
require 'rack/contrib'
# The project root directory
$root = ::File.dirname(__FILE__)
class SinatraStaticServer < Sinatra::Base
get(/.+/) do
@tylerhunt
tylerhunt / cunt_catcher.rb
Created October 31, 2011 23:17 — forked from r38y/cunt.rb
Help prevent typos
module CuntCatcher
def cunt
warn "I'm guessing you meant 'count'?"
count
end
end
class Object
include CuntCatcher
end
@tylerhunt
tylerhunt / hswitch.rb
Created July 11, 2011 15:25
Switches Keys for Multiple Heroku Accounts
#!/usr/bin/ruby
require 'fileutils'
account = ARGV.first
unless account
puts "Usage: #{File.basename(__FILE__)} <account>"
exit(1)
end