Skip to content

Instantly share code, notes, and snippets.

@rlipscombe
rlipscombe / adhoc-https-file-server.md
Last active February 8, 2021 14:56
Ad-hoc serving files over HTTPS

Overview

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

Install some prerequisites

sudo apt install -y busybox-static openssl socat
-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;
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 March 24, 2019 19:03
Transcode FLAC to MP3
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 / nginx-worker-limits.md
Created October 23, 2018 12:56
Increasing nginx file limits

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 / gnutls-client.cpp
Created January 17, 2018 19:53
Demonstrate memory leak with debdiff from #1722411
#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>
@rlipscombe
rlipscombe / maps-with-size
Last active January 5, 2018 15:37
/proc/pid/maps doesn't have the *size* of the mapped regions
sudo cat /proc/$PID/maps | perl -ne 'print sprintf("%10s", hex($2) - hex($1)), " ", $_ if /([0-9a-f]+)-([0-9a-f]+)/'
@rlipscombe
rlipscombe / QpidSender.cs
Created September 5, 2017 12:54
AMQP.Net Lite, talking to Qpid C++ broker, without TLS
// Problem:
// qpidd reports "[System] error SASL layer required!"
// amqpnetlite reports: "Authentication failed because the remote party has closed the transport stream."
//
// Reason:
// You're connecting to the plaintext qpidd port, and you don't have SASL configured.
//
// Solution:
// Pass scheme: "amqp" to the Address ctor ----------vvvv
var address = new Address("localhost", 5672, scheme: "amqp");
@rlipscombe
rlipscombe / initial_calls.erl
Last active March 25, 2017 00:54
Finding leaked processes in Erlang
lists:sort(fun({_, X}, {_, Y}) -> X > Y end,
dict:to_list(lists:foldl(
fun(Pid, Dict) ->
InitialCall = case erlang:process_info(Pid, initial_call) of
{initial_call,{proc_lib,init_p,A}} ->
case erlang:process_info(Pid, dictionary) of
{dictionary, D} -> proplists:get_value('$initial_call', D, undefined);
_ -> {proc_lib,init_p,A}
end;
{initial_call,{erlang,apply,A}} ->
function dump(o) {
switch (typeof(o)) {
case "table":
local table = "";
foreach (k, v in o) {
if (table != "") {
table += ", "
}
table += dump(k) + ": " + dump(v);
}