Skip to content

Instantly share code, notes, and snippets.

View barrucadu's full-sized avatar

Michael Walker barrucadu

View GitHub Profile
#include <stdio.h>
#include <math.h>
#define PHI ((1 + sqrt (5)) / 2)
/**
* Get an integer above a given minimum value.
*
* @param The prompt to display
* @param The minimum value
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/* ***** Caching stuff ***** */
double *fibcache = NULL;
int fibcache_size = 0;
@barrucadu
barrucadu / fib.c
Created October 26, 2011 15:06
Fibonacci generator
#include <assert.h>
#include <stdio.h>
#include <math.h>
#include "fib.h"
/* ***** Caching stuff ***** */
/**
* This function checks if f(n) is in the cache for a given n.
@barrucadu
barrucadu / Cypher.c
Created November 2, 2011 13:43 — forked from anonymous/Cypher.c
#include <stdio.h>
#include <string.h>
#define MAXSTR 50
char pt[MAXSTR], ct[MAXSTR], dt[MAXSTR] ;
int trans(void){ /*Transposition Cypher
*Swaps adjacent pairs of letters
*/
-- Expression type
data Expression = Constant Float
| Variable String
| Partial String String
| BinOp String Expression Expression
| Func String Expression
deriving Show
-- -- Evaluation
eval e = simplify e
-- -- Expression type
data Expression = Constant Float
| Variable String
| Partial String String
| BinOp String Expression Expression
| Func String Expression
| Exp Expression Float
deriving Show
-- -- Evaluation
BIN := xo
CC := gcc
CFLAGS := -Wall -Wextra -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Winit-self -Wmissing-prototypes -Wstrict-prototypes -Wconversion -std=gnu99 -ggdb -pedantic
SOURCES := $(wildcard *.c)
.PHONY: all clean
all: $(BIN)
$(BIN): $(SOURCES:.c=.o)
@barrucadu
barrucadu / xkcd.c
Last active December 15, 2015 16:19
HackSoc's attempt on the XKCD challenge
/* This needs the Skein functions from the NIST distribution. You can
* get the zip file from http://www.schneier.com/skein.html ("Source
* code and test vectors for Skein and Threefish (12 MB)"), and then
* you need to stick the contents of NIST/CD/Reference_Implementation
* in the same directory as this file.
*
* Compile with clang -std=c99 *.c -lcurl -lpthread -O3 -o xkcd-skein
*/
#include <time.h>
@barrucadu
barrucadu / client.py
Created May 11, 2013 22:43
Implementation of the key distribution protocol described in Secure Communications over Insecure Channels (Merkle 1978)
#!/usr/bin/env python
"""Puzzle Key Exchange Client.
Usage:
puzzle.py [--n=<n>] [--c=<c>] --host=<hostname> [--port=<port>] [-v]
puzzle.py -h | --help
Options:
@barrucadu
barrucadu / index.hs
Last active December 17, 2015 18:09
Adventures with indexable data types, as talked about in http://blog.barrucadu.co.uk/2013/05/25/indexing-collections-in-haskell/
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Indexable where
-- Our Indexables are all Traversables, and for the default implementation
-- of (!!!) we need fromJust.
import Data.Maybe (fromJust)
import Data.Traversable (Traversable(..))