Skip to content

Instantly share code, notes, and snippets.

@sbp
sbp / colourbox.coffee
Last active December 14, 2015 20:59
Octavo colour-box command
$ ->
octavo.shortcuts["Ctrl+'"] = (position) ->
octavo.input (value) ->
return if not position.balanced
span = $("<span/>").text("").css
width: "9px"
height: "9px"
border: "1px solid #000"
background: value
@sbp
sbp / coffee-script-1.5.0-bis.min.js
Created February 28, 2013 10:26
Minified CoffeeScript 1.5.0 bis, supporting text/literate-coffeescript in the browser
/**
* CoffeeScript Compiler v1.5.0
* http://coffeescript.org
*
* Copyright 2011, Jeremy Ashkenas
* Released under the MIT License
*/
(function(root){var CoffeeScript=function(){function require(t){return require[t]}return require["./helpers"]=new function(){var t=this;(function(){var e,n,i,r;t.starts=function(t,e,n){return e===t.substr(n,e.length)},t.ends=function(t,e,n){var i;return i=e.length,e===t.substr(t.length-i-(n||0),i)},t.compact=function(t){var e,n,i,r;for(r=[],n=0,i=t.length;i>n;n++)e=t[n],e&&r.push(e);return r},t.count=function(t,e){var n,i;if(n=i=0,!e.length)return 1/0;for(;i=1+t.indexOf(e,i);)n++;return n},t.merge=function(t,e){return n(n({},t),e)},n=t.extend=function(t,e){var n,i;for(n in e)i=e[n],t[n]=i;return t},t.flatten=i=function(t){var e,n,r,s;for(n=[],r=0,s=t.length;s>r;r++)e=t[r],e instanceof Array?n=n.concat(i(e)):n.push(e);return n},t.del=function(t,e){var n;return n=t[e],delete t[e],n},t.last=function(t,e){return t[t.length-(e||0)-1]},t.some=null!=(r=Array.prototype.some)?r:fun
@sbp
sbp / search.cgi
Created December 26, 2012 21:59
Swhack search service
#!/usr/bin/python
import sys, os, time, urllib, mmap
print 'Content-Type: text/plain; charset=utf-8'
print
query = os.environ['QUERY_STRING']
query = urllib.unquote(query)
now = time.time()
@sbp
sbp / contents.js
Created December 6, 2012 00:26
Table of Contents generation in JavaScript using jQuery
function contents() {
var first = $('h2:first');
if (!first) return;
var p = '<p><strong>Contents</strong>';
var ol = '<ol id="contents"></ol>';
first.before('<div class="contents">' + p + ol + '</div>');
var outer = $('#contents');
$('h2, h3, h4').map(function (i) {
@sbp
sbp / realm.py
Created August 28, 2012 15:55
Check Warcraft realm status, up or down
import re
import urllib
def status(name):
u = urllib.urlopen("http://www.mywowarmory.com/realmstatus.php")
bytes = u.read()
u.close()
search = re.search('(?i)(up|down).png[^>]*>' + name, bytes)
if search:
@sbp
sbp / selector.py
Created August 26, 2012 10:00
Use random.org to select an item
# Derived from http://pastebin.com/10egeE1a
# Original Copyright 2012, Paul
# License: Eiffel Forum License 2
import re, urllib
def randomorg(max):
svcurl = "http://www.random.org/integers/?num=1&min=1&max=%d&col=1&base=10&format=plain&rnd=new" % max
u = urllib.urlopen(svcurl)
content = u.read()
@sbp
sbp / irc.py
Created August 15, 2012 21:46
Bot sketch, intended for a phenny-like bot
import re
import socket
import threading
import queue
import multiprocessing
import time
import commands
class Client(object):
@sbp
sbp / services.py
Created August 14, 2012 15:46
Services sketch, intended for a phenny-like meta-service
# remote python execution
# wolfram alpha service
# remote services?
import re, urllib.request, urllib.parse, traceback
from html.entities import name2codepoint
def error(who, message):
output = {"who": who, "message": message}
stack = traceback.extract_stack()
@sbp
sbp / wikby.py
Created August 13, 2012 13:04
Get a list of Wikipedia articles near a location
#!/usr/bin/env python
import sys, re, urllib
from decimal import Decimal as dec
def error(message):
print message
sys.exit(1)
def parse_lat_lon_string(lat_lon):
@sbp
sbp / WhitsBot.py
Created August 4, 2012 17:37
WhitsBot
#!/usr/bin/env python
import sys, os.path, re, json, time, shutil, cgi
from htmlentitydefs import name2codepoint
sys.path.append(
os.path.expanduser("~/usr/opt/python-packages")
)
from twitter import Twitter, OAuth