Skip to content

Instantly share code, notes, and snippets.


Daphne Preston-Kendal dpk

View GitHub Profile
dpk / bfc
Last active Feb 18, 2022
Brainfuck compiler in 182 bytes. (172 without shebang; 163 without shebang or automatic feeding to C compiler)
View bfc
tr -Cd '][.,<>+-'|sed 's/\./putchar(*p);/g;s/,/*p=getchar();/g;s/[+-]/&&*p;/g;s/[<>]/&&p;/g;s/\[/while(*p){/g;y/]<>/}-+/;s/^/main(){int a[30000];int *p=a;/;s/$/}/'|cc -xc -
dpk / gist:8325992
Last active Aug 28, 2021
PyICU cheat sheet
View gist:8325992

PyICU cheat sheet

Because you can't get the docs.


Create a transliterator:

greek2latin = icu.Transliterator.createInstance('Greek-Latin')
dpk / define-macro.scm
Created Mar 4, 2012
define-macro for Chicken Scheme
View define-macro.scm
; kind of a stupid implementation but with
(define-syntax define-macro
(lambda (exp rename compare)
(if (symbol? (cadr exp))
(let ((name (cadr exp))
(expndr (caddr exp))
(-exp (gensym)) (-rename (gensym)) (-compare (gensym)))
`(define-syntax ,name
dpk / gist:5694265
Created Jun 2, 2013
Python: iterate over the graphemes in a string.
View gist:5694265
import unicodedata as u
def itergraphemes(str):
def modifierp(char): return u.category(char)[0] == 'M'
start = 0
for end, char in enumerate(str):
if not modifierp(char) and not start == end:
yield str[start:end]
start = end
yield str[start:]
dpk / gist:1844421
Created Feb 16, 2012
Remove sendmail from FreeBSD
View gist:1844421
# remove sendmail from a FreeBSD system
echo 'sendmail_enable="NO"' >> /etc/rc.conf
chmod 0 /usr/libexec/sendmail/sendmail
chmod 0 /usr/sbin/sendmail
mv /usr/libexec/sendmail/sendmail /usr/libexec/sendmail/sendmail.bak
mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
View utf8strlen.c
#include <stdlib.h>
unsigned long utf8_strlen(unsigned char *s) {
unsigned long len = 0;
while (*++s) {
len += !(*s >> 7) || (*s >> 6);
return len;
dpk / mk-darwin-x86_64.diff
Last active Dec 18, 2017
Patch file for mk-with-libs.tgz to enable installing and building mk from on Mac OS. to apply: patch -p1 < mk-darwin-x86_64.diff
View mk-darwin-x86_64.diff
diff -rNu mk.old/libbio/Make.Darwin-x86_64
--- mk.old/libbio/Make.Darwin-x86_64 1970-01-01 01:00:00.000000000 +0100
+++ 2017-12-18 11:33:22.000000000 +0100
@@ -0,0 +1,7 @@
+CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I${PREFIX}/include
dpk /
Last active Nov 12, 2017
closefrom shim for Python 3
import os
import os.path
import fcntl
import ctypes
from ctypes.util import find_library
import re
libc = None
strategy = None
dpk / gist:3969332
Created Oct 28, 2012
Klop's fixed-point combinator. Needs a lazy-evaluated Scheme.
View gist:3969332
(define L (lambda (a) (lambda (b) (lambda (c) (lambda (d) (lambda (e) (lambda (f) (lambda (g) (lambda (h) (lambda (i) (lambda (j) (lambda (k) (lambda (l) (lambda (m) (lambda (n) (lambda (o) (lambda (q) (lambda (p) (lambda (s) (lambda (t) (lambda (u) (lambda (v) (lambda (w) (lambda (x) (lambda (y) (lambda (z) (lambda (r) (r ((((((((((((((((((((((((((t h) i) s) i) s) a) f) i) x) e) d) p) o) i) n) t) c) o) m) b) i) n) a) t) o) r)))))))))))))))))))))))))))))
(define Yk (((((((((((((((((((((((((L L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L) L))
(define (factorial c)
(lambda (n)
(if (= n 0)
(* n (c (- n 1))))))
View format.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=""
<xsl:import href="util.xslt"/>
<xsl:import href="unformat.xslt"/>
<xsl:function name="isbn:format-13">
<xsl:param name="isbn"/>
<xsl:value-of select="string(isbn:format-13-internal($isbn))"/>
<xsl:function name="isbn:format-13-internal">