Skip to content

Instantly share code, notes, and snippets.

View christhekeele's full-sized avatar
💜

Christopher Keele christhekeele

💜
View GitHub Profile
@christhekeele
christhekeele / mnemonix_repos.md
Last active July 2, 2017 12:52
How Mnemonix's repository pattern is implemented

Synopsis

Mnemonix is a key/value adapter library that employs a repository pattern. I wanted to support a few things with it:

  • Multiple 'feature sets'--collections of functions that may or may not be implemented for an adapter
  • A single unified API inside the core module incorporating all feature sets
  • Compile-time and runtime support for configuring repositories
  • Application-controlled and DIY repo supervision
  • The ability for library users to build custom modules with only particular feature sets
@christhekeele
christhekeele / ecto_adapter_custom.ex
Last active August 31, 2018 08:42
Scaffold for a full implementation of the Ecto Adapter behaviours. (Ecto v2.1.4)
defmodule Ecto.Adapter.Custom do
####
# Ecto.Adapter
##
# TYPES
# @type t :: Ecto.Adapter.t
@type t :: Ecto.Adapter.Custom
@christhekeele
christhekeele / guard.ex
Last active September 17, 2016 04:38
Check quoted expressions for validity inside guards.
defmodule Guard do
@guardables ~W[
== != === !== > >= < <=
and or not
+ - * /
<>
in
is_atom is_binary is_bitstring is_boolean
is_float is_function is_integer is_list
@christhekeele
christhekeele / mix.exs
Last active May 21, 2016 19:09
Local Git Repos for Mix
defmodule MyApp.Mixfile do
use Mix.Project
def project do
[app: :my_app,
version: "0.0.1",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
@christhekeele
christhekeele / 1-indirect_uses_tracker.ex
Last active February 10, 2024 02:44
Elixir metaprogramming module usage: A way to track when certain modules are used, and an example adapter/plugin architecture built on top.
# For simpler use cases, see the UsesTracker instead:
# https://gist.github.com/christhekeele/e858881d0ca2053295c6e10d8692e6ea
###
# A way to know, at runtime, what modules a module has used at compile time.
# In this case, you include `IndirectUsesTracker` into a module. When that module gets
# used in some other module, it makes that module registerable under a namespace of your choosing.
# When the registerable module is used into a third module, that third module will know at runtime which
# registerables were `use`d in it at compile time, via a function titled after the namespace.
@christhekeele
christhekeele / 1-uses_tracker.ex
Last active May 27, 2023 00:42
Metaprogramming Elixir module usage: A simple way to know what modules a module has used in Elixir.
# For more elaborate use cases, see the IndirectUsesTracker instead:
# https://gist.github.com/christhekeele/fc4e058ee7d117016b9b041b83c6546a
###
# A way to know, at runtime, what modules a module has used at compile time.
# In this case, you include `UsesTracker` into a module. When that module gets
# used in some other module, it registers itself with the other module.
##
defmodule UsesTracker do
@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:

# 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