Skip to content

Instantly share code, notes, and snippets.

@shawnchin
shawnchin / blinky.py
Last active Aug 29, 2015
Quick REST Client Wrapper, and an example wrapper for the blink(1)control REST API
View blinky.py
"""
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
@shawnchin
shawnchin / twistedweb_resource_wrapper.py
Created Jun 3, 2013
Wrapper for twisted.web.resource to apply basic authentication using a dict of usernames/passwords.
View twistedweb_resource_wrapper.py
from zope.interface import implements
from twisted.internet.defer import succeed, fail
from twisted.cred.error import UnauthorizedLogin
from twisted.cred.credentials import IUsernamePassword
from twisted.cred.checkers import ICredentialsChecker
from twisted.cred.portal import IRealm, Portal
from twisted.web.resource import IResource
from twisted.web.guard import BasicCredentialFactory, HTTPAuthSessionWrapper
from twisted.web.static import File
@shawnchin
shawnchin / testcode_buildbot.py
Last active Aug 5, 2020
Buildbot BuildSlave for testcode2
View testcode_buildbot.py
"""
Buildbot BuildStep that runs and parses the output of testcode2.
Copyright (c) 2013 Shawn Chin
This sofware is released under the BSD 3-Clause License
"""
import re
from itertools import chain
from collections import defaultdict
from buildbot.steps.shell import ShellCommand
@shawnchin
shawnchin / pygment_fortran_lexer.py
Last active Dec 14, 2015
Alternative PythonLexer for pygments that attempts to address other Fortran standards (not just Fortran 90).
View pygment_fortran_lexer.py
# Description: Alternative Fortran Lexer for pygments that
# attempts to address other Fortran standards (not just
# Fortran 90 as provided by the official lexer).
#
# Author: Shawn Chin
# Homepage: https://gist.github.com/shawnchin/5031105
#
import re
View gist:4474813
Index: flame2/api/Makefile.am
===================================================================
--- flame2/api/Makefile.am (revision 977)
+++ flame2/api/Makefile.am (working copy)
@@ -15,7 +15,9 @@
# Note: flame2.h is installed by the master Makefile.am
-module_sources =
+# compile dummy file so "ar" on OSX does not choke on empty archive
@shawnchin
shawnchin / using_kdtree.c
Created Jul 12, 2012
Usage example of kd3
View using_kdtree.c
#include "kd3/kdtree.h"
void some_function(void) {
double *x, *y, *z; /* array of points */
size_t i, j; /* loop indices */
x = malloc(sizeof(double) * SIZE);
y = malloc(sizeof(double) * SIZE);
z = malloc(sizeof(double) * SIZE);
@shawnchin
shawnchin / gist:3082329
Created Jul 10, 2012
pseudocode of answer for SO question 11409942
View gist:3082329
# http://stackoverflow.com/questions/11409942/function-subseq-python-need-thoughts
function is_sub(s1, s2):
let L1 be the length of s1 and L2 the length of s2
1. if L2 > L1, s2 is definitely not a subset of s1, so return False
2. if the first L2 elements in s1 equals to s2, then s2 is a subset. return True.
3. otherwise, make a recusive call to determine if s2 is a subset of s1[1:] and return the result.
p.s. You might find the slice notation useful. See http://stackoverflow.com/a/509295/115845
View vector_wrapper.hpp
class VectorWrapperBase {
public:
virtual ~VectorWrapperBase() {}
virtual void reserve(unsigned int n) = 0;
virtual VectorWrapperBase* clone() const = 0;
};
inline VectorWrapperBase* new_clone(const VectorWrapperBase& a) {
return a.clone();
}
View vector_wrapper.hpp
class VectorWrapperBase {
public:
virtual ~VectorWrapperBase() {}
virtual void reserve(unsigned int n) = 0;
};
template <typename T>
class VectorWrapper: public VectorWrapperBase {
public:
typedef T data_type;