Skip to content

Instantly share code, notes, and snippets.

View reiddraper's full-sized avatar

Reid Draper reiddraper

View GitHub Profile
tanb /
Last active November 27, 2021 13:07
FreeBSD running on xhyve tutorial. (Appendix: Resize image with qemu. Create FreeBSD VM with qemu).


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


gfredericks / gen_subset.clj
Created April 1, 2014 17:19
Example use of the hypothetical gen/for for test.check.
(defn gen-subset
"Generates an even-cardinality subset of the given elements"
(gen/for [bools (apply gen/tuple (repeat (count elements) gen/boolean))
:let [true-count (->> bools (filter identity) (count))]
:when (even? true-count)]
(->> (map list bools elements)
(filter first)
(map second)
eraserhd / simple-check.clj
Created January 24, 2014 00:25
An attempt at testing multiple splices via simple-check.
;; 1. What I'm testing: A rope implementation where the binary tree is
;; balanced by splaying.
;; 2. To simplify things, it supports one update operation:
;; (splice rope start-offset end-offset new-data)
;; 3. I'd like to verify that the nodes are in the right order and other
;; properties after multiple splicings
;; Here's a spec I wrote for testing that the rope has the right
;; string representation after a single insertion-type splice:
jfarcand /
Last active May 29, 2018 18:07
Fixing broken ngrep with OS X Mavericks

Migrating to OS X Mavericks breaks the ngrep utility. Doing:

sudo ngrep -d lo0 -q -W byline port 8080

stopped working where the process exits immediately. I didn't dig into the ngrep code, but was able to find a simple workaround by doing

sudo ngrep -q -W byline -d lo0 '' 'port 8080'

You can call that a lazy hack, but it work!

simple_test() ->
{ok, EC} = erasuerl:new(),
{ok, Bin} = file:read_file("/usr/share/dict/words"),
{MD, KBins, MBins} = erasuerl:encode(EC, Bin),
[K1, K2, K3, K4, K5, K6, K7, K8, K9] = KBins,
[M1, M2, M3, M4] = MBins,
KBins2 = [undefined, undefined, undefined, K4, K5, K6, K7, K8, K9],
MBins2 = [undefined, M2, M3, M4],
Bin = iolist_to_binary(erasuerl:decode(EC, MD, KBins2, MBins2)).
(defn- shrink-number
(->> (iterate #(quot % 2) n)
(drop 1)
(take-while (if (integer? n)
(partial not= 0)
#(not (== 0 (.unscaledValue (bigdec %))))))))
ericbmerritt / Makefile
Last active August 11, 2023 09:35
Universal drop in Makefile for Erlang projects that use rebar
# Copyright 2012 Erlware, LLC. All Rights Reserved.
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
# Unless required by applicable law or agreed to in writing,
aphyr / gist:5428061
Last active December 16, 2015 11:29
This is a last-write-wins Riak application running across five nodes. Clients are subject to a perfect global write lock: no two clients will ever change a key at the same time. "." means 100 writes, "!" means a single failed write. The string of !!!s in the middle, gradually decreasing in density, is the effect of a network partition followed b…
user=> (run (apps (comp locking-app riak-lww-sloppy-quorum-app)))
.......!!!!!!!!!!!!!!!!!!!!.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.!!!!!!!!!!!!!!!!.!!!!!!!!.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.........Hit enter when ready to collect results.
Writes completed in 178.326 seconds
2000 total
1841 acknowledged
1246 survivors
599 acknowledged writes lost! (╯°□°)╯︵ ┻━┻
505 506 510 511 515 516 ... 1985 1986 1990 1991 1995 1996
if [ "$1" = "-p" ]; then
gburd / bitpop.erl
Last active July 2, 2018 06:27
Hamming weight of 64bit integers in Erlang using the popcount_3() method found counts the number of bits set to 1.
%% -*- coding: utf-8 -*-
%% %CopyrightBegin%
%% Copyright (C) 2013 Gregory Burd. All Rights Reserved.
%% The contents of this file are subject to the Mozilla Public License,
%% Version 2, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Mozilla Public License along with this software. If not, it can be