Skip to content

Instantly share code, notes, and snippets.

@badp
badp / ligaturify.py
Created June 21, 2010 07:35
Put ligatures where possible. Save characters.
#/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
if sys.version_info < (3,):
raise Exception("This requires Python 3 to run. Sorry.")
ligatures = { "db": "ȸ",
"AE": "Æ",
"ae": "æ",
@badp
badp / trueskill.py
Created June 21, 2010 07:41
An iffy, unaccurate, limited trueskill implementation of TrueSkill in Python.
from math import *
from math import pi as π
from pprint import pprint
games = [
("PK", "SF"), ("RT", "XT"), ("ACE", "BS"), ("SRM", "GB"), #day 1
("SysX", "XT"), ("PK", "RT"), ("SF", "GB"), ("SRM", "BS"), #day 2
("SysX", "GB"), ("RT", "BS"), ("SF", "SRM"), ("XT", "ACE"), #day 3
("SysX", "PK"), ("RT", "SF"), ("XT", "BS"), ("GB", "SRM"), #day 4
("SysX", "RT"), ("PK", "ACE"), ("XT", "SF"), ("BS", "GB"), #day 5
@badp
badp / pastebin.py
Created June 24, 2010 09:07
Quick and dirty pastebin interface in Pyhton
import urllib
valid_expiration_values = ('N', '10M', '1H', '1D', '1M')
def postToPastebin( message,
title = "RTBot",
subdomain = "rtbot",
expire_date = "1D",
format = "text"):
@badp
badp / isgd.py
Created June 24, 2010 09:32
Quick and dirty is.gd interface in Python
import urllib
def isgd(url):
request_dict = {"longurl": url}
request = urllib.urlencode(request_dict)
result = urllib.urlopen("http://is.gd/api.php?" + request)
if result.getcode() == 500:
raise ValueError(result.read())
else:
return result.read()
@badp
badp / mockup.xml
Created September 9, 2010 08:28
SO Close dialog with additional migration step
<mockup version="1.0" skin="sketch" measuredW="568" measuredH="1453" mockupW="514" mockupH="1402">
<controls>
<control controlID="13" controlTypeID="com.balsamiq.mockups::Canvas" x="44" y="41" w="461" h="504" measuredW="100" measuredH="70" zOrder="0" locked="false" isInGroup="-1"/>
<control controlID="14" controlTypeID="com.balsamiq.mockups::Label" x="60" y="51" w="-1" h="-1" measuredW="330" measuredH="25" zOrder="1" locked="false" isInGroup="-1">
<controlProperties>
<bold>true</bold>
<size>16</size>
<text>Why%20should%20this%20question%20be%20closed%3F</text>
</controlProperties>
</control>
<mockup version="1.0" skin="sketch" measuredW="507" measuredH="529" mockupW="343" mockupH="519">
<controls>
<control controlID="298" controlTypeID="com.balsamiq.mockups::Canvas" x="165" y="35" w="322" h="63" measuredW="100" measuredH="70" zOrder="0" locked="false" isInGroup="-1">
<controlProperties>
<color>13421772</color>
</controlProperties>
</control>
<control controlID="299" controlTypeID="com.balsamiq.mockups::Label" x="306" y="51" w="-1" h="-1" measuredW="39" measuredH="29" zOrder="1" locked="false" isInGroup="-1">
<controlProperties>
<size>16</size>
/* bonus: die Tahoma die! */
a.question-hyperlink,
a.answer-hyperlink,
table.history-table a.question-hyperlink,
table.history-table a.answer-hyperlink,
#question-suggestions a.question-hyperlink,
#questions a.question-hyperlink,
table.summary-table a.question-hyperlink,
table.summary-table a.answer-hyperlink,
$.fn.each2 = function(callback)
{
for ( var i = 0; i < this.length; ++i ) {
jQueryObj = this.eq(i)
if( callback.call( jQueryObj, i, jQueryObj) === false){
break;
}
}
};
@badp
badp / spam.py
Created November 11, 2010 14:19
Send a message to all users on a system. Depends on the `libnotify-bin` package.
We couldn’t find that file to show.