Skip to content

Instantly share code, notes, and snippets.

@rlb3
rlb3 / start_peer.exs
Created December 18, 2022 06:40 — forked from ityonemo/start_peer.exs
starts a BEAM peer node
:net_kernel.start([:"main@127.0.0.1"])
:erlang.set_cookie(:cook)
{:ok, peer, peername} =
:peer.start(%{connection: 0, name: :peer, host: ~C'127.0.0.1'})
:peer.call(peer, :erlang, :set_cookie, [:cook])
Node.connect(peername)
# add code paths
:rpc.call(peername, :code, :add_paths, [:code.get_path()])
@rlb3
rlb3 / Engineering.md
Created September 12, 2022 20:03 — forked from MithunArunan/Engineering.md
Building a great product

.

@rlb3
rlb3 / drain_stop.ex
Created June 27, 2022 04:31 — forked from aaronjensen/drain_stop.ex
Phoenix Drain Stop
# 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.
@rlb3
rlb3 / run.sh
Created June 24, 2022 17:25 — forked from bitwalker/run.sh
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@127.0.0.1" -eval "rpc:call('app@127.0.0.1', init, stop, [])" -s init stop
echo "Stopped"
}
trap 'term_handler' TERM INT
@rlb3
rlb3 / dagger_demos.livemd
Created May 11, 2022 23:46 — forked from zblanco/dagger_demos.livemd
Dagger Demos 5/3/22

Dagger Demos

Summary

Dagger is a tool for modeling your workflows as data that can be composed together at runtime.

Dagger constructs can be integrated into a Dagger.Workflow and evaluated lazily in concurrent contexts.

Getting Lazy with Dataflow Graphs in Elixir

Intro

What do Tensorflow, Apache Airflow, Rule Engines, and Excel have in common?

Under the hood they all use DAGs to model data-flow dependencies of the program. Using graphs to model programs is great because you can modify the program at runtime. Lets talk about doing this in Elixir for great good.

@rlb3
rlb3 / README.md
Created February 26, 2021 20:25 — forked from astamicu/Remove videos from Youtube Watch Later playlist.md
Script to remove all videos from Youtube Watch Later playlist

UPDATED 3.12.2020

The old version of youtube with "disable_polymer" is not working anymore, so the script also stopped working.

Thanks to JanTheDeveloper we have a new working script. Big up!

I just changed the '//span[contains(text(),"Watch later")]', to '//span[contains(text(),"Remove from")]', and it should work for any playlist, not just the watch later one. (thanks to hudsonite for the tip)

setInterval(function () {
 document.querySelector('#primary button[aria-label="Action menu"]').click();

Falsehoods programmers believe about prices

  1. You can store a price in a floating point variable.
  2. All currencies are subdivided in 1/100th units (like US dollar/cents, euro/eurocents etc.).
  3. All currencies are subdivided in decimal units (like dinar/fils)
  4. All currencies currently in circulation are subdivided in decimal units. (to exclude shillings, pennies) (counter-example: MGA)
  5. All currencies are subdivided. (counter-examples: KRW, COP, JPY... Or subdivisions can be deprecated.)
  6. Prices can't have more precision than the smaller sub-unit of the currency. (e.g. gas prices)
  7. For any currency you can have a price of 1. (ZWL)
  8. Every country has its own currency. (EUR is the best example, but also Franc CFA, etc.)
@rlb3
rlb3 / README.md
Created April 24, 2019 19:16 — forked from eiri/README.md
Demonstrate Erlang's 'busy wait' effect on CPU utilization

Demonstrate Erlang's 'busy wait' effect on CPU utilization

How?

Just make Erlang to do some light-load task in a bunch of relatively short leaving processes. Calculating PI to 80th digit in batches per 10 procs with short, 8 ms, sleep in-between, to give schedulers a breath space, will do.

Running

Run erl with 8 schedulers and no busy waiting on schedulers at all.

@rlb3
rlb3 / code_lock.ex
Created February 11, 2019 21:47 — forked from peerreynders/code_lock.ex
Erlang gen_statem OTP design principles "handle_event_function" callback mode revised example "translated" to Elixir
# file: code_lock.ex
# Translated from: http://erlang.org/doc/design_principles/statem.html#example-revisited
# callback mode: :handle_event_function
#
defmodule CodeLock do
@behaviour :gen_statem
@name :code_lock_2
def start_link(code),
do: :gen_statem.start_link({:local, @name}, __MODULE__, code, [])