Skip to content

Instantly share code, notes, and snippets.

🍸

Christopher Keele christhekeele

🍸
Block or report user

Report or block christhekeele

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@christhekeele
christhekeele / README.md
Last active Mar 17, 2020 — forked from twolfson/README.md
Leverage Flask-SQLAlchemy with Celery
View README.md

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.

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": {
@christhekeele
christhekeele / matcha.ex
Last active Apr 17, 2018
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
christhekeele / aliases.md
Last active Feb 22, 2018
Some git aliases
View aliases.md

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 Dec 13, 2017
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
christhekeele / default_behaviour.ex
Last active Nov 16, 2017
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
christhekeele / mnemonix_repos.md
Last active Jul 2, 2017
How Mnemonix's repository pattern is implemented
View mnemonix_repos.md

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 Aug 31, 2018
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
##
# TYPES
# @type t :: Ecto.Adapter.t
@type t :: Ecto.Adapter.Custom
@christhekeele
christhekeele / guard.ex
Last active Sep 17, 2016
Check quoted expressions for validity inside guards.
View guard.ex
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
Local Git Repos for Mix
View mix.exs
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]
You can’t perform that action at this time.