Skip to content

Instantly share code, notes, and snippets.

View cwvh's full-sized avatar

Chris Van Horne cwvh

  • Seattle, WA, USA
View GitHub Profile
@cwvh
cwvh / foo.py
Created December 11, 2011 21:47
from pipeline import pipeline
@pipeline()
def foo():
pass
@pipeline()
def baz():
pass
@cwvh
cwvh / gist:1495096
Created December 19, 2011 01:55
stash
@pattern(r'^([a-zA-Z_\$\%][a-zA-Z_0-9\{\}]*)\s*:(?<=:)(?::([a-zA-Z_\$][a-zA-Z_0-9\{\}]*)?:)?\s*(.*)$')
def target(match, env=env):
labels = ('name', 'dep', 'components')
groups = dict(zip(labels, match.groups()))
for k, v in groups.iteritems():
groups[k] = env.interp(v) if v else v
name, dep = groups['name'], groups['dep']
components = re.findall('\w+', groups['components'])
makefile.addtarget(name, dep, components)
#!/usr/bin/env bash
# $ gostart x
# vim x.go
FILENAME="$1"
cp "$GOROOT"/doc/Makefile .
sed -i '' -e "s/tmpltohtml/"$FILENAME"/g" -e 's/\.\./$\(GOROOT\)/' -e '/^#.*/d' Makefile
touch "$1".go
class Comonad w where
(=>>) :: w a -> (w a -> b) -> w b
extract :: w a -> a
data T a = L a | B (T a) a (T a) deriving (Eq, Show)
unit :: a -> T a
unit = L
counit :: T a -> a
#include <exception>
#include <future>
#include <thread>
#include <tbb/concurrent_queue.h>
namespace {
template<typename Future, typename F, typename T>
void set_value(std::promise<Future>& p, F& f, T& t) {
p.set_value(f(t));
}
@cwvh
cwvh / x.cpp
Created May 26, 2013 04:42
parallel features of C++11
#include <iostream>
#include <future>
#include <vector>
#include <algorithm>
#include <numeric>
#include <chrono>
template<typename Ran>
int parallel_sum(Ran b, Ran e)
{
@cwvh
cwvh / x.c
Created September 2, 2013 03:29
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ccan/list/list.h>
struct context {
struct list_head connections;
int num_connections;
};
@cwvh
cwvh / .ghci
Last active December 23, 2015 15:39
Read header comment on how to setup.
{-
Place contents of this file in $HOME/.ghci then run
$ cabal install -j2 hoogle
$ hoogle data
-}
let ghciEscapeShellArg arg = "'" ++ concatMap (\c -> if c == '\'' then "'\"'\"'" else [c]) arg ++ "'"
:def! h return . (":! hoogle --color --count=20 " ++) . ghciEscapeShellArg
stack = []
for line in sys.stdin:
dec = int('0b' + line, 2)
signed = struct.unpack('=l', struct.pack('=L', dec & 0xffffffff))[0]
stack.append(signed)
00000000000000000000000000000000
01000000000000000000000000011000
01100000000000000000000000011010
01000000000000000000000000011010
01100000000000000000000000011011
01000000000000000000000000010111
10000000000000000000000000011011
11000000000000000000000000000000
00100000000000000000000000010100
10000000000000000000000000011010