Skip to content

Instantly share code, notes, and snippets.

// Example code, see try/catch/throw implementation below
function bar(x) {
if(x < 0) {
Throw(new Error("error!"));
}
return x * 2;
}
function foo(x) {
@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
@valtron
valtron / gist:5688638
Last active January 24, 2017 23:53
typescript-unsound-generics.ts
class Box<T> { constructor(public value: T) {} }
class A {}
class B { foo() {} }
var bb : Box<B> = new Box<B>(null);
// This typechecks (it shouldn't; T is used both in a co- and contra-variant position, so it's invariant)...
var ba : Box<A> = xb;
ba.value = new A();
@divarvel
divarvel / continuation.js
Last active May 11, 2018 08:57
Continuation monad in JS. just run $ node continuation.js
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof(actual) === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
// Hello! I'm Leo Tindall, the SilverWingedSeraph, and this is a follow-up to my tutorial on
// using match expressions in Rust.
// In my last video, we created a finite state machine to parse and modify some simple markup.
// In this video, we'll make the machine more abstract and more concise.
// We'll start out the same way: defining the four states of the machine.
// However, we'll use a neat trick that Rust
// provides to make things easier later on. We'll ask the compiler to derive the Copy and Clone
// traits on MachineState, so we don't have to worry about borrowing and ownership.
@jvns
jvns / linkers_101.md
Last active November 18, 2018 14:38
How to understand what's in a binary, with code!

Step 0: A program, and prerequisites

We're going to be dealing with a "Hello, world!" program. Just one. There's going to be a bunch of fruit for discussion here. I'm going to be assuming you're on Linux, because we're gonna be talking about ELF and Macs use Mach-O and I don't know anything about Mach-O.

#include <stdio.h>

char *penguin = "Penguin";
char array[5] = {'a', 'b', 'c', 'd', 'e'};
@kaos
kaos / Vagrantfile
Created May 30, 2013 18:58
Vagrant setup for zotonic
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise32"
// Example code, see below for run/yield implementation. Note how we
// can even do yields across the stack, so this implements something
// more like coroutines than generators.
function foo() {
var x = Yield();
return x + 1;
}
var process = Run(function() {
@TheSeamau5
TheSeamau5 / svgdragdrop.elm
Last active January 29, 2020 05:26
Drag and drop example with svg in Elm
import Svg (Svg, circle, svg, g, line, text)
import Svg.Attributes (cx, cy, r, fill, stroke, strokeWidth, x, y, x1, x2, y1, y2, fontSize, style)
import Html
import Html.Attributes as Html
import Signal (Signal, map, foldp)
import DragAndDrop (mouseEvents, MouseEvent(..))
import List
--------------
@NicolasT
NicolasT / _tags
Last active February 4, 2020 00:26
RWST for state machines in OCaml
true: package(lwt)
true: package(lwt.unix)
<rwst.ml>: camlp4orf, use_monad