Skip to content

Instantly share code, notes, and snippets.

View Tuxified's full-sized avatar
⚗️
Elixiring

Tonći Galić Tuxified

⚗️
Elixiring
View GitHub Profile
@christhekeele
christhekeele / 1-uses_tracker.ex
Last active May 27, 2023 00:42
Metaprogramming Elixir module usage: A simple way to know what modules a module has used in Elixir.
# 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 May 6, 2024 20:21
System Design Cheatsheet

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 June 9, 2021 14:16
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
#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 March 24, 2024 13:28
Websockets in Elixir with Cowboy and Plug
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 July 14, 2020 18:10
A functional FizzBuzz (without any integer modulus or division) in Elixir. See https://pragprog.com/magazines/2012-08/thinking-functionally-with-haskell
# 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)
@fxg42
fxg42 / optional.ex
Last active January 21, 2022 12:48
Maybe monad with an Elixir macro dsl
defmodule Optional do
defmacro __using__(_opts) do
quote do
require unquote(__MODULE__)
import unquote(__MODULE__)
end
end
def unit(nil), do: {:err, nil}
def unit(value), do: {:ok, value}
@trusktr
trusktr / DefaultKeyBinding.dict
Last active April 21, 2024 06:32
My DefaultKeyBinding.dict for Mac OS X
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
or replace @ with ^ in this file.
Here is a rough cheatsheet for syntax.
Key Modifiers
@pcreux
pcreux / pipable.rb
Last active June 12, 2018 17:08
*nix has pipes, Elixir has pipes, Ruby deserves pipes.
# 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 May 7, 2024 09:38
The introduction to Reactive Programming you've been missing
#!/bin/bash
# Bash completion for `up` <http://brettterpstra.com/2014/05/14/up-fuzzy-navigation-up-a-directory-tree/>
_up_complete()
{
local rx
local token=${COMP_WORDS[$COMP_CWORD]}
local IFS=$'\t'
local words=$(dirname `pwd` | tr / " ")
local nocasematchWasOff=0