Skip to content

Instantly share code, notes, and snippets.

View Xophmeister's full-sized avatar

Christopher Harrison Xophmeister

View GitHub Profile
@Xophmeister
Xophmeister / gist:e745014ded101858d6c7
Last active August 29, 2015 14:01
Functional(ish) Fibonacci in C :)
#include <stdio.h>
int (*fn[2])(int);
int fib(int n) { return (*fn[n < 2])(n); }
int fibSeed(int n) { return 1; }
int fibRecur(int n) { return fib(n - 1) + fib(n - 2); }
void fibInit(void) {
fn[0] = fibRecur;
@Xophmeister
Xophmeister / gist:89f64fff308682e5203e
Last active August 29, 2015 14:19
Xiongxiong token authentication in Python/Flask
from datetime import datetime
from functools import wraps
from flask import Flask, request, Response
app = Flask(__name__)
# Read in the private key and instantiate xiongxiong
with open('privateKeyFile') as keyFile:
@Xophmeister
Xophmeister / gist:df3acce05bd024036ad1
Created May 7, 2015 21:19
Disjunction, functional style
var or = function(/* args */) {
if (arguments.length) {
var x = !!arguments[0],
xs = Array.prototype.slice.call(arguments, 1);
return x || or.apply(undefined, xs);
} else {
return false;
}
};
@Xophmeister
Xophmeister / MinimalChineseWrappingDemo.opensesame
Created August 4, 2015 20:14
Minimal demonstration of wrapping problem with Chinese text
# Generated by OpenSesame 2.9.6 (Hesitant Heisenberg)
# Tue Aug 04 21:11:15 2015 (nt)
# <http://www.cogsci.nl/opensesame>
set background "black"
set bidi "no"
set canvas_backend "legacy"
set compensation "0"
set coordinates "relative"
set description "Default description"
@Xophmeister
Xophmeister / Makefile
Created September 3, 2015 10:07
Generic [GNU] Makefile for C projects on OS X (or otherwise), using pkg-config
# Output
TARGET = my_binary
# OS X default is a GCC frontend to LLVM
# Real GCC can be installed via, e.g., Homebrew
CC = gcc
LD = ld
# List of library dependencies
# pkg-config can be installed via, e.g., Homebrew
@Xophmeister
Xophmeister / human_size.c
Last active September 8, 2015 13:40
Quick-and-Dirty Human Size
#include <stdio.h>
#include <sys/types.h>
/**
@brief Human file size
@param size File size in bytes
@return Base 2 prefixed file size string
This isn't as complete as Gnulib's `human_readable`, but it does the
job without any allocation or messing around
@Xophmeister
Xophmeister / foo.sh
Created September 14, 2015 09:59
Process substitution is neat :)
#!/bin/bash
# Change the group and group permissions for everything, recursively, in the cwd
find . | tee >(xargs chgrp -h NEW_GROUP) | xargs chmod -h g+rw
@Xophmeister
Xophmeister / bp.d
Created June 28, 2012 13:28
Branch Prediction Benchmarking in D
import std.stdio, std.random, core.time;
void main() {
int data[32768];
foreach(ref x; data)
x = uniform(0, 256);
data.sort;
@Xophmeister
Xophmeister / msTimer.d
Created June 29, 2012 13:18
Just a silly little timer!
import std.stdio, core.time;
class msTimer {
TickDuration start;
this() { reset(); }
long split() { return (TickDuration.currSystemTick() - start).msecs(); }
void reset() { start = TickDuration.currSystemTick(); }
}
@Xophmeister
Xophmeister / gist:3040407
Created July 3, 2012 15:20
Playing with Primes in Python
import math
import random
class PrimeBuilder:
_p = set()
_maxChecked = 0
def __init__(self, p = {2, 3, 5}):
self._p = p
self._maxChecked = max(p)