Skip to content

Instantly share code, notes, and snippets.

@sbp
sbp / editable.coffee
Created July 30, 2012 22:58
Edit a DOM using UI controls with contenteditable
node_name = (node) ->
return node.nodeName.toLowerCase()
current_range = () ->
if window.getSelection
selection = window.getSelection()
if selection.getRangeAt and selection.rangeCount
return selection.getRangeAt 0
@sbp
sbp / png.py
Created July 10, 2012 16:49
Simple PNG parser
#!/usr/bin/env python
import sys, struct, binascii
def header(bytes):
return struct.unpack('>NNccccc', bytes)
def parse(bytes):
signature = bytes[:8]
bytes = bytes[8:]
@sbp
sbp / screenshottr.bash
Created July 10, 2012 12:27
Take a screenshot on OS X and upload it to imgur using the "Anonymous" API
#!/bin/bash
# screenshottr!
# Take a screenshot on OS X and upload it to imgur using the "Anonymous" API
# Written by Sean B. Palmer
# Released under the Apache License 2.0. Viva la Libre!
# Abusest thou not this API key
API_KEY="273b7108a37679d9ac31ad5a9f1a314a"
SCREENSHOT="/tmp/$$.screenshot.png"
OUTPUT="/tmp/$$.output.json"
@sbp
sbp / wikipedia-simple-words.txt
Created February 7, 2012 13:51
Wikipedia simple words
a
able
about
account
acid
across
act
addition
adjustment
advertisement
@sbp
sbp / pyg.py
Created February 2, 2012 15:18
Convert between XMP and PRE sections using pygments
#!/usr/bin/env python
import sys
import os
import re
import subprocess
import shutil
r_tag = re.compile(r"(?s)<[^>]+>")
r_pre = re.compile(r"(?s)<pre([^>]+)>(.*?)</pre>")
@sbp
sbp / sitemap.py
Created January 26, 2012 14:02
Generate an HTML sitemap
#!/usr/bin/env python
# $ python sitemap.py ~/sbp.so | pbcopy
import sys
import os
def help():
print "Usage: sitemap.py [ docroot ]"
def main():
@sbp
sbp / clock.py
Created December 31, 2011 23:58
Clock script
import re, math, time, urllib, locale, socket, struct, datetime
from decimal import Decimal as dec
while True:
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.sendto('\x1b' + 47 * '\0', ('ntp1.npl.co.uk', 123))
data, address = client.recvfrom(1024)
if data:
buf = struct.unpack('B' * 48, data)
d = dec('0.0')
@sbp
sbp / videojs-combo.py
Created December 27, 2011 17:32
Create a combined VideoJS file for use with jQuery
#!/usr/bin/env python
import sys, os, shutil, json
out = 'video.combo.js'
if os.path.exists(out):
print >> sys.stderr, 'Error: %s already exists' % out
sys.exit(1)
@sbp
sbp / fiddle.html
Created December 24, 2011 17:03
Resize SVG images
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/7/77/Kirshhoff-example.svg" alt="Kirshhoff-example" class="resizable">
</div>
@sbp
sbp / project.bash
Created December 20, 2011 17:05
Mirror a user's gists
#!/bin/sh
GIST_USER=sbp
function usage() {
echo Usage: $0 [command], where command is one of:
echo update - Gets any new gists for user
echo pull - Keep existing gists synced with server
echo sync - Do an update then a pull
}