Skip to content

Instantly share code, notes, and snippets.

@courtc
courtc / depgen.c
Created May 12, 2014 20:38
Dependency generator
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <getopt.h>
#include <sys/stat.h>
enum {
INC_COMMANDLINE,
INC_AFTER,
@courtc
courtc / pp-gcc.py
Last active August 29, 2015 14:01
Error file to patch line, with fuzzing
#!/usr/bin/env python2
import fileinput;
import sys;
import re;
import os;
def shortpath(name):
cwd = os.getcwd()
if name.startswith(cwd):

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 / simplefreq.cpp
Last active December 8, 2015 23:13
Simple frequency detection
/*
* 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 / example.c
Last active June 30, 2016 22:52
HSM, simplified
#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 / class_static_wrapper.py
Created March 10, 2017 16:02
Class static method variable decorator
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 / init.c
Created November 18, 2017 00:52
libc init example
/*
* 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 / cache.h
Last active February 1, 2018 19:50
caching api
#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 / inn-resolve.py
Created January 18, 2023 00:25
Innernet host HTTP query
#!/usr/bin/env python3
# $ ./inn-resolve.py fire.example.wg
# 172.28.208.2
import configparser
import urllib.request
import json
import sys
query = sys.argv[1]
@courtc
courtc / vpy
Last active March 23, 2023 20:53
Virtualenv for Python: Yuck
#!/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.