Skip to content

Instantly share code, notes, and snippets.

View andrewhao's full-sized avatar

Andrew Hao andrewhao

View GitHub Profile
@andrewhao
andrewhao / 1.ex
Last active April 1, 2018 02:19
Mocking interfaces in Elixir with Mox
module MyApp.Alexa do
def call do
# ...
get_country_and_zip_code(device_id, consent_token)
|> do_some_other_transformation
# ...
end
defp get_country_and_zip_code(device_id, consent_token) do
url =
@andrewhao
andrewhao / game.ex
Last active July 1, 2025 06:55
Dynamic Supervisors in Elixir
defmodule Game do
use GenServer
def init(game_id) do
{:ok, %{game_id: game_id}}
end
def start_link(game_id) do
GenServer.start_link(__MODULE__, game_id, name: {:global, "game:#{game_id}"})
end
@andrewhao
andrewhao / 01.ex
Last active January 21, 2026 12:25
Lightweight Elixir dependency injection
module MyApp.MyModule do
@my_collaborating_module Application.get_env(:my_app, :my_collaborating_module)
def perform() do
@my_collaborating_module.do_something()
end
end