Skip to content

Instantly share code, notes, and snippets.

Connor Lane Smith cls

  • Oxford Nanopore
  • Berkshire, UK
Block or report user

Report or block cls

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cls
cls / functional-templates.hpp
Last active Mar 9, 2018
Type-level linked lists, with map, filter, and foldr
View functional-templates.hpp
#include <type_traits>
namespace type_list {
class nil {};
template<class Head, class Tail>
class cons {};
// map f [] = []
@cls
cls / suffix-array.c
Last active Dec 30, 2017
Constructing a simple suffix array
View suffix-array.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int pstrcmp(const void *, const void *);
int
main(void)
{
char buf[BUFSIZ];
@cls
cls / debruijn.hs
Last active Oct 21, 2017
Untyped lambda calculus with De Bruijn indices as a nested data type
View debruijn.hs
import Control.Applicative (liftA2)
data Term a = App (Term a) (Term a)
| Lam (Term (Maybe a))
| Var a
instance Functor Term where
fmap f (App s t) = App (fmap f s) (fmap f t)
fmap f (Lam t) = Lam (fmap (fmap f) t)
fmap f (Var x) = Var (f x)
@cls
cls / utf8base64.c
Last active Aug 7, 2017
Print non-ASCII UTF-8 sequences' unique Base64 identifiers
View utf8base64.c
#include <stdio.h>
const char clo[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6,
};
const char b64[64] = {
@cls
cls / ucd.awk
Last active Jul 13, 2017
Script to extract certain fields from the Unicode Character Database
View ucd.awk
BEGIN { FS = ";"; OFS = ","; }
{ name = $2; }
name ~ /<.*>/ { name = $11; }
name { print $1, name, $3; }
@cls
cls / cartesian.hs
Created Feb 21, 2017
Cartesian product over lists
View cartesian.hs
cartesian :: [[a]] -> [[a]]
cartesian [] = [[]]
cartesian (xs:zss) = [x:ys | x <- xs, ys <- cartesian zss]
@cls
cls / catalan.py
Created Feb 20, 2017
Calculating the Catalan number series
View catalan.py
from fractions import Fraction
def catalan(n):
c = 1
for k in range(2, n + 1):
c *= Fraction(n + k, k)
return int(c)
@cls
cls / repack.py
Last active Feb 16, 2017
Repacking structs to minimise bit wastage
View repack.py
from queue import PriorityQueue
class Field:
def __init__(self, size, align):
self.size = size
self.align = align
class Struct:
def __init__(self, fields):
size = 0
@cls
cls / dissre.py
Last active Feb 10, 2017
Python regular expression bytecode disassembler
View dissre.py
import re
import sre_compile
import sre_parse
from sre_constants import *
opcodes = dict((v,k) for (k,v) in OPCODES.items())
atcodes = dict((v,k) for (k,v) in ATCODES.items())
chcodes = dict((v,k) for (k,v) in CHCODES.items())
def print_dis(s, indent):
@cls
cls / next.sh
Last active May 27, 2016
Script to execute the next binary along in $PATH
View next.sh
#!/bin/sh
dir=${1%/*}
bin=${1##*/}
shift
unset flag
set -f
IFS=:
You can’t perform that action at this time.