Skip to content

Instantly share code, notes, and snippets.

View dpk's full-sized avatar

Daphne Preston-Kendal dpk

View GitHub Profile
@dpk
dpk / gist:3969332
Created October 28, 2012 18:11
Klop's fixed-point combinator. Needs a lazy-evaluated Scheme.
(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))))))
<?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">
<?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) >
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:])
@dpk
dpk / gist:646570
Created October 26, 2010 09:05
View Generated Source in BBEdit
-- based on John Gruber's original Safari Source in BBEdit script
-- http://daringfireball.net/2003/01/safari_source_in_bbedit
-- and duct tape
tell application "Safari" to set theSource to do JavaScript "window.document.documentElement.outerHTML" in document 1
tell application "BBEdit"
activate
make new text window with properties ¬
{contents:theSource, source language:"HTML"}
#!/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 June 24, 2016 05:50
Brexit: A brief summary of the future, so people don’t keep asking me the same questions

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 / gist:4757681
Last active January 29, 2016 13:40
RFC 3986 URI BNF translated to a regular expression. (Uses Ruby/Oniguruma/Onigmo named capture syntax)
(?xi)
\A
# unreserved: [a-z0-9\-._~]
# sub-delims: [!$&'()*+,;=]
# pct-encoded: %[0-9a-f]{2}
# dec-octet: (?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
# pchar: (?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})
# h16: [0-9a-f]{1,4}
# ls32: (?:[0-9a-f]{1,4}:[0-9a-f]{4}|
# (?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
@dpk
dpk / imgurorder.py
Created August 4, 2013 12:40
rename images downloaded from imgur so as to sort as in the original
#!/usr/bin/env python3
from lxml.html import html5parser as html
import requests
import os, os.path
import sys
class ImgurAlbumError(Exception): pass
def imgur_album_get(url):
@dpk
dpk / uniqid.py
Last active December 19, 2015 22:59
Python: compact-ish unique identifiers
import base64
import struct
from uuid import getnode as get_mac
import os
from threading import Lock
import time
from ssl import RAND_bytes as random_bytes
mac = struct.pack('>Q', get_mac())[2:] # do this now in case it is slow (see Python manual)