Skip to content

Instantly share code, notes, and snippets.

View christhekeele's full-sized avatar
💜

Christopher Keele christhekeele

💜
View GitHub Profile
@christhekeele
christhekeele / a_list_of_styleguides.md
Last active August 29, 2015 13:56
My personal collection of styleguides, with rationalizations for most preferences.

Styleguides

These are my personally cultivated styleguides for different types of text (normally code or markup).

They're less about common conventions (ie. put single spaces between sentences or new lines between different contexts) and more about what syntax features to prefer or avoid in which contexts. As such, they expect the reader to be familiar with the language or markup in question. They are not suitable introductory material to a syntax.

Comments and discussion are welcome, otherwise I'd just keep these in my head instead of on a publicly available forum. I especially invite you to try and change my mind: these, like all opinions and code, are works in progress; not absolutes.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in the OXFORD ENGLISH DICTIONARY.

@christhekeele
christhekeele / secret.rake
Last active August 29, 2015 13:56
Rake task to reset your Rails Application's secret token.
namespace :secret do
desc "Replace application's secret_key_base in the secret_token initalizer with a new one"
task :reset do
# Rails default location
@secret_token_file ||= Rails.root.join('config', 'initializers', 'secret_token.rb')
# Find first string in file
@secret_token_finder ||= /(?<=config\.secret_key_base\s\=\s["'])(.*?)(?=["'])/
File.open(@secret_token_file, 'r+') do |file|
@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 = '.'
@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 / 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 / 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 / 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
# 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 / 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
_ ->

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: