Skip to content

Instantly share code, notes, and snippets.

@sbp
sbp / cpulimit.py
Created December 17, 2011 16:17 — forked from anonymous/cpulimit.py
reduce the cpu time of a process by pausing and resuming it repeatedly
#!/usr/bin/env python
import time, os, sys, signal
sleeptime = waketime = 0.01
def send(signal, pids):
for pid in pids:
os.kill(pid, signal)
@sbp
sbp / gists.py
Created December 10, 2011 12:04
Download all of a user's gists
#!/usr/bin/env python
import sys, os, urllib, json
user = sys.argv[1]
u = urllib.urlopen('http://gist.github.com/api/v1/json/gists/' + user)
bytes = u.read()
u.close()
gistdir = user + '-gists'
@sbp
sbp / moonphase.py
Created December 9, 2011 22:15
Phase of the moon
#!/usr/bin/env python
# http://en.wikipedia.org/wiki/Lunar_phase#Calculating_phase
import math, decimal, datetime
dec = decimal.Decimal
def position(now=None):
if now is None:
now = datetime.datetime.now()
@sbp
sbp / google-chrome-advert.txt
Created November 24, 2011 20:57
Google Chrome advert
<div id="notification-container" class="">
<div id="notification">
<span><a href="http://www.google.com/chromebook/index.html#utm_campaign=en&amp;utm_source=en-ntp-holidays-na-us-bkws&amp;utm_medium=ntp-holidays">Get a Chromebook for the holidays</a>: the computer powered by Chrome.</span>
<div id="notificationLinks"></div>
<button class="close-button"></button>
</div>
</div>
@sbp
sbp / en-phoneme-frequencies.txt
Created November 16, 2011 13:24
Frequency table of English phonemes
773 ɪ
750 ə
547 n
489 t
480 ː
393 d
334 s
327 a
304 l
296 e
@sbp
sbp / text.js
Created October 2, 2011 10:50
Add paragraphs and style to HTML
(function() {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = 'style.css';
document.head.appendChild(link);
})();
window.onload = function() {
document.body.innerHTML = document.body.innerHTML
.replace(/\n\n/g, '<p>')
@sbp
sbp / avocet.py
Created September 1, 2011 15:19
Emphasis style hypertext, lightweight format script
import re
p_emphasis = ur'(?<!\\)\*(.+?)\*'
p_paragraph = ur'\A(?=\S)|(?<=\A\n)(?=\S)|(?<=\n\n)(?=\S)'
p_link = ur'(?s)(?<!\\)\*([^*]+)\*(\W?)(?:[^\S\n]+|\n(?!\n))+(\S*[./]\S+)'
r_link = re.compile(p_link)
r_emphasis = re.compile(p_emphasis)
r_paragraph = re.compile(p_paragraph)
@sbp
sbp / logs.cgi
Created August 27, 2011 20:13
Swhack logs script
#!/usr/bin/env python
import cgitb
cgitb.enable()
import sys, os, re, glob, datetime
def utf8ize(s):
nuggets = []
for nugget in s.split(' '):
@sbp
sbp / jquery.paginator.js
Created August 20, 2011 11:23
jQuery Paginator script
/*!
* jQuery Paginator v1.0 - 20 Aug 2011
* Copyright 2011 Sean B. Palmer, Apache License 2.0
* http://sbp.so/paginator
*/
$(function () {
var body = $('body');
var content = false;
@sbp
sbp / example.html
Created August 18, 2011 21:03
Pages snippet for getting the pygments colours
<html>
<head>…</head>
<body>
<h1>…</h1>
<p id="summary">…</p>
<section id="content">…</section>
</body>
</html>