Skip to content

Instantly share code, notes, and snippets.


Daphne Preston-Kendal dpk

View GitHub Profile
dpk / gist:1027863
Created Jun 15, 2011
LESS CSS FCGI script. Using this with a FastCGI server will mean you can serve your LESS files directly as CSS, compiling them on-the-fly as a request is made. Uses the content of the LESS source file to generate an Etag for Validation caching.
View gist:1027863
require 'fcgi'
require 'less'
require 'digest/sha1'
FCGI.each do |request|
out = request.out
source =["SCRIPT_FILENAME"], 'r').read;
hash = Digest::SHA1.hexdigest(source).inspect
dpk / gist:1076477
Created Jul 11, 2011 WHOIS record as of 19:35, 11th July 2011
View gist:1076477
Domain name:
News International Newspapers Limited
Registrant type:
UK Limited Company, (Company number: 1885543)
dpk / gist:1370253
Created Nov 16, 2011
Display a sparkline live, based on the STDIN (newline-seperated) or a comma-seperated list on the cmd-line. Options are obvious enough.
View gist:1370253
#!/usr/bin/env ruby
# encoding: UTF-8
# live sparkline display
# gems required: ruby-terminfo, getoptions
require 'terminfo'
require 'getoptions'
def bar_height n, min, max
h = (((n - min) / (max - min)) * $bs).to_i
dpk / gist:1397778
Created Nov 27, 2011
Plan: a web server. (This is not Scheme.)
View gist:1397778
(set! default-headers* '{content-type "text/html; charset=utf-8"
server "Plan httpd"})
(set! response-codes* '{100 "Continue" ; 100-199 -- informational
101 "Switching Protocols"
102 "Processing"
200 "OK" ; 200-299 -- success
201 "Created"
202 "Accepted"
dpk / gist:1402006
Created Nov 28, 2011
Plan: the Mustache templating system
View gist:1402006
;; An implementation of the Mustache template system. (
;; See for the format documentation
;; Usage: (mustache '{employees ({name "Bob" age "34"} {name "Jim" age "27"} {name "Sally" age "54"})} "{{#employees}}\n* {{name}} is {{age}} years old\n{{/employees}}")
;; ==> "\n* Bob is 34 years old\n\n* Jim is 27 years old\n\n* Sally is 54 years old\n"
(deffn (mustache-tokens tmpl)
(regexp-split (mustache-strip-comments tmpl) r“({{(?:{.+?}|[#&^/>]?.+?)}})”))
(deffn (mustache-strip-comments tmpl)
dpk / gist:1573191
Created Jan 7, 2012
J-style "under" in Plan. Might go in the standard library. (cf.
View gist:1573191
; don't use "inverse" because it's not the same as a mathematical inverse
; and maybe we'll have a separate system for keeping track of those later.
; also possibly set-opposite should be called set-opposite!
(let opposites+ {}
(deffn (opposite f) (opposites+ f))
(deffn (set-opposite f g)
(set (opposites+ f) g)))
(defmac (under var (f &s) &body)
dpk / gist:1583206
Created Jan 9, 2012
Bayesian text filter in Plan.
View gist:1583206
(set spam-words* {}) (tag spam-words* 'default 0) ; todo: implement :->tagged
(set good-words* {}) (tag good-words* 'default 0)
(deffn (tokens body)
(map symbol (regexp-split body /\W+/)))
(deffn (bayes &fs)
(with (pfs (apply * fs) ifs (map (fn (x) (- 1 x)) fs))
(/ pfs (+ pfs (apply * ifs)))))
View gist:1666847
;; A T-esque object system in Plan
;; Uses new-style let syntax
;; wherein (let (x 1 y 2) ...) replaces both (let x 1 ...) and (with (x 1 y 2) ...)
(deffn (operation? f)
(and (function? f) (= (tag f 'disposition) 'operation)))
(deffn (object? o)
(and (function? o) (= (tag o 'disposition) 'object)))
(w/uniq msg-password
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
dpk / realpath.c
Created Feb 22, 2012
Command-line interface to realpath(3)
View realpath.c
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
char* instr;
char outstr[PATH_MAX];
instr = argv[1];