Skip to content

Instantly share code, notes, and snippets.

View dpk's full-sized avatar

Daphne Preston-Kendal dpk

View GitHub Profile
@dpk
dpk / allcaps.pl
Last active September 23, 2015 14:08
A smarter way to all-caps a string.
#!/usr/bin/perl -w
# A smarter string capitaliser. Everyone knows that in words that start with certain prefixes,
# the prefix should be left in lower- or mixed-case when the word is made 'all-caps.'
# For instance, MacDonald becomes MacDONALD rather than MACDONALD, iPod becomes
# iPOD instead of IPOD, etc. This script attempts to be vaguely clever about doing that while
# also avoiding doing the same with intercapsed or camelcased product names like QuarkXPress.
# The cut-off point was set at four characters because the longest surname prefix that ought
# to be left in mixed-case that I could think of was 'Fitz,' but this causes problems with some
# product names, and they can be listed in @exceptions. Included are MacBook, AirPort, WiFi,
# and PostScript. If you have any other word suggestions, mail them to me at the address on
// A javascript port of my Perl string capitaliser. Possibly someone who is better at
// DOM scripting than me could make a script that would automatically apply this to any
// element styled with text-transform: uppercase.
// Again, the algorithm is too simple to be worth insisting on attribution, but if you
// do use this script anywhere, please attribute it to me in a comment block somewhere.
// By David Kendal, http://dpk.org.uk/
// see also the original perl version at http://gist.github.com/567255
function is_exception (word, exceptions) { // possibly there's a routine built-in to JavaScript to do this
word = word.toLowerCase();
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use JSON;
use Getopt::Long;
use URI::Escape qw( uri_escape_utf8 );
# options
my $query;
my $titles;
#!/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: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"}
@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:931741
Created April 20, 2011 15:54
Plan: a very basic SXML-to-XML transformer. Only takes a small, simple subset of the full SXML.
(deffn sxml->xml (sxml)
(with (tag (car sxml) attrs nil children nil)
(if (= (caadr sxml) '@) ; if we have attributes
(do (if (is-a? (car (cdadr sxml)) 'list)
(set attrs (cdadr sxml)) ; association list attribute mode
(set attrs (pairs (cdadr sxml)))) ; pair list attribute mode -- plan only
(set children (cddr sxml)))
(set children (cdr sxml))) ; else, if we don't have any attributes