Skip to content

Instantly share code, notes, and snippets.

View christhekeele's full-sized avatar
💜

Christopher Keele christhekeele

💜
View GitHub Profile
@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.

@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