Skip to content

Instantly share code, notes, and snippets.

View timtrueman's full-sized avatar

Tim Trueman timtrueman

View GitHub Profile
<script id="uniqueId" type="text/javascript">
(function() {
// Code you want to execute here
})();
</script>
<img src="spacer.gif"
onload="eval(document.getElementById('uniqueId').innerHTML);">
sudo dd bs=1024 if=/Volumes/Drobo/ubuntu-9.04-desktop-amd64.iso of=/dev/disk3
#!/usr/bin/python
#encoding:utf-8
import stompy
import time
import curses
def monitor_stompserver():
try:
myscreen = curses.initscr()
def update_elo_score(k=32, defender_rating=1000, attacker_rating=1000, attacker_won=False):
q_a = 10**(defender_rating/400.0)
q_b = 10**(attacker_rating/400.0)
expected_defender_score = q_a / float(q_a + q_b)
expected_attacker_score = q_b / float(q_b + q_a)
print "Expected chance of winning, defender %0.1f%%, attacker %0.1f%%" % (expected_defender_score*100, expected_attacker_score*100)
if attacker_won:
updated_defender_rating = defender_rating + int(k * (0 - expected_defender_score))
updated_attacker_rating = attacker_rating + int(k * (1 - expected_attacker_score))
else:
@timtrueman
timtrueman / gist:296560
Created February 6, 2010 05:32
Takes a body of text and truncates full urls into domain + tld
def truncate_urls_to_domain_plus_tld(text):
"""
Get all the urls
Find the domain + tld
Find and replace each url found with its domain + tld
"""
match_urls = re.compile(r'\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^%s\s]|/)))')
break_down_url = re.compile(r'^((?P<scheme>https?|ftp):\/)?\/?((?P<username>.*?)(:(?P<password>.*?)|)@)?(?P<hostname>[^:\/\s]+)(?P<port>:([^\/]*))?(?P<path>(\/\w+)*\/)(?P<filename>[-\w.]+[^#?\s]*)?(?P<query>\?([^#]*))?(?P<fragment>#(.*))?$')
urls = match_urls.findall(text)
for url in urls:
@timtrueman
timtrueman / curses_print_numpy_matrix.py
Created February 9, 2010 05:16
Python — Use the curses library to display a numpy matrix in a pretty manner
def display_matrix(screen, m, x, y, precision=2, title=None):
rows, cols = m.shape
if title:
screen.addstr(x, y, title)
x += 1
screen.addstr(x, y, "[")
screen.addstr(x, cols*(4+precision)+y+1, "]")
screen.addstr(rows+x-1, y, "[")
screen.addstr(rows+x-1, cols*(4+precision)+y+1, "]")
for row in range(rows):
#!/usr/bin/env python
# encoding: utf-8
import sys
import socket
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from struct import unpack_from
from math import cos, sin, tan, atan, isnan, pi, degrees, radians, sqrt
from numpy import matrix
#!/usr/bin/env python
# encoding: utf-8
import serial
import sys
#set up the serial port for action
#originally from http://dmt195.wordpress.com/2009/01/19/python-to-interface-with-the-pololu-8-channel-servo-controller/
ser=serial.Serial(port='/dev/tty.Pololu', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1)
#!/usr/bin/python
#encoding:utf-8
import stompy
import time
import curses
def monitor_stompserver():
try:
myscreen = curses.initscr()
#!/usr/bin/python
#encoding:utf-8
from telnetlib import Telnet
import time
import sys
"""
Usage