Skip to content

Instantly share code, notes, and snippets.

View christhekeele's full-sized avatar
💜

Christopher Keele christhekeele

💜
View GitHub Profile
@christhekeele
christhekeele / pre-commit
Last active May 3, 2016 00:19
Ever committed with `gem 'foobar', path: '~/source'` in your Gemfile and broken a build?This git pre-commit hook ensures you never will again.If you try and commit while a gem in your Gemfile is loading with the `:path` option, you will be stopped with a helpful message. The only exception: gems embedded within your project are allowed.
#!/usr/bin/env ruby
# A pre-commit hook script to ensure that no local gem dependencies (gem 'asdf', path: '~/local')
# exist in your Gemfile before commiting.`
# Allows gems to be loaded from source within the current project directory, but not from outside.
puts 'Checking for local dependencies in your Gemfile.'
ROOT_PATH = File.expand_path('../../..', __FILE__)
NESTED_GEMSPECS = Dir["#{ROOT_PATH}/**/*.gemspec"]
GEMFILE = ENV['BUNDLE_GEMFILE'] || File.join(ROOT_PATH, 'Gemfile')
@christhekeele
christhekeele / pipeline.rb
Last active January 26, 2016 19:01
Cool use of subclassing Module in Ruby.
class Pipeline < Module
attr_accessor :transforms
def initialize(*transforms, &implementation)
@transforms = transforms
instance_eval &implementation if block_given?
end
def call(*args, &block)
transformers.reduce(block || default_block) do |pipeline, transformer|

Keybase proof

I hereby claim:

  • I am christhekeele on github.
  • I am christhekeele (https://keybase.io/christhekeele) on keybase.
  • I have a public key whose fingerprint is FD54 8218 8153 75DB 2F2E 31E4 4F18 C524 2FAE 4D97

To claim this, I am signing this object:

@christhekeele
christhekeele / pattern_match.ex
Last active January 2, 2016 12:59
Macro for testings pattern and guards in iex.
# Put in your .iex, and `require Pattern`
defmodule Pattern do
defmacro match?(pattern, input, code_block // []) do
code = Dict.get(code_block, :do, nil)
quote do
case unquote(input) do
unquote(pattern) ->
unquote(code)
:ok
_ ->
# FORCE RAILS REDIRECTS TO HONOR CONTENT-TYPE HEADERS
# https://github.com/rails/rails/issues/17194
require 'action_controller/metal/redirecting'
module ActionController
module Redirecting
def redirect_to(options = {}, response_status = {}) #:doc:
raise ActionControllerError.new("Cannot redirect to nil!") unless options
@christhekeele
christhekeele / config.rb
Last active August 31, 2015 20:44 — forked from thetron/config.rb
Middleman Rails Assets config
# config.rb
after_configuration do
if defined?(RailsAssets)
RailsAssets.load_paths.each do |path|
sprockets.append_path path unless sprockets.paths.include? path
Dir[File.join(path, '*')].select do |contents|
File.file? contents
end.map do |file|
Pathname.new File.basename file
@christhekeele
christhekeele / RPG-stylesheet.md
Last active August 29, 2015 14:21
A jist.in stylesheet for RPG gists.

This is a custom css stylesheet for Markdown gists using the jist.in service.

To use, simply add the custom.css file to your gist.

Below is a demonstration of all markdown components and how they appear styled.

Header 1

@christhekeele
christhekeele / postgres_ext-issue-162.rb
Last active August 29, 2015 14:20
Test first_or_initialize behaviour with postgres_ext array types.
require 'active_record'
require 'postgres_ext'
require 'minitest/autorun'
require 'logger'
# DB created on localhost with `createdb first_or_initialize`
ActiveRecord::Base.establish_connection('postgres://localhost/first_or_initialize')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
@christhekeele
christhekeele / ams-nested-listed-predicates-monkeypatch.rb
Created July 28, 2014 17:01
A monkey patch to ActiveModel::Serializers 0.9.0.alpha1 to add contextual awareness of nesting and listing.
require 'active_model/serializer/associations'
module ActiveModel
class Serializer
def initialize(object, options={})
@object = object
@scope = options[:scope]
@root = options.fetch(:root, self.class._root)
@meta_key = options[:meta_key] || :meta
@meta = options[@meta_key]
@christhekeele
christhekeele / quack.gemspec
Last active August 29, 2015 13:57
Method contracts for Ruby. No more `if object.respond_to? :waddle and object.respond_to? :quack and object.respond_to?...`
Gem::Specification.new do |s|
s.name = 'quack'
s.summary = ''
s.description = ''
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.files = ['quack.rb']
s.require_path = '.'