Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import ID3, os
for fname in [ x for x in os.listdir(".") if x.lower().endswith(".mp3") ]:
print "handling: %s" % fname
tag = ID3.ID3(fname)
new_name = "%0.2d %s.mp3" % (tag.track, tag.title)
if fname and tag and new_name:
os.rename(fname, new_name)
for i in range(ord('a'), ord('z')):
print "{0:d}\t{0:b}".format(i)
@bensonk
bensonk / coords.rb
Created September 6, 2011 03:16
Coordinate auto-splitting
class Search < MongoObject
def coords=(x)
if String === x
super(x.split(","))
else
super(x)
end
end
end
public class SampleSingleton {
private static SampleSingleton instance;
private SampleSingleton() {
instance = this;
}
public static synchronized SampleSingleton getInstance() {
if(instance)
return instance;
else
return new SampleSingleton();
class HashTable(object):
def __init__(self, size=100):
self.data = [ list() for x in range(size) ]
def add(self, key, item):
l = self.data[hash(key)]
for i, tup in enumerate(l):
if tup[0] == key:
del l[i]
break
@bensonk
bensonk / bin_to_ascii.py
Created September 13, 2011 01:08
Ascii binary decoder
#!/usr/bin/env python
def chunk(s):
if s == "": return []
elif len(s) < 8: return [s]
else: return [s[:8]] + chunk(s[8:])
def decode(bin):
chars = [ chr(int(x, 2)) for x in chunk(bin) ]
return "".join(chars)
<html>
<head>
<title>Color Tests</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
// Do Awesome Things With Colors!
function makeColor(index) {
function color(i) {
// Wrap around using modulus
add_index "locations", ["accuracy"], :name => "index_locations_on_accuracy"
add_index "locations", ["altitude"], :name => "index_locations_on_altitude"
add_index "locations", ["latitude"], :name => "index_locations_on_latitude"
add_index "locations", ["longitude"], :name => "index_locations_on_longitude"
add_index "locations", ["recorded_at"], :name => "index_locations_on_recorded_at"
add_index "locations", ["user_id"], :name => "index_locations_on_user_id"
#define cycleTime 150
void setup() {
for(int i = 2; i < 13; i++)
pinMode(i, OUTPUT);
}
void usePin(int pin) {
for(int i = 2; i < 13; i++)
digitalWrite(i, LOW);
@bensonk
bensonk / quadtree.py
Created October 12, 2011 00:49
Something like a QuadTree for space partitioning
#!/usr/bin/env python
class TreeNode(object):
def __init__(self, parent, x_min, y_min, x_max, y_max, items = []):
(self.x_min, self.y_min) = (x_min, y_min)
(self.x_max, self.y_max) = (x_max, y_max)
self.x_mid = (x_min + x_max) / 2
self.y_mid = (y_min + y_max) / 2