Skip to content

Instantly share code, notes, and snippets.

@shawnchin
shawnchin / complex.h
Created October 26, 2011 13:37
Dummy complex.h to allow splint to work
/*
Dummy header file for complex.h
This file suppresses the relevant keywords and replaces constants/functions
with dummy ones so splint doesn't choke.
Keywords derived from :
http://pubs.opengroup.org/onlinepubs/009604499/basedefs/complex.h.html
*/
@shawnchin
shawnchin / base.py
Created November 23, 2011 13:48
quick hack to make template name available to tags
from __future__ import absolute_import
import re
from functools import partial
from inspect import getargspec
from django.conf import settings
from django.template.context import (Context, RequestContext,
ContextPopException)
from django.utils.importlib import import_module
@shawnchin
shawnchin / path_prefix.py
Created January 13, 2012 17:16
Trie-based path prefix matching
class PathPrefixMatch(object):
"""
Trie-based path prefix mathching utility
Usage:
path_prefixes = ("/hello/world/", "/test/")
p = PathPrefixMatch(path_prefixes)
p.add_path("/test2") # add another path
p.match("/test2/drive/x.txt") # returns "/test2"
@shawnchin
shawnchin / circles_v3_mock.xml
Created January 31, 2012 10:52
Mockup of XMMLv3
<flame_model version="3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation='http://flame.ac.uk/schema/xmml_v3.xsd'>
<model_name>Circles</model_name>
<model_version>02</model_version>
<model_description>...</model_description>
<environment>
<variable type="double" name="width" />
<variable type="double" name="height" />
@shawnchin
shawnchin / GForgeCodeSyntaxHighlight.user.js
Created April 16, 2012 16:47
UserScript to load SyntaxHighlighter on-demand within the CCPForge CVS/SVN code browser
// ==UserScript==
// @name GForge SCM Syntax Highlighter
// @version 1.1.1
// @namespace http://shawnchin.github.com
// @description Provides syntax highlighting for CVS/SVN/Git Code Viewer
// @include http://*/gf/project/*/scm*/?action=browse&*view=markup*
// @include http://*/gf/project/*/scmgit/*;a=blob;*
// ==/UserScript==
// Note that GForge already loads jQuery (a rather old version!)
typedef std::map<std::string, boost::any> VectorMap;
typedef std::pair<std::string, boost::any> VectorMapValue;
class VectorStore {
public:
template <typename T>
void RegisterVec(std::string vec_name) {
std::pair<VectorMap::iterator, bool> ret;
ret = map_.insert(VectorMapValue(vec_name, std::vector<T>()));
class VectorWrapperBase {
public:
virtual ~VectorWrapperBase() {}
virtual void reserve(unsigned int n) = 0;
};
template <typename T>
class VectorWrapper: public VectorWrapperBase {
public:
typedef T data_type;
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();
}
@shawnchin
shawnchin / gist:3082329
Created July 10, 2012 09:41
pseudocode of answer for SO question 11409942
# 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
@shawnchin
shawnchin / using_kdtree.c
Created July 12, 2012 12:07
Usage example of kd3
#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);