Skip to content

Instantly share code, notes, and snippets.

let mk_idmap (mk_id : unit -> 'b) (ids : 'a list) : 'a -> 'b =
List.fold_left (fun acc x ->
let new_id = mk_id () in
(fun id -> if id = x then new_id else acc id )
) (fun _ -> raise Not_found) ids
let mk_id =
let id = ref 0 in
function () -> incr id; !id
// gcc -Wall -std=gnu11 main.c -o main
#include <stdio.h>
#include <stdlib.h>
typedef void callback_t(void);
void test(void (*)(void));
void myFun(void *);
@graymalkin
graymalkin / example.ml
Created January 23, 2017 14:45
quick run through co658 examples
(* count *)
(* val count: 'a -> 'a list -> int *)
let rec count x xs =
match xs with
| a::xs when a == x -> 1 + count x xs
| _::xs -> 0 + count x xs
| [] -> 0
(* remove list duplicates *)
(* val nub : 'a list -> 'a list *)
@graymalkin
graymalkin / output.txt
Created November 20, 2016 13:53
Statically allocate arrays with data
simon@merkel:~/tmp
$ gcc -Wall stat_arr.c -o stat_arr
simon@merkel:~/tmp
$ ./stat_arr
Pub #0 is at 51.27955, 1.07893
Pub #1 is at 51.28248, 1.08050
Pub #2 is at 51.28223, 1.07135
Pub #3 is at 51.27766, 1.08356
Pub #4 is at 51.28236, 1.08262
@graymalkin
graymalkin / wheel.scad
Last active August 15, 2016 15:28
Parametric wheel design
WHEEL_D = 30; // Wheel diameter
WHEEL_W = 10; // Wheel width (or height)
WHEEL_T = 3; // Wheel & axle rim thickness
COMB_SIZE = 4; // Width of honey comb "holes"
COMB_GAP = 1; // Width of honey comb "walls"
AXLE_D = 2; // Axle diameter
// Set the resolution of the render
$fn = 100;
#include "mbed.h"
#include "C12832.h"
Serial xbee(D1, D0);
Serial host(USBTX, USBRX);
C12832 lcd(D11, D13, D12, D7, D10);
AnalogIn pot(A0);
#define MAX_RPM 9600
@graymalkin
graymalkin / Change log
Last active August 29, 2015 14:24
lambda-0.1 Diff
- Updated include for readline.h
- Included lambda.tab.h in lamscan
- Changed `NEWLINE` to `NEW_LINE` to prevent naming clash
wc_zero = [
lambda n: (n < 32),
lambda n: (n >= 127 and n < 160),
lambda n: unicodedata.combining(chr(n)) > 0
]
wc_two = [
lambda n: (n>=4352 and n<=4447),
lambda n: (n>=11904 and n<=42191 and (n&~17)!=12298 and n!=12351),
lambda n: (n>=65072 and n<=65135), lambda n: (n>=65280 and n<=65375),
lambda n: (n>=65504 and n<=65511), lambda n: (n>=131072 and n<=196607)
#!/usr/bin/env runhaskell
--- Moves all headings down one for use as sections in a LaTeX document
--- Also overrides :
--- The codeblock behaviour to use minty, with some given options
--- The image behaviour
import Text.Pandoc.JSON
import Text.Pandoc.Walk
heading :: Block -> Block
@graymalkin
graymalkin / app_shared_memory.xc
Last active August 29, 2015 14:20
Sharing memory in XC
/*
* app_shared_memory.xc
*
* Created on: 8 May 2015
* Author: simonc
*/
#include <print.h>
#include <xs1.h>
int q;