Skip to content

Instantly share code, notes, and snippets.


Tonći Galić Tuxified

View GitHub Profile
bitwalker / config.ex
Created Jul 19, 2016
Useful config wrapper for Elixir
View config.ex
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.

Install makeself:

apt-get install makeself


brew install makeself
aaronjensen / drain_stop.ex
Last active Jul 31, 2021
Phoenix Drain Stop
View drain_stop.ex
# ATTENTION: This is now supported in plug_cowboy as of 2.1.0:
defmodule DrainStop do
@moduledoc """
DrainStop Attempts to gracefully shutdown an endpoint when a normal shutdown
occurs. It first shuts down the acceptor, ensuring that no new requests can be
made. It then waits for all pending requests to complete. If the timeout
expires before this happens, it stops waiting, allowing the supervision tree
to continue its shutdown order.
christhekeele / 1-uses_tracker.ex
Last active Dec 4, 2020
A way to know what modules a module has used in Elixir.
View 1-uses_tracker.ex
# For more elaborate use cases, see the IndirectUsesTracker instead:
# A way to know, at runtime, what modules a module has used at compile time.
# In this case, you include `UsesTracker` into a module. When that module gets
# used in some other module, it registers itself with the other module.
defmodule UsesTracker do
vasanthk / System
Last active Oct 16, 2021
System Design Cheatsheet
View System

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
rbnpi / starwars.rb
Last active Jun 9, 2021
starwars.rb The StarWars theme arranged for Sonic Pi, based on a version by Max Loh Hear it at
View starwars.rb
#Star Wars theme arranged for Sonic Pi by Robin Newman December 2015
#Based on arrangement by Max Loh featured on youtube
use_synth :dsaw
s=0.11 #adjust tempo here
sq=1*s #note timings
sq7=4*sq/7.0 #for semiquaver run
qt=2/3.0*q #for triplets
alanpeabody / my_app.ex
Last active Oct 16, 2021
Websockets in Elixir with Cowboy and Plug
View my_app.ex
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
Plug.Adapters.Cowboy.child_spec(:http, MyApp.Router, [], [
dispatch: dispatch
sunaku / fizzbuzz.exs
Last active Jul 14, 2020
A functional FizzBuzz (without any integer modulus or division) in Elixir. See
View fizzbuzz.exs
# A functional FizzBuzz (without any integer modulus or division) in Elixir
nums = Stream.iterate(1, &(&1 + 1))
fizz = Stream.cycle ["", "", "Fizz"]
buzz = Stream.cycle ["", "", "", "", "Buzz"]
fizzbuzz =, buzz) |> |>
{{"", "" }, number} -> number
{{fizzword, buzzword}, _number} -> fizzword <> buzzword
fizzbuzz |> Stream.take(100) |> Enum.each(&IO.puts/1)
pcreux / pipable.rb
Last active Jun 12, 2018
*nix has pipes, Elixir has pipes, Ruby deserves pipes.
View pipable.rb
# Elixir has pipes `|>`. Let's try to implement those in Ruby.
# I want to write this:
# email.body | RemoveSignature | HighlightMentions | :html_safe
# instead of:
staltz /
Last active Oct 16, 2021
The introduction to Reactive Programming you've been missing