This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrap(angle): | |
if angle > pi: | |
angle -= (2*pi) | |
if angle < -pi: | |
angle += (2*pi) | |
if angle < 0: | |
angle += 2*pi | |
return angle | |
def magnetometer_readings_to_tilt_compensated_heading(bx, by, bz, phi, theta): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#encoding:utf-8 | |
import stompy | |
import time | |
import curses | |
def monitor_stompserver(): | |
try: | |
myscreen = curses.initscr() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import socket | |
from struct import * | |
from twisted.internet.protocol import DatagramProtocol | |
from twisted.internet import reactor | |
import math | |
UDP_IP="127.0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo dd bs=1024 if=/Volumes/Drobo/ubuntu-9.04-desktop-amd64.iso of=/dev/disk3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script id="uniqueId" type="text/javascript"> | |
(function() { | |
// Code you want to execute here | |
})(); | |
</script> | |
<img src="spacer.gif" | |
onload="eval(document.getElementById('uniqueId').innerHTML);"> |
NewerOlder