Skip to content

Instantly share code, notes, and snippets.

class VectorWrapperBase {
public:
virtual ~VectorWrapperBase() {}
virtual void reserve(unsigned int n) = 0;
};
template <typename T>
class VectorWrapper: public VectorWrapperBase {
public:
typedef T data_type;
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>()));
@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!)
@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 / 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 / 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 / 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 / shmemctypes.py
Created September 16, 2011 15:09
shm_open() version of multiprocessing.sharedctypes.RawArray
#
# Based on multiprocessing.sharedctypes.RawArray
#
# Uses posix_ipc (http://semanchuk.com/philip/posix_ipc/) to allow shared ctypes arrays
# among unrelated processors
#
# Usage Notes:
# * The first two args (typecode_or_type and size_or_initializer) should work the same as with RawArray.
# * The shared array is accessible by any process, as long as tag matches.
# * The shared memory segment is unlinked when the origin array (that returned
#!/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),
/* 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) {