Skip to content

Instantly share code, notes, and snippets.

@rlipscombe
rlipscombe / to_dot.ex
Created Aug 5, 2021
Processes to graphviz
View to_dot.ex
def to_dot(pid, path) do
# Starting with the given process, find all of the processes that it's linked to/from, and that it's monitoring/monitored; put them in the dot file.
f = File.open!(path, [:write])
IO.write(f, "digraph G {\n")
IO.write(f, "concentrate=true")
seen = MapSet.new()
to_dot(pid, f, seen)
IO.write(f, "}\n")
@rlipscombe
rlipscombe / rm-duplicate-tracknr.exs
Last active Jul 20, 2021
Elixir snippet to find MP3 files with the same track number in their filenames
View rm-duplicate-tracknr.exs
re = ~r/^.*([0-9][0-9]) .*$/U
files = Path.wildcard("**/*.mp3") |> Enum.filter(&Regex.match?(re, &1))
groups = files |>
Enum.group_by(fn f ->
d = Path.dirname(f)
f = Path.basename(f)
[_, n] = Regex.run(re, f)
{d, n}
end)
View assert_timers.erl
-module(assert_timers).
-export([start_trace/0, stop_trace/0]).
-export([no_timers/1, has_timer/1]).
%% @doc use a dbg handler to track active timers; see http://stackoverflow.com/a/4059587/8446
start_trace() ->
ets:new(timer_trace, [public, named_table, bag]),
Fun = fun({'trace', Pid, 'call', {erlang, send_after, [Time, Dest, Msg]}} = _Msg, State) ->
lager:debug("~p erlang:send_after(~p, ~p, ~p)", [Pid, Time, Dest, Msg]),
State;
View vscode-extensions
CoenraadS.bracket-pair-colorizer
vscode-icons-team.vscode-icons
ms-vscode.cpptools
pgourlain.erlang
JakeBecker.elixir-ls
rust-lang.rust
serayuzgur.crates
@rlipscombe
rlipscombe / Rakefile
Last active Mar 24, 2019
Transcode FLAC to MP3
View Rakefile
require 'find'
VERBOSE = false
mp3_files = []
Find.find('.') do |f|
if File.extname(f) == '.flac'
flac = f
mp3 = "../Music/#{File.dirname(flac)}/#{File.basename(flac, '.flac')}.mp3"
@rlipscombe
rlipscombe / https-server.txt
Last active Dec 6, 2018
Ad-hoc HTTPS server
View https-server.txt
## On the server
# AWS EC2
SERVER_IP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
# Digital Ocean
SERVER_IP=$(curl http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
# Generate a self-signed server certificate
openssl genrsa -out server.key 4096
@rlipscombe
rlipscombe / adhoc-https-file-server.md
Last active Feb 8, 2021
Ad-hoc serving files over HTTPS
View adhoc-https-file-server.md

Overview

You can run a secure ad-hoc HTTP server with negligible effort.

Install some prerequisites

sudo apt install -y busybox-static openssl socat
@rlipscombe
rlipscombe / nginx-worker-limits.md
Created Oct 23, 2018
Increasing nginx file limits
View nginx-worker-limits.md

I needed to load-test an HTTP client, so I used nginx. I ran into some limits:

2018/10/17 23:44:09 [alert] 1860#1860: 768 worker_connections are not enough

To get around this, edit /etc/nginx/nginx.conf and edit the events section:

events {
        worker_connections 5000;
        # multi_accept on;
}
@rlipscombe
rlipscombe / jwt.io.hs256.sh
Created Jul 19, 2018
Generating HS256 JWT in bash (jq, openssl)
View jwt.io.hs256.sh
#!/usr/bin/env bash
# This script uses the same secret key and example as jwt.io,
# so that you can verify that it's correct.
secret_key="your-256-bit-secret"
base64url() {
# Don't wrap, make URL-safe, delete trailer.
base64 -w 0 | tr '+/' '-_' | tr -d '='
@rlipscombe
rlipscombe / gnutls-client.cpp
Created Jan 17, 2018
Demonstrate memory leak with debdiff from #1722411
View gnutls-client.cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <gnutls/x509.h>
#include <assert.h>