Skip to content

Instantly share code, notes, and snippets.

View cls's full-sized avatar

Connor Lane Smith cls

View GitHub Profile
@cls
cls / utf8base64.c
Last active August 7, 2017 22:03
Print non-ASCII UTF-8 sequences' unique Base64 identifiers
#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 July 13, 2017 11:35
Script to extract certain fields from the Unicode Character Database
BEGIN { FS = ";"; OFS = ","; }
{ name = $2; }
name ~ /<.*>/ { name = $11; }
name { print $1, name, $3; }
@cls
cls / cartesian.hs
Created February 21, 2017 11:09
Cartesian product over lists
cartesian :: [[a]] -> [[a]]
cartesian [] = [[]]
cartesian (xs:zss) = [x:ys | x <- xs, ys <- cartesian zss]
@cls
cls / catalan.py
Created February 20, 2017 14:45
Calculating the Catalan number series
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 February 16, 2017 17:42
Repacking structs to minimise bit wastage
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 March 19, 2024 07:22
Python regular expression bytecode disassembler
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 / nmgrep.sh
Last active June 1, 2018 20:22
Script to grep objects' symbol tables
#!/bin/sh
pattern="$1"
shift
if [ $# -gt 1 ]
then
GREP_OPTIONS="$GREP_OPTIONS --with-filename"
export GREP_OPTIONS
fi
@cls
cls / mircrev.c
Last active February 28, 2021 00:18
Reversal of mIRC rich text (ASCII only)
#include <ctype.h>
#define BIT(X) (1 << (X))
#define CTRL(X) ((X) - '@')
enum { None = -1 };
enum {
Bold = CTRL('B'),
Colour = CTRL('C'),
@cls
cls / intern.c
Last active August 29, 2015 14:23
Interning strings with a prefix tree
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *
intern(const char *s)
{
union tree {
const char *str;
@cls
cls / CovariantIterator.java
Last active August 29, 2015 14:17
Adaptor for covariant iterators in Java
import java.util.Iterator;
public class CovariantIterator<T extends U, U> implements Iterator<U>
{
private Iterator<T> iter;
public CovariantIterator(Iterator<T> it)
{
this.iter = it;
}