Skip to content

Instantly share code, notes, and snippets.

View markandrus's full-sized avatar
🍊
orange

Mark Roberts markandrus

🍊
orange
View GitHub Profile
{-#LANGUAGE DeriveFunctor #-}
{-#LANGUAGE ExistentialQuantification #-}
{-#LANGUAGE FlexibleInstances #-}
{-#LANGUAGE ScopedTypeVariables #-}
module Main where
import Data.List
import Data.Maybe
import Data.Void
import Numeric.Natural
@markandrus
markandrus / generate.sh
Last active December 28, 2015 02:09
Generate Blink/v8 bindings with idl_compiler.py
#!/bin/sh
# It's not so clear how to use idl_compiler.py, and the .gyp/.gn files are fairly
# opaque (not to mention the "Global Information" section of
# https://www.chromium.org/developers/design-documents/idl-compiler#TOC-Global-information
# isn't even filled out... oh well).
set -e
echo "Generating core-files-list.txt..."
find core -name \*.idl ! -name InspectorInstrumentation.idl >core-files-list.txt
@markandrus
markandrus / roundtrip.idr
Last active October 2, 2015 06:50
Roundtrip a String through Vect and back
module Main
import Data.Vect
listToVect : List a -> (n ** Vect n a)
listToVect [] = (0 ** [])
listToVect (a :: as) with (listToVect as)
| (n ** as') = (1 + n ** a :: as')
stringToVect : String -> (n ** Vect n Char)
@markandrus
markandrus / macchiato.js
Last active August 29, 2015 14:26
We should have a concurrent Mocha-like test framework!
'use strict';
var assert = require('assert');
var util = require('util');
var DEFAULT_TIMEOUT = 200;
// Abstract Syntax Tree for Defining Tests
// ----------------------------------------------------------------------------
@markandrus
markandrus / Makefile
Last active January 5, 2023 08:02
Makefile to convert a directory of Markdown sources to HTML
SRC_MD_FILES=$(shell find src -name \*.md)
MD_FILES=$(SRC_MD_FILES:src/%=%)
HTML_FILES=$(MD_FILES:.md=.html)
BUILD_HTML_FILES=$(HTML_FILES:%=build/%)
all: $(BUILD_HTML_FILES)
build/%.html: src/%.md
mkdir -p $$(dirname $@)
pandoc -o $@ $?
@markandrus
markandrus / test.sh
Created April 16, 2015 23:43
Test HTTP 302 response to WebSocket upgrade request
#!/bin/sh
HTTP_PORT=9090
WS_PORT=9091
echo "HTTP/1.1 302 Found\r\nLocation: http://localhost:${WS_PORT}\r\nContent-Length: 0\r\n" | nc -l ${HTTP_PORT} &
wscat -l ${WS_PORT} &
wscat -c ws://localhost:${HTTP_PORT}
@markandrus
markandrus / main.hs
Created March 28, 2015 21:45
Data.Functor.Nest to arbitrary depth
{-#LANGUAGE DataKinds #-}
{-#LANGUAGE KindSignatures #-}
{-#LANGUAGE TypeFamilies #-}
{-#LANGUAGE TypeOperators #-}
{-#LANGUAGE UndecidableInstances #-}
{-#LANGUAGE ViewPatterns #-}
module Main where
import Data.Functor.Identity
@markandrus
markandrus / http.hs
Created February 24, 2015 17:55
Sketch for a testable, free monad-based HTTP client
{-#LANGUAGE DataKinds #-}
{-#LANGUAGE DeriveDataTypeable #-}
{-#LANGUAGE DeriveFoldable #-}
{-#LANGUAGE DeriveFunctor #-}
{-#LANGUAGE DeriveGeneric #-}
{-#LANGUAGE DeriveTraversable #-}
{-#LANGUAGE GADTs #-}
{-#LANGUAGE GeneralizedNewtypeDeriving #-}
{-#LANGUAGE KindSignatures #-}
{-#LANGUAGE TypeFamilies #-}
@markandrus
markandrus / example.py
Created January 28, 2015 06:36
example.py
class Option(object):
def __init__(self, is_defined, value=None):
self.is_defined = is_defined
if is_defined:
self.value = value
@classmethod
def Some(cls, value):
return Option(True, value)
@markandrus
markandrus / chunked.scala
Last active August 29, 2015 14:13
chunked.scala
object Chunked {
def getItems(start: Int, count: Int): List[Int] = {
// Simulate doing I/O to get the items.
val items = List.range(start*count, (start*count)+count)
println(s"> Database returned: ${items}")
items
}
def chunked(count: Int): Stream[Int] = {