Skip to content

Instantly share code, notes, and snippets.

View dpk's full-sized avatar

Daphne Preston-Kendal dpk

View GitHub Profile
#!/usr/bin/php -q
<?php
// ---- NOTICE ----
// THIS SCRIPT IS NO LONGER UPDATED AND HAS SIGNIFICANT BUGS
// The script is now maintained at https://gist.github.com/1348479
$txt = new Textile;
print $txt->TextileThis(file_get_contents($argv[1]));
@dpk
dpk / gist:708653
Created November 21, 2010 11:18
Generate v4 UUID
<?php
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
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)
(load "lib/re.arc")
(load "albert/httpd.arc")
(load "albert/routes.arc")
@dpk
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.
; 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
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.
(atom-feed
(title "David's Weblog")
(subtitle "An awesome weblog")
(link 'self "http://dpk.org.uk/feed/")
(each post (posts 20)
(entry
(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
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.
#!/usr/bin/ruby
require 'fcgi'
require 'less'
require 'digest/sha1'
FCGI.each do |request|
out = request.out
source = File.new(request.env["SCRIPT_FILENAME"], 'r').read;
hash = Digest::SHA1.hexdigest(source).inspect
@dpk
dpk / gist:1076477
Created July 11, 2011 18:35
thesunonsunday.co.uk WHOIS record as of 19:35, 11th July 2011
Domain name:
thesunonsunday.co.uk
Registrant:
News International Newspapers Limited
Registrant type:
UK Limited Company, (Company number: 1885543)
@dpk
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.
#!/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
dpk / gist:1397778
Created November 27, 2011 16:37
Plan: a web server. (This is not Scheme.)
(set! default-headers* '{content-type "text/html; charset=utf-8"
server "Plan httpd"})
;; OHSHI-
(set! response-codes* '{100 "Continue" ; 100-199 -- informational
101 "Switching Protocols"
102 "Processing"
200 "OK" ; 200-299 -- success
201 "Created"
202 "Accepted"
@dpk
dpk / gist:1402006
Created November 28, 2011 20:55
Plan: the Mustache templating system
;; An implementation of the Mustache template system. (http://mustache.github.com/)
;; See http://mustache.github.com/mustache.5.html 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)