Skip to content

Instantly share code, notes, and snippets.

@sbp
sbp / getconf.h
Created July 12, 2024 08:56
getconf.sh from sbase generated by scripts/getconf.sh as of commit b30fb56804bfed69b45ef0e944d2e029e4d26258
static const struct var confstr_l[] = {
#ifdef _CS_PATH
{"PATH", _CS_PATH},
#endif
#ifdef _CS_POSIX_V7_ILP32_OFF32_CFLAGS
{"POSIX_V7_ILP32_OFF32_CFLAGS", _CS_POSIX_V7_ILP32_OFF32_CFLAGS},
#endif
#ifdef _CS_POSIX_V7_ILP32_OFF32_LDFLAGS
{"POSIX_V7_ILP32_OFF32_LDFLAGS", _CS_POSIX_V7_ILP32_OFF32_LDFLAGS},
#endif
@sbp
sbp / rels.py
Created July 23, 2021 08:21
Script to convert IANA link relations CSV to JSON-LD
#!/usr/bin/env python3
"""
Usage: ./rels.py link-relations-1.csv URL
URL should be e.g. 'http://www.example.org/assignments/relation/#'
"""
from typing import Any, Dict, Iterator, List
def stream(f: Iterator[str], base: str) -> Iterator[Dict[str, str]]:
@sbp
sbp / run-j1-eforth.sh
Created July 20, 2017 19:42
How to run the J1 eForth by @samawati on macOS
#!/bin/sh
git clone https://github.com/samawati/j1eforth
cd j1eforth
brew install gforth libpcap
LDFLAGS=-L/usr/local/opt/libpcap/lib CPPFLAGS=-I/usr/local/opt/libpcap/include gcc -o j1 -lpcap j1.c
gforth j1.4th
./j1
@sbp
sbp / litc.py
Created March 28, 2017 13:39
Literate Markdown comments in C
#!/usr/bin/env python3
import re
import subprocess
import sys
pattern = r'(?s)("[^"\\]*(?:\\.[^"\\]*)*")|/\*(.*?)\*/|([^"/]+)|(.)'
token = re.compile(pattern)
def put(text):
@sbp
sbp / simplesha3.patch
Last active November 11, 2015 12:01
Patch to make simplesha3 (Version 20150922) Python 3 compatible
$ diff -Naur simplesha3.djb.c simplesha3.c
--- simplesha3.djb.c 2015-09-22 11:28:31.000000000 +0100
+++ simplesha3.c 2015-11-11 11:59:16.000000000 +0000
@@ -11,7 +11,7 @@
int n; \
if (!PyArg_ParseTuple(args,"s#:update",&m,&n)) return 0; \
Keccak(r*8,m,n,p,h,d); \
- return PyString_FromStringAndSize((const char *)h,d); \
+ return PyBytes_FromStringAndSize((const char *)h,d); \
} \
@sbp
sbp / firefox-url-safe
Created September 9, 2015 16:32
Firefox URL safe characters
!#$&*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}~
@sbp
sbp / choice.py
Created September 4, 2015 14:12
Choose from a range interactively
#!/usr/bin/env python3
# choice.py, by Sean B. Palmer
import sys
countries = ["Albania", "Andorra", "Austria", "Belarus", "Belgium", "Bulgaria",
"Cyprus", "Czechoslovakia", "Denmark", "Estonia", "Faeroe Islands", "Finland",
"France", "Germany", "Gibraltar", "Greece", "Guernsey", "Hungary", "Iceland",
"Ireland", "Isle of Man", "Italy", "Jan Mayen", "Jersey", "Latvia",
"Liechtenstein", "Lithuania", "Luxembourg", "Malta", "Moldova", "Monaco",
@sbp
sbp / BLAKE2.patch
Created August 24, 2015 12:03
Patch for building BLAKE2 b2sum on OS X
$ git diff
diff --git a/b2sum/makefile b/b2sum/makefile
index 806cc72..1171005 100644
--- a/b2sum/makefile
+++ b/b2sum/makefile
@@ -1,5 +1,5 @@
-CC=gcc
-CFLAGS=-std=c99 -O3 -march=native -I../sse -static -fopenmp
+CC=gcc-5
+CFLAGS=-std=c99 -O3 -march=native -I../sse -fopenmp
@sbp
sbp / bytes-to-base58
Created July 3, 2015 13:24
Convert bytes to base58
#!/usr/bin/env python3
import sys
base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
def base_encode(octets, alphabet):
base = len(alphabet)
bignum = 0
for (index, octet) in enumerate(reversed(octets)):
@sbp
sbp / copi-stack-annotation.txt
Last active August 29, 2015 14:24
Copi stack annotation
"json"
import ->
"urllib.request"
import ->
"https://api.bitcoinaverage.com/ticker/global/all"
urllib
.request ->- module
.urlopen -->- http.client.HTTPResponse