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
""" | |
Wrapper client for the blink(1)control REST API. | |
Example Usage: | |
import blinky | |
b = Blinky() | |
b.on() # Let there be (white) light | |
# Have the first LED fade to #336699 over 10 seconds |
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
<html> | |
<head> | |
<meta http-equiv="refresh" content="60" /> | |
<!--link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" --> | |
<!-- link href="picwall.css" rel="stylesheet" /--> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.1/masonry.pkgd.min.js"></script> | |
<!--script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script--> | |
<!--script src="picwall.js"></script--> |
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
import os | |
import inspect | |
import logging | |
import unittest | |
from glob import glob | |
def locate_suites(test_dirname="tests", test_file_prefix="test_"): | |
""" | |
Recursively search the test_dirname directory for *.py files that starts | |
with test_file_prefix and returns all test suites found within them. |
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
import sys, math | |
p,t,w=map(int,sys.argv[1:]) # read input | |
grid = [[' ']*(w+1) for i in range(0,w+1)] # prepare grid | |
def plot(x,y): | |
"""plots point on grid""" | |
grid[int(round(x))][int(round(y))]='x' | |
def line (x0, y0, x1, y1): | |
"""draw line using bresenham's line algorithm""" |
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
// return data-* attributes of a node as a dict | |
function getDataAttributes(node) { | |
var vstr = $().jquery.split("."); | |
var v0 = parseInt(vstr[0]) || 0, | |
v1 = parseInt(vstr[1]) || 0, | |
v2 = parseInt(vstr[2]) || 0; | |
// jQuery >= 1.4.4 has built in op to do this. | |
if ( v0 > 1 || (v0 == 1 && v1 > 4) || (v0 == 1 && v1 == 4 && v2 >= 4)) { |
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 | |
# Description: a trie-based prefix matching utility | |
# Author: Shawn Chin (http://shawnchin.github.com) | |
# | |
# Usage: | |
# keys = ["BANANA", "APPLE", "DURIAN", "MANGO"] | |
# m = PrefixMatch(keys) | |
# m.add_key("ORANGE") # extend list of keys | |
# m.match("BANANA") # returns True (matches key) | |
# m.match("ORANGEBOY") # returns True (starts with key) |
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 | |
""" | |
Author: Shawn Chin (http://shawnchin.github.com) | |
Description: colorise output of `ls` based on svn status | |
Note: | |
This is a proof-of-concept implementation and only performs | |
a basic `ls` call in the current working directory. | |
""" |
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 | |
from datetime import timedelta | |
def time_delta(d1,d2): | |
""" | |
Returns time delta as the following tuple: | |
("before|after|same", "years", "months", "days") | |
""" | |
if d1 == d2: | |
return ("same",0,0,0) |
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
/* scroll page so obj is visible in current view with | |
* a _minimum_ bottom margin of "bottom_margin" (default:20). | |
* -- requires jQuery -- | |
*/ | |
function scroll_to(obj, bottom_margin, speed) { | |
bottom_margin = bottom_margin || 20; | |
var target_height = obj.height() + bottom_margin; | |
var visible_height = $(window).height(); | |
var scroll_top = obj.offset().top; | |
if (target_height < visible_height) { |
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 | |
import itertools | |
from dateutil import parser | |
jumpwords = set(parser.parserinfo.JUMP) | |
keywords = set(kw.lower() for kw in itertools.chain( | |
parser.parserinfo.UTCZONE, | |
parser.parserinfo.PERTAIN, | |
(x for s in parser.parserinfo.WEEKDAYS for x in s), | |
(x for s in parser.parserinfo.MONTHS for x in s), |
OlderNewer