Skip to content

Instantly share code, notes, and snippets.

View christhekeele's full-sized avatar
💜

Christopher Keele christhekeele

💜
View GitHub Profile
@christhekeele
christhekeele / postgres-uuid-reflection.md
Last active July 20, 2023 16:29
Automatic UUID Reflection in Postgres

Automatic UUID Reflection in Postgres

You have a system backed by a Postgres database that uses UUIDs as primary keys for everything. This is nice:

  • You can generate ids on clients before transmitting writes to servers if you wish.
  • You don't have to worry about exhausting the integer size allocated to your auto-incrementing primary keys.[^1]
  • You don't have to worry about enumeration attacks from auto-incrementing primary keys.
  • You can identify and index on data that has no natural key, without the challenges of auto-incrementing primary keys.

The Problem

@christhekeele
christhekeele / elixir-bio.md
Last active October 26, 2023 03:42
My activity in Elixir since 2013!

In roughly chronological order:

@christhekeele
christhekeele / compile.markdown.ex
Last active August 16, 2020 08:51
Turn markdown files into HTML in Elixir projects at compile-time.
####
# USAGE:
#
# 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
christhekeele / foo.ex
Created June 12, 2020 07:56 — forked from 0x6a68/foo.ex
Spec to Callback
defmodule MyApp.Foo do
@on_definition MyApp.SpecToCallback
@spec bar(String.t()) :: String.t()
def bar(foobar) do
impl().bar(foobar)
end
defp impl, do: Application.get_env(:my_app, :my_app_foo_impl, __MODULE__.DefaultImpl)
end
@christhekeele
christhekeele / README.md
Last active March 17, 2020 19:08 — forked from twolfson/README.md
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.

Setup

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

https://github.com/mitsuhiko/flask-sqlalchemy/blob/2.0/flask_sqlalchemy/__init__.py#L668

This means Celery can piggyback off of this initialization.

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
christhekeele / matcha.ex
Last active April 17, 2018 22:19
Possible macro API for generating match patterns/specifications in Elixir
defmodule Matcha do
@moduledoc """
Documentation for Matcha.
"""
@doc """
Handles the sigil `~m`.
It returns a match pattern or specification.
@christhekeele
christhekeele / aliases.md
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
christhekeele / mnemonix-passthrough-proxy.ex
Last active December 13, 2017 19:54
An example meta store for Mnemonix
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
christhekeele / default_behaviour.ex
Last active April 22, 2024 02:05
Behaviours with Defaults for Elixir
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.