Skip to content

Instantly share code, notes, and snippets.

View dpk's full-sized avatar

Daphne Preston-Kendal dpk

View GitHub Profile
View Textile for BBEdit
#!/usr/bin/php -q
// ---- NOTICE ----
// The script is now maintained at
$txt = new Textile;
print $txt->TextileThis(file_get_contents($argv[1]));
dpk / gist:708653
Created November 21, 2010 11:18
Generate v4 UUID
View gist:708653
function uuidgen() { // generate a version 4 UUID
// clarification: a v4 UUID is in the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
// where any x is a random alphanumeric character
// 4 is the numeral 4
// and y may only by one of 8, 9, A or B
$format = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
$x = '1234567890ABCDEF';
dpk / albert.arc
Created January 29, 2011 00:26
A sneak-peek at a new web framework written in Arc, Paul Graham's "hundred year language," or whatever. To go: (load "albert.arc") (srv)
View albert.arc
(load "lib/re.arc")
(load "albert/httpd.arc")
(load "albert/routes.arc")
dpk / textile.arc
Created February 7, 2011 23:04
An increasingly complete version of Textile for Arc. Works, but still todo: links, images, footnotes, span attributes, lists.
View textile.arc
; Textile for Arc, version 0.1
; by David Kendal
; still todo as of this version: links, images, lists, span attributes, footnotes
; also: internal preflight routine to normalise line endings, strip BOM, etc.
; known bugs: subscript not working due to use of tilde sign in function name
(load "lib/re.arc")
(= txt-block-names* (list "h[1-6]" "bq" "fn[0-9]+" "p" "bc" "pre")
txt-block-re* (string "(" (joinstr txt-block-names* "|") ")")
dpk / gist:913932
Created April 11, 2011 17:50
The usage of Plan's Atom feed generator, based on Rails' atom_feed Builder handler. It works by generating SXML which is then turned into the actual XML of the feed.
View gist:913932
(title "David's Weblog")
(subtitle "An awesome weblog")
(link 'self "")
(each post (posts 20)
(title (post 'title)) ; maybe do an automagic thing to detect dictionary items with the same name as atom properties?
(id (tag-uri post))
(link 'alternate (post 'permalink)) ; could be automagic, too
dpk / gist:1027863
Created June 15, 2011 19:21
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 July 11, 2011 18:35 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 November 16, 2011 14:58
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 November 27, 2011 16:37
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 November 28, 2011 20:55
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)