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: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)
@dpk
dpk / gist:1573191
Created January 7, 2012 00:11
J-style "under" in Plan. Might go in the standard library. (cf. http://prog21.dadgum.com/121.html)
; 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
dpk / gist:1583206
Created January 9, 2012 14:38
Bayesian text filter in Plan.
(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)))))
;; 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
dpk / gist:1844421
Created February 16, 2012 12:13
Remove sendmail from FreeBSD
# 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
dpk / realpath.c
Created February 22, 2012 13:44
Command-line interface to realpath(3)
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
char* instr;
char outstr[PATH_MAX];
instr = argv[1];