Skip to content

Instantly share code, notes, and snippets.


Christopher Keele christhekeele

View GitHub Profile
christhekeele / compile.markdown.ex
Last active August 16, 2020 08:51
Turn markdown files into HTML in Elixir projects at compile-time.
View compile.markdown.ex
# 1. Add Earmark to your dependencies
# 2. Place this file in lib/mix/compile.markdown.ex
# 3. Add to your mix.exs project's compilers:, ie:
# compilers: [:markdown] ++ Mix.compilers()
# 4. Profit?
defmodule Mix.Tasks.Compile.Markdown do
christhekeele / foo.ex
Created June 12, 2020 07:56 — forked from 0x6a68/foo.ex
Spec to Callback
View foo.ex
defmodule MyApp.Foo do
@on_definition MyApp.SpecToCallback
@spec bar(String.t()) :: String.t()
def bar(foobar) do
defp impl, do: Application.get_env(:my_app, :my_app_foo_impl, __MODULE__.DefaultImpl)
christhekeele /
Last active March 17, 2020 19:08 — forked from twolfson/
Leverage Flask-SQLAlchemy with Celery

Last update: 2020-03-17

Flask-SQLAlchemy has some nice built-ins (e.g. accessing query directly on classes). To continue leveraging these nicities while still inside of a Celery worker, we need to make sure we setup/teardown in a similar fashion to Flask-SQLAlchemy does on Flask.


Flask-SQLAlchemy uses create_scoped_session at startup which avoids any setup on a per-request basis.

This means Celery can piggyback off of this initialization.

View gist:9114d43f152393088a3d002aacdb7fb4
This file has been truncated, but you can view the full file.
"yieldstar_best": [
"Partner": "realpage",
"Data": {
"PhysicalProperty": {
"Property": {
"Building": { "@IDValue": "1", "Name": "N/A" },
"Floorplan": {
"Identification": { "@IDValue": "1" },
christhekeele / matcha.ex
Last active April 17, 2018 22:19
Possible macro API for generating match patterns/specifications in Elixir
View matcha.ex
defmodule Matcha do
@moduledoc """
Documentation for Matcha.
@doc """
Handles the sigil `~m`.
It returns a match pattern or specification.
christhekeele /
Last active February 22, 2018 09:14
Some git aliases

git chunk

git config --global alias.chunk 'add -p'

Usage: starts an interactive chunk-by-chunk staging session, similar to git rebase -i. Handy for picking apart a full index to make a nicer narrative of small commits.

git current

christhekeele / mnemonix-passthrough-proxy.ex
Last active December 13, 2017 19:54
An example meta store for Mnemonix
View mnemonix-passthrough-proxy.ex
defmodule Mnemonix.Stores.Meta.PassThrough do
@moduledoc """
A `Mnemonix.Store` that caches reads from a backend store into a frontend one.
Writes and removals are applied to both stores.
Works best with quicker or closer stores in the frontend, like in-memory ones;
with a store-wide ttl to keep their footprint light.
iex> {:ok, backend} = Mnemonix.Stores.Redix.start_link()
christhekeele / default_behaviour.ex
Last active November 17, 2022 08:49
Behaviours with Defaults for Elixir
View default_behaviour.ex
defmodule Default.Behaviour do
@moduledoc """
Creates a behaviour that carries its own default implementation.
When used into a behaviour module, when that module in turn is used, all functions
defined on it are given to the using module.
This allows you to have concrete implementations of the behaviour's default functionality
for testing, unlike cramming them all into a __using__ macro.
christhekeele /
Last active July 2, 2017 12:52
How Mnemonix's repository pattern is implemented


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 / 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)
View ecto_adapter_custom.ex
defmodule Ecto.Adapter.Custom do
# Ecto.Adapter
# @type t :: Ecto.Adapter.t
@type t :: Ecto.Adapter.Custom