Skip to content

Instantly share code, notes, and snippets.

@jes
jes / th-decode.pl
Created July 4, 2023 15:02
opensips topology_hiding Contact param decoder
#!/usr/bin/perl
#
# Decoder for OpenSIPS topology_hiding Contact header data params
# James Stanley 2023
#
# The OpenSIPS topology_hiding module can encode information in
# a Contact header URI parameter. The encoding is just XOR against the
# key, with the key repeating when it is too short. The plaintext
# contains the contents of the Record-Route headers, Contact header,
# and receiving socket address of the message that came into OpenSIPS.

The Gambler's Ballad

or, An Incident in Jakes's Saloon

by Milan Bulovic, 1971

Transcribed from https://www.youtube.com/watch?v=l23K3OLc1Es

One afternoon in Jake's Saloon gamblers were in the back.
A breed of men in a smoky den, all with a losing knack.

$ cat app.ts
const rl = require('readline').createInterface({
input: process.stdin,
});
rl.on('line', (n: number) => {
const m = n + 1;
console.log(`m = ${m}`);
});
@jes
jes / protoproxy.go
Last active September 23, 2022 11:53
Run SSH and HTTP on the same port
package main
import (
"fmt"
"net"
"os"
"strings"
)
func main() {
Note that these are measured in bytes (from my Linux system) rather than words. The size in words is half the size in bytes.
$ ls -lS sys/*.bin
-rw-rw-r-- 1 jes jes 49494 Aug 10 15:33 slangi.bin
-rw-rw-r-- 1 jes jes 40426 Aug 10 15:04 asm.bin
-rw-rw-r-- 1 jes jes 40362 Aug 10 15:04 lisp.bin
-rw-rw-r-- 1 jes jes 38508 Aug 10 15:04 slangc.bin
-rw-rw-r-- 1 jes jes 37650 Aug 10 15:04 rude.bin
-rw-rw-r-- 1 jes jes 31168 Aug 10 15:04 kilo.bin
-rw-rw-r-- 1 jes jes 22382 Aug 10 15:53 sh.bin
>>> def f():
... return 1
...
>>> def g():
... return f()
...
>>> g()
1
>>> def f():
... return 2
//var f = "uncomment me to change colours";
var yellow = new Uint16Array([0x0000,0xFFC0],0,1); // black, yellow
var white = new Uint16Array([0x0000,0xffff],0,1); // black, white
var red = new Uint16Array([0x0000,0xf800],0,1); // black, red
var buf = Graphics.createArrayBuffer(240,160,1, {msb:true});
function flip(x,y,palette) {
g.drawImage({width:240,height:40,bpp:1,buffer:buf.buffer, palette:palette},x,y);
#!/usr/bin/perl
# neural net to represent an image by mapping (x,y) => (r,g,b)
# James Stanley 2021
# inspired by https://news.ycombinator.com/item?id=28448626
use strict;
use warnings;
use AI::FANN qw(:all);
@jes
jes / generate-stencil.pl
Last active February 28, 2021 01:44
Convert a black-and-white PNG into an STL stencil
#!/usr/bin/perl
# XXX: This program is super unfinished. It works for my use case, but you will certainly
# have to modify the constants in order to use it for your use case. Make sure the input
# image is black-and-white. Note that the output triangle mesh is super unoptimised.
#
# This is very MVP.
use strict;
use warnings;
/* Cat Laser */
#include <Servo.h>
// pin configuration
const int xservopin = 2;
const int yservopin = 3;
const int speedpin = A0;
const int dwellpin = A1;
const int xrangepin = A2;