Skip to content

Instantly share code, notes, and snippets.

@jbulow
jbulow / isip.rl
Created December 7, 2015 12:20 — forked from jlyo/isip.rl
Ragel IPv4/6 address validator
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netdb.h>
%%{
machine isip;
octet4 = [0-9]{1,2}
@jbulow
jbulow / Makefile
Created December 7, 2015 12:20 — forked from khayrov/Makefile
stock quote parsing with Ragel
CFLAGS=-O2
CXXFLAGS=-O2
all: parser
parser.cpp: parser.rl
ragel -G2 $^ -o $@
parser.o: parser.cpp RawQuote.h
@jbulow
jbulow / recon.ml
Created January 4, 2016 11:21 — forked from kseo/recon.ml
A Hindley-Milner type inference implementation in OCaml
open Core.Std
type term =
| Ident of string
| Lambda of string * term
| Apply of term * term
| Let of string * term * term
| LetRec of string * term * term
let rec term_to_string = function
@jbulow
jbulow / xhyve-freebsd-tutorial-1.md
Created March 31, 2016 06:11 — forked from tanb/xhyve-freebsd-tutorial-1.md
FreeBSD running on xhyve tutorial. (Appendix: Resize image with qemu. Create FreeBSD VM with qemu).

TL;DR

  • Create 5GB FreeBSD image.
  • Install FreeBSD on xhyve.
  • Mount host directory.

Requisites

@jbulow
jbulow / mapread.c
Created October 13, 2016 19:54 — forked from marcetcheverry/mapread.c
mmap and read/write string to file
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
@jbulow
jbulow / avl.ml
Created January 19, 2017 07:39 — forked from matthieubulte/avl.ml
(* Good morning everyone, I'm currently learning ocaml for one of my CS class and needed to implement
an avl tree using ocaml. I thought that it would be interesting to go a step further and try
to verify the balance property of the avl tree using the type system. Here's the resulting code
annotated for people new to the ideas of type level programming :)
*)
(* the property we are going to try to verify is that at each node of our tree, the height difference between
the left and the right sub-trees is at most of 1. *)
-- The meta-circular interpreter from section 5 of Reynolds's Definitional
-- Interpreters for Higher Order Programming Languages
-- (http://www.cs.uml.edu/~giam/91.531/Textbooks/definterp.pdf)
data EXP
= CONST Const
| VAR Var
| APPL Appl
| LAMBDA Lambda
| COND Cond
@jbulow
jbulow / xmldiff.py
Created April 4, 2017 11:08 — forked from dalelane/xmldiff.py
Comparing XML files ignoring order of attributes and elements - see http://dalelane.co.uk/blog/?p=3225 for background
##########################################################################
#
# xmldiff
#
# Simple utility script to enable a diff of two XML files in a way
# that ignores the order or attributes and elements.
#
# Dale Lane ([email protected])
# 6 Oct 2014
#
@jbulow
jbulow / variants.c
Created June 26, 2017 21:24
Tagged unions (a.k.a variants) in C
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#define var __auto_type
#define let __auto_type const
static inline void * variant_cast(void * variant_ptr, ptrdiff_t desired_tag) {
ptrdiff_t * variant_tag = (ptrdiff_t *)variant_ptr;
assert(*variant_tag == desired_tag);
@jbulow
jbulow / AM335x_PRU.cmd
Created January 18, 2018 12:30 — forked from jadonk/AM335x_PRU.cmd
PRU programming with Debian Stretch BeagleBoard.org IoT 2017-06-11 image
/****************************************************************************/
/* AM335x_PRU.cmd */
/* Copyright (c) 2015 Texas Instruments Incorporated */
/* */
/* Description: This file is a linker command file that can be used for */
/* linking PRU programs built with the C compiler and */
/* the resulting .out file on an AM335x device. */
/****************************************************************************/
-cr /* Link using C conventions */