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
@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 / jwt.io.hs256.sh
Created July 19, 2018 10:51
Generating HS256 JWT in bash (jq, openssl)
#!/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 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 / exwx.exs
Created November 26, 2017 16:08
Using wxWidgets from Elixir
#!/usr/bin/env elixir
defmodule Canvas do
@behaviour :wx_object
@title "Canvas Example"
@size {600, 600}
def start_link() do
:wx_object.start_link(__MODULE__, [], [])
@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");
function dump(o) {
switch (typeof(o)) {
case "table":
local table = "";
foreach (k, v in o) {
if (table != "") {
table += ", "
}
table += dump(k) + ": " + dump(v);
}
%% erl -pa deps/exec/ebin -s exec
%%
%% c(exec_sup).
%% {ok, Pid} = exec_sup:start_link().
%%
%% ps -ef | grep sleep
%% killall sleep
%% ps -ef | grep sleep
-module(exec_sup).
#!/usr/bin/env escript
%%% This script converts an arbitrary binary file to an Erlang module with a
%%% single exported 'bin/0' function that returns the original binary.
%%%
%%% See the end of the file for how I figured out the correct terms.
main(["+debug_info" | Files]) ->
io:format("Embedding binaries with debug_info...\n"),
lists:foreach(fun(X) -> embed_file_in_beam(X, [debug_info]) end, Files);