Skip to content

Instantly share code, notes, and snippets.

Avatar

Skylar Saveland skyl

View GitHub Profile
@skyl
skyl / defaultdikt.py
Created Apr 27, 2012
defaultdict musical score scratchpad idea
View defaultdikt.py
"""
1 2 3 4
tekaTa Ta Ka tktkTA
16 16 8 4 4 32 32 32 32 8
0 6 12 24 48 72 75 78 81 84
"""
@skyl
skyl / isSubSet.js
Created Apr 26, 2012
Javascript array, is Sub Set
View isSubSet.js
isSubSet = function(ar1, ar2) {
// Test if ar1 is a subset of ar2
ar1 = _.uniq(ar1);
ar2 = _.uniq(ar2);
if (ar1.length > ar2.length) {
return false;
}
_.each(ar1, function(el){
if (ar2.indexOf(el) === -1){
return false;
@skyl
skyl / gist:1961812
Created Mar 2, 2012
Which is actually cleaner? (django templates)
View gist:1961812
{% exec %}
try:
f = durs[duration]
f.field.widget.attrs['placeholder'] = duration
print f
except KeyError:
pass
{% endexec %}
OR
@skyl
skyl / linkify.coffee
Created Feb 22, 2012
linkify phone numbers in coffeescript
View linkify.coffee
s = """
Extensions are not supported.
Alphabetic phonenumbers eg 1888-FOR-RILZ are not supported.
Of course, you'll want to prevent injection by stripping html tags first.
It switches the numbers to international format (or sth) - suggestions welcome!
706 555 5001put some
ill formed(404) 555-1397text in here
+34712938479 to make it interesting...5
404.555.1239.
@skyl
skyl / kwacros.py
Created Feb 1, 2012
Django Template macros with args and kwargs
View kwacros.py
#
# templatetags/kwacros.py - Support for macros in Django templates
#
# Based on snippet by
# Author: Michal Ludvig <michal@logix.cz>
# http://www.logix.cz/michal
#
# modified for args and kwargs by Skylar Saveland http://skyl.org
#
@skyl
skyl / gist:1531186
Created Dec 29, 2011
Fill varnish with requests
View gist:1531186
import urllib
import requests
exposure_liability_map = {
"people": [
#("RESDQ", "All residents Day"),
("RESNQ", "Night Residents"),
("RESFDQ", "Female residents Day"),
("RESN4Q", "Night residents < 4yo"),
],
@skyl
skyl / gist:1422095
Created Dec 2, 2011
canvas img linear filter in coffeescript
View gist:1422095
minmax = (value, low, high) -> Math.min Math.max(low, value), high
class ImageProcessor
constructor: (@img, parent=document.body) ->
@canvas = document.createElement("canvas")
@context = @canvas.getContext("2d")
@canvas.width = @img.width
@canvas.height = @img.height
parent.appendChild @canvas
@skyl
skyl / gist:1410323
Created Nov 30, 2011
Python order of operations gotcha
View gist:1410323
In [61]: l
Out[61]: [1, 2, 3, False]
In [62]: i
Out[62]: 1
In [63]: not i in l
Out[63]: False
In [64]: (not i) in l
@skyl
skyl / gist:1359979
Created Nov 12, 2011
multidimensional k-means cluster finder in python
View gist:1359979
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
slut tcp_client.py
View 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
You can’t perform that action at this time.