Skip to content

Instantly share code, notes, and snippets.

Avatar

Christian Blavier cblavier

View GitHub Profile
@cblavier
cblavier / rewrite_request_logger_cookie.ex
Created Oct 13, 2020
Phoenix plug to rewrite phoenix_live_dashboard request_logger cookie to parent domain
View rewrite_request_logger_cookie.ex
@cblavier
cblavier / ecto_producer.ex
Created Nov 2, 2019
GenStage producer streaming / buffering data from an Ecto query. Can be used with Flow.
View ecto_producer.ex
defmodule Flow.EctoProducer do
use GenStage
import Ecto.Query
@default_chunk_size 5000
@default_key :id
@stop_delay 10
# Possible options for producer
View n_test.sh
$> mix n_test 1 4
$> mix n_test 2 4
$> mix n_test 3 4
$> mix n_test 4 4
@cblavier
cblavier / semaphore.yml
Created Oct 7, 2019
SemaphoreCI pipeline
View semaphore.yml
version: v1.0
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
fail_fast:
stop:
when: "true"
@cblavier
cblavier / ntest.ex
Created Oct 7, 2019
Parallel test runner
View ntest.ex
defmodule Mix.Tasks.NTest do
use Mix.Task
@wildcard "apps/*/test/**/*_test.exs"
def run([i, n | args]) do
{i, _} = Integer.parse(i)
{n, _} = Integer.parse(n)
test_paths =
@cblavier
cblavier / wait_helper.ex
Created Oct 7, 2019
Wait helpers, used with Elixir hound browser testing library
View wait_helper.ex
defmodule MyApp.WaitHelper do
use Hound.Helpers
def wait_until(fun), do: wait_until(1000, fun)
def wait_until(0, fun), do: fun.()
def wait_until(timeout, fun) do
fun.()
rescue
Hound.NoSuchElementError -> retry(timeout, fun)
View mix xref output
mix xref graph --sink lib/my_app_web/controllers/campaign_controller.ex
lib/my_app_web/views/admin/admin_campaign_log_view.ex
├── lib/my_app_web/router.ex (compile)
│ ├── lib/my_app_web/controllers/admin/admin_tag_controller.ex
│ │ ├── lib/my_app_web/router.ex (compile)
│ │ ├── lib/my_app_web/plugs/authorization.ex (compile)
│ │ │ └── lib/my_app_web/router.ex (compile)
│ │ ├── lib/my_app_web/controllers/helpers/error_helpers.ex (compile)
│ │ │ ├── lib/my_app_web/views/error_view.ex
@cblavier
cblavier / firmware_reload.ex
Last active Jul 9, 2019
Elixir nerves to upload firmware / reload code
View firmware_reload.ex
defmodule Mix.Tasks.MyNervesProject.Firmware.Reload do
use Mix.Task
@app_name Mix.Project.config[:app]
@cookie_file "rel/vm.args"
@mdns_domain Application.get_env(:nerves_init_gadget, :mdns_domain)
@node_name Application.get_env(:nerves_init_gadget, :node_name)
def run(_) do
@cblavier
cblavier / application.ex
Last active Sep 10, 2020
Cowboy 2.5 proxy, used to bind a single port (on Heroku) for umbrella Phoenix applications. It supports HTTPS and websockets properly.
View application.ex
defmodule MasterProxy.Application do
alias MyApp.Endpoint, as: MyAppEndpoint
alias MyApp.UserSocket, as: MyAppUserSocket
alias MyOtherApp.Endpoint, as: MyOtherAppEndpoint
alias MyOtherApp.UserSocket, as: MyOtherAppUserSocket
alias Phoenix.LiveReloader.Socket, as: LiveReloadSocket
alias Plug.Cowboy
View facade.ex
defmodule MyApp.Facade do
defmacro facade(mod) do
quote bind_quoted: [mod: mod] do
Enum.each apply(mod, :__info__, [:functions]), fn {fun, arity} ->
case arity do
0 -> defdelegate unquote(fun)(), to: mod
_ ->
values = Enum.map(1..arity, &(Macro.var(:"arg#{&1}", mod)))
defdelegate unquote(fun)(unquote_splicing(values)), to: mod
You can’t perform that action at this time.