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
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 / 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
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) >
View domain_wildcards.py
from itertools import islice
def possibilities(hostname):
hostname = hostname.lower().strip('.')
yield hostname
labels = hostname.split('.')
for suffix_i in range(1, len(labels)):
yield '*.' + '.'.join(labels[suffix_i:])
View git-scour
#!/bin/sh
# find a file by content from basically anywhere in your git history
# for when you think you lost something but hopefully not
(git stash list; git reflog) | awk '{print $1}' | xargs git grep "${@}"
@dpk
dpk / brexit.md
Created Jun 24, 2016
Brexit: A brief summary of the future, so people don’t keep asking me the same questions
View brexit.md

The answer to any question you might have right now is, basically, ‘nobody knows’. This was not a referendum with a solid plan or piece of legislation behind it: the ‘European Union Referendum Act 2015’ just said there’ll be a vote on it, nothing more. The government wanted to remain in the EU, so the campaign for the Leave vote was campaigning based on pure speculation. And, of course, presented the most optimistic possible image and downplayed any suggestion of things going wrong after a Brexit vote as ‘scaremongering’.

Here’s the situation: assuming the referendum is implemented (according to the letter of the question, if not the spirit) it looks like we can either (a) stay in something to to with Europe, but break a lot of the promises the Leave camp made and ultimately end up with a worse deal than before; or (b) completely leave and trash our economy even further.

Door A

Behind Door A there are two options, which I’ll call Norway and Switzerland.

Norway involves leaving the European Union but st

@dpk
dpk / README.md
Last active Sep 20, 2015 — forked from mbostock/.block
Albers Equal-Area Conic
View retina.js
if (('devicePixelRatio' in window && window.devicePixelRatio >= 1.5) ||
('matchMedia' in window && window.matchMedia("(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)").matches))
{
document.addEventListener('DOMContentLoaded', function() {
var elements = document.getElementsByClassName('retina');
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.tagName !== 'IMG') continue;
var match = element.src.match(/^(.+)\.(.+?)$/);
@dpk
dpk / gist:a92d3ea83aa7142e3317
Created Jun 11, 2015
Restart frontmost application with AppleScript (revised version of my script from c. 2011)
View gist:a92d3ea83aa7142e3317
tell application "System Events" to set _app to the name of the first process whose frontmost is true
tell application _app
quit
set _isRunning to true
repeat while (_isRunning)
delay 1
tell application "System Events"
set _isRunning to ((name of processes) contains _app)
end tell
end repeat
You can’t perform that action at this time.