Skip to content

Instantly share code, notes, and snippets.

@courtc
courtc / cache.h
Last active Feb 1, 2018
caching api
View cache.h
#ifndef _CACHE_H_
#define _CACHE_H_
#include "node.h"
struct cache_item {
void (* release)(struct cache_item *);
struct node mi;
struct node li;
};
@courtc
courtc / init.c
Created Nov 18, 2017
libc init example
View init.c
/*
* Copyright (c) 2010, Courtney Cavin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
@courtc
courtc / class_static_wrapper.py
Created Mar 10, 2017
Class static method variable decorator
View class_static_wrapper.py
from functools import wraps
def class_static_vars(**kwargs):
def decorator(fn):
@wraps(fn)
def wrap(*args):
if not wrap._done:
method = getattr(args[0], fn.__name__)
for k in kwargs:
setattr(method.__func__, k, kwargs[k])
@courtc
courtc / simplefreq.cpp
Last active Dec 8, 2015
Simple frequency detection
View simplefreq.cpp
/*
* Copyright (c) 2015, Courtney Cavin
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
@courtc
courtc / vpy
Created Apr 24, 2015
Virtualenv for Python: Yuck
View vpy
#!/bin/bash -e
#
# Stay off my lawn
#
# I refuse to source scripts, so this is my way of dealing with virtualenv.
#
# Basically the idea here is that I mess up my own personal environment so that
# this script runs in place of python. With that I load the proper environment
# based on the python script being run. Environment mapping is based on the
# canonical file path of each script.
View keybase.md

Keybase proof

I hereby claim:

  • I am courtc on github.
  • I am courtc (https://keybase.io/courtc) on keybase.
  • I have a public key whose fingerprint is 45F0 0BA6 FF74 8BDF 0AC3 F093 23AE 6A8E FA0D 18B8

To claim this, I am signing this object:

@courtc
courtc / example.c
Last active Jun 30, 2016
HSM, simplified
View example.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hsm.h"
#define container_of(x, y, z) (y *)((char *)(x) - ((unsigned long)&((y *)0)->z))
enum {
STATE_FILL,
STATE_WRITE,
@courtc
courtc / pp-gcc.py
Last active Aug 29, 2015
Error file to patch line, with fuzzing
View pp-gcc.py
#!/usr/bin/env python2
import fileinput;
import sys;
import re;
import os;
def shortpath(name):
cwd = os.getcwd()
if name.startswith(cwd):
@courtc
courtc / depgen.c
Created May 12, 2014
Dependency generator
View depgen.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/stat.h>
enum {
INC_COMMANDLINE,
INC_AFTER,