Skip to content

Instantly share code, notes, and snippets.

dpk dpk

Block or report user

Report or block dpk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dpk
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;
s--;
while (*++s) {
len += !(*s >> 7) || (*s >> 6);
}
return len;
}
@dpk
dpk / gist:8325992
Last active Jul 17, 2018
PyICU cheat sheet
View gist:8325992

PyICU cheat sheet

Because you can't get the docs.

Transliteration

Create a transliterator:

greek2latin = icu.Transliterator.createInstance('Greek-Latin')
@dpk
dpk / clipcat
Created Nov 18, 2010
usage: clipcat [filename] -- despite being called 'cat', it doesn't concatenate multiple
View clipcat
#!/usr/bin/perl -w
# clipcat: the misleadingly-named textClipping outputter for Mac OS X.
# you'll need MacPerl and DeRez. I think the latter ships with OS X,
# but at least comes with the dev tools (which by definition you have
# if you installed MacPerl)
# -------------------------
# by David Kendal (http://dpk.org.uk / @dpkendal)
# bug reports & comments to the address on http://dpk.org.uk/contact/
@dpk
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 https://9fans.github.io/plan9port/unix/ 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.new/libbio/Make.Darwin-x86_64
--- mk.old/libbio/Make.Darwin-x86_64 1970-01-01 01:00:00.000000000 +0100
+++ mk.new/libbio/Make.Darwin-x86_64 2017-12-18 11:33:22.000000000 +0100
@@ -0,0 +1,7 @@
+CC=gcc
+CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I${PREFIX}/include
+O=o
+AR=ar
+ARFLAGS=rvc
+NAN=nan64.$O
@dpk
dpk / closefrom.py
Last active Nov 12, 2017
closefrom shim for Python 3
View closefrom.py
import os
import os.path
import fcntl
import ctypes
from ctypes.util import find_library
import re
libc = None
F_CLOSEM = None
strategy = None
@dpk
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)
1
(* n (c (- n 1))))))
@dpk
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:]
View format.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:isbn="tag:nonceword.org,2016:isbn">
<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>
<xsl:function name="isbn:format-13-internal">
View isbn_ranges.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE ISBNRangeMessage [
<!ELEMENT ISBNRangeMessage (MessageSource?, MessageSerialNumber?, MessageDate, EAN.UCCPrefixes, RegistrationGroups) >
<!ELEMENT MessageSource (#PCDATA) >
<!ELEMENT MessageSerialNumber (#PCDATA) >
<!ELEMENT MessageDate (#PCDATA) >
<!ELEMENT EAN.UCCPrefixes (EAN.UCC+) >
<!ELEMENT RegistrationGroups (Group+) >
<!ELEMENT EAN.UCC (Prefix, Agency, Rules) >
<!ELEMENT Group (Prefix, Agency, Rules) >
You can’t perform that action at this time.