Skip to content

Instantly share code, notes, and snippets.

Avatar
⚗️
Elixiring

Tonći Galić Tuxified

⚗️
Elixiring
View GitHub Profile
@bitwalker
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.
View ct.md

Install makeself:

apt-get install makeself

or

brew install makeself
@aaronjensen
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:
# https://hexdocs.pm/plug_cowboy/Plug.Cowboy.Drainer.html
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
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:
# https://gist.github.com/christhekeele/fc4e058ee7d117016b9b041b83c6546a
###
# 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
vasanthk / System Design.md
Last active Oct 16, 2021
System Design Cheatsheet
View System Design.md

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
rbnpi / starwars.rb
Last active Jun 9, 2021
starwars.rb The StarWars theme arranged for Sonic Pi, based on a version by Max Loh http://www.maxloh.com/sheetmusic/ Hear it at https://soundcloud.com/rbnman/starwars
View starwars.rb
#Star Wars theme arranged for Sonic Pi by Robin Newman December 2015
#Based on arrangement by Max Loh www.maxloh.com 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
q=2*sq
qt=2/3.0*q #for triplets
@alanpeabody
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
sunaku / fizzbuzz.exs
Last active Jul 14, 2020
A functional FizzBuzz (without any integer modulus or division) in Elixir. See https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
View fizzbuzz.exs
# A functional FizzBuzz (without any integer modulus or division) in Elixir
# https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
nums = Stream.iterate(1, &(&1 + 1))
fizz = Stream.cycle ["", "", "Fizz"]
buzz = Stream.cycle ["", "", "", "", "Buzz"]
fizzbuzz = Stream.zip(fizz, buzz) |> Stream.zip(nums) |> Stream.map(fn
{{"", "" }, number} -> number
{{fizzword, buzzword}, _number} -> fizzword <> buzzword
end)
fizzbuzz |> Stream.take(100) |> Enum.each(&IO.puts/1)
@pcreux
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:
#
# HighlightMentions.call(RemoveSignature.call(email.body)).html_safe
#
@staltz
staltz / introrx.md
Last active Oct 16, 2021
The introduction to Reactive Programming you've been missing
View introrx.md