Skip to content

Instantly share code, notes, and snippets.

View skyl's full-sized avatar

Skylar Saveland skyl

View GitHub Profile
@skyl
skyl / gist:1359979
Created November 12, 2011 03:15
multidimensional k-means cluster finder in python
import math
import random
class ClusterCenters(object):
"""
>> d = ((0,0,0), (0,1,0), (0, 2, 0), (1,2,0), (55, 55,50), (50,50,50), (-100,-100,-100), (-80,-80,-100), (60,60,50))
>> cc = ClusterCenters(d, 3)
[[55, 55, 50], [0, 1, 0], [-90, -90, -100]]
>> cc = ClusterCenters(d, 2)
@skyl
skyl / tcp_client.py
Created May 1, 2011 06:00
slut tcp_client.py
(tut)skyl@skylarwerk:~/Code/gui/slut$ python tcp_client.py
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted/internet/_sslverify.py:5: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import itertools, md5
You are running [slut v0.9.0] happy hacking!
2011-05-01 01:57:45.984 python[79813:903] *** __NSAutoreleaseNoPool(): Object 0x1014e3d50 of class NSCFData autoreleased with no pool in place - just leaking
fCoreAudioDriverUID AppleHDAEngineInput:1B,0,1,0:1
Enabled joystick: OSCulator HID 1
Enabled joystick: OSCulator HID 2
-> Default interaction model loaded.
[F11] -> toggle fullscreen
@skyl
skyl / gist:866920
Created March 12, 2011 01:30
shruti system
In [35]: shrutis = {
....: 0: (1/Decimal('1'),),
....: 1: (256/Decimal('243'), 16/Decimal('15')),
....: 2: (10/Decimal('9'), 9/Decimal('8')),
....: 3: (32/Decimal('27'), 6/Decimal('5')),
....: 4: (5/Decimal('4'), 81/Decimal('64')),
....: 5: (4/Decimal('3'),),
....: # 27/Decimal('20'),
....: 6: (45/Decimal('32'), 729/Decimal('512')),
....: 7: (3/Decimal('2'),),
@skyl
skyl / gist:849500
Created March 1, 2011 17:20
stashing a mediocre idea
import djredis.models as djr
class MyMod(models.Model, djr.DredisMixin):
#...
currency = models.CharField(max_length=3)
djr_currency = djr.String()
cache_fields = (('currency', 'djr_currency'),)
@skyl
skyl / gist:778973
Created January 14, 2011 01:10
rough openlayers example
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>
Example Site : Welcome
</title>
@transaction.commit_on_success
def _action(action, o):
getattr(o,action)()
o.is_processing = False
o.save()
def _bulk_action(action, objs):
for o in objs:
_action(action,o)
@skyl
skyl / gist:764182
Created January 3, 2011 23:41
TxBl api sample
v1 = Stepper(
[60,30,30,30,50,N] * 2 + [120,40,40,120,40,40] * 2
)
n1 = snd(cycle(
[R(60,48)]
))
d1 = rhodes_f()
player1 = Player(d1, n1, v1, interval=sixteenth)
player1.startPlaying()
from django import db
from django.db import connection
from django.conf import settings
class LoggingMiddleware(object):
def process_request(self, request):
"""Logs the POST (and resets the queries if DEBUG)"""
@skyl
skyl / Tomjunk
Created June 7, 2010 18:17 — forked from anonymous/Tomjunk
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
@skyl
skyl / gist:423540
Created June 3, 2010 06:06
djongobjomposition
from django.db import models
from mymongo.models import Mongo
class M(models.Model):
...
mongo = Mongo()