Skip to content

Instantly share code, notes, and snippets.

View christhekeele's full-sized avatar
💜

Christopher Keele christhekeele

💜
View GitHub Profile
@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 = '.'
@christhekeele
christhekeele / styles.less
Last active December 8, 2017 15:37
My custom git color styling for Atom
// Colors selected to match the Twilight theme
@git-added-color: #8F9D6A;
@git-modified-color: #7587A6;
@git-removed-color: #CF6A4C;
// Blur inactive windows
body.is-blurred .workspace {
-webkit-filter: blur(0.13em) hue-rotate(19deg);
}
@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 / 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 / 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
_ ->
@christhekeele
christhekeele / guard_helpers.ex
Last active September 1, 2020 20:48
A defguard macro written for Elixir v0.11.something a while back. I don't remember anything breaking at the time. Written for a library that was supposed to help AST transformations, in part by creating guards for particular AST constructs.
defmodule Guard.Helpers do
@moduledoc """
Tools for creating custom guards. Deprecated in favor of `Kernel.defguard`.
"""
@doc """
Creates a macro that's aware of its presence in a guard.
Taken from https://github.com/elixir-lang/elixir/blob/df8b216357e023e4ef078be396fed6b873d6a938/lib/elixir/lib/kernel.ex#L1601-L1615,
@christhekeele
christhekeele / prime.ex
Last active May 5, 2017 10:54
Infinite Prime Generator in Elixir
# Elixir v1.0.2
defmodule Prime do
def stream do
Stream.unfold( [], fn primes ->
next = next_prime(primes)
{ next, [next | primes] }
end )
end