Skip to content

Instantly share code, notes, and snippets.

View yomimono's full-sized avatar
https://ko-fi.com/yomimono

yomimono yomimono

https://ko-fi.com/yomimono
View GitHub Profile
@yomimono
yomimono / coruscate.ino
Created December 14, 2013 07:28
An Arduino program which instructs independently-addressable wearable LEDs to change color at random while avoiding certain undesirable states, and to set their intensity in accordance with input from a light sensor.
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561.h>
#define PIN 6
#define MINIMUM_LUX 20
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
@yomimono
yomimono / Makefile
Last active January 2, 2016 01:39
An implementation of the Sieve of Eratosthenes, which answers the the question "what is the nth prime?", as long as n is <= 10001.
CFLAGS = -g -Wall
all : problem_7
problem_7 : problem_7.c
$(CC) $(CFLAGS) -o $@ $< -lm
@yomimono
yomimono / fortune.hs
Created March 10, 2014 23:03
fortune server in haskell
import Control.Concurrent (forkIO)
import Control.Monad (forever)
import Network
import System.IO
import System.Random
rand :: Int -> IO Int
rand p = getStdRandom (randomR (0, p))
fortune :: [String] -> (Handle, HostName, PortNumber) -> IO ()
@yomimono
yomimono / ec2-ebs-ami.sh
Last active June 21, 2016 12:21
Automate creation of an EC2-ready Mirage unikernel.
#!/bin/bash
#set -e
#set -x
fail() {
echo $1
[ -e ${EBS_DEVICE} ] && [ "$VOLUME_ID" != "" ] && [ $REGION != "" ] && {
ec2-detach-volume --region $REGION $VOLUME_ID
ec2-delete-volume --region $REGION $VOLUME_ID
@yomimono
yomimono / never_graduate.ino
Created June 26, 2014 04:18
Blink shirt LEDs with a sequence and timing that suggests a terminal cursor.
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define PIXELS 7
#define MAX_PERTURBATION 3
#define RANDOM_SOURCE 10
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
@yomimono
yomimono / config.ml
Created August 19, 2014 03:32
config.ml for static site blog
open Mirage
(* If the Unix `MODE` is set, the choice of configuration changes:
MODE=crunch (or nothing): use static filesystem via crunch
MODE=fat: use FAT and block device (run ./make-fat-images.sh)
*)
let mode =
try match String.lowercase (Unix.getenv "FS") with
| "fat" -> `Fat
| _ -> `Crunch
@yomimono
yomimono / dispatch.ml
Created August 19, 2014 03:34
dispatch.ml for static site blog
open Lwt
open Printf
open V1_LWT
open Re_str
module Main (C:CONSOLE) (FS:KV_RO) (S:Cohttp_lwt.Server) = struct
let start c fs http =
let read_fs name =
@yomimono
yomimono / client.ml
Created February 23, 2015 17:46
stackv4.create_connection fails with statically configured interface
open Lwt
open V1_LWT
module Main (C: V1_LWT.CONSOLE) (CLIENT_STACK: V1_LWT.STACKV4) = struct
let local_webserver="8.8.8.8"
let port = 5162
let start c client_stack =
let construct_request () =
let buf = Io_page.(to_cstruct (get 1)) in
@yomimono
yomimono / pcb_snippet.ml
Created June 25, 2015 14:30
snippet of pcb.ml
337 (* Compose the overall thread from the various tx/rx threads
338 and the main listener function *)
339 let tx_thread = (Tx.thread t pcb ~send_ack ~rx_ack) in
340 let rx_thread = (Rx.thread pcb ~rx_data) in
341 let wnd_thread = (Wnd.thread ~utx ~urx ~wnd ~state ~tx_wnd_update) in
342 let threads = [ tx_thread; rx_thread; wnd_thread ] in
343 let catch_and_cancel = function
344 | Lwt.Canceled -> ()
345 | ex ->
346 (* cancel the other threads *)
@yomimono
yomimono / gist:e6c90105ac8f3f80cecd01761dd644d9
Last active January 24, 2017 22:07
MirageOS 3 description of changes.
Less Code, Less Magic, More Results
## Major Changes
* The solo5 targets `ukvm` and `virtio` (see [https://mirage.io/blog/introducing-solo5]), which allow unikernels to run on KVM hypervisors and on FreeBSD via bhyve, are now available in the mainline `mirage` package. These targets use a newly refactored freestanding OCaml runtime (see [https://github.com/mirage/ocaml-freestanding]).
* The `V1` and `V1_LWT` modules, which contained module type definitions agreed upon by implementations used in `mirage`, have been renamed to `Mirage_types` and `Mirage_types_lwt`. The module type definitions themselves are no longer contained in this repository, but have been moved to their own independently-versioned repositories and are merely referenced from `Mirage_types` and `Mirage_types_lwt`.
* Across the universe of module type definitions, errors in computation are now signalled by a `result` type and a set of polymorphic variants representing common errors that might occur. Individual implementations may extend