Skip to content

Instantly share code, notes, and snippets.

voila

  • Dunedin, NZ
Block or report user

Report or block voila

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View punch_tape_animation.py
import sys
from time import sleep
import random
import cursor
class Renderer:
def __init__(self, width, height):
@Leonidas-from-XIV
Leonidas-from-XIV / lwt_ppx_let.ml
Last active Mar 19, 2019
Using Lwt with ppx_let instead of ppx_lwt
View lwt_ppx_let.ml
module Let_syntax = struct
let return = Lwt.return
let (>>=) = Lwt.Infix.(>>=)
let (>>|) = Lwt.Infix.(>|=)
module Let_syntax = struct
let bind m ~f = Lwt.bind m f
end
end
@porglezomp
porglezomp / Leftpad.idr
Last active Oct 22, 2018
Taking on Hillel's challenge to formally verify leftpad (https://twitter.com/Hillelogram/status/987432181889994759)
View Leftpad.idr
import Data.Vect
-- `minus` is saturating subtraction, so this works like we want it to
eq_max : (n, k : Nat) -> maximum k n = plus (n `minus` k) k
eq_max n Z = rewrite minusZeroRight n in rewrite plusZeroRightNeutral n in Refl
eq_max Z (S _) = Refl
eq_max (S n) (S k) = rewrite sym $ plusSuccRightSucc (n `minus` k) k in rewrite eq_max n k in Refl
-- The type here says "the result is" padded to (maximum k n), and is padding plus the original
leftPad : (x : a) -> (n : Nat) -> (xs : Vect k a)
@keleshev
keleshev / xml.ml
Last active Apr 8, 2018
Simple XML pretty-printing in OCaml using Format module
View xml.ml
#! /usr/bin/env ocaml
let fprintf = Format.fprintf
type t =
| Tag of {name: string; attributes: (string * string) list; body: t list}
| String of string
let format_attribute f (key, value) = fprintf f " %s=\"%s\"" key value
@Drup
Drup / difflist.ml
Last active Jul 11, 2019
Difference lists and Miniformat
View difflist.ml
type ('ty,'v) t =
| Nil : ('v, 'v) t
| Cons : 'a * ('ty, 'v) t -> ('a -> 'ty, 'v) t
let cons x l = Cons (x,l)
let plus1 l = Cons ((),l)
let one x = Cons (x,Nil)
View match_tutorial_rewrite.rs
// 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.
View interactive_machine_learning.md

Interactive Machine Learning

Taught by Brad Knox at the MIT Media Lab in 2014. Course website. Lecture and visiting speaker notes.

View run-yield.js
// 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() {
View try-throw-catch.js
// Example code, see try/catch/throw implementation below
function bar(x) {
if(x < 0) {
Throw(new Error("error!"));
}
return x * 2;
}
function foo(x) {
@johnynek
johnynek / stref.scala
Last active Nov 10, 2015
mutable variables via a state thread in scala. This is just meant as an illustration of how ST in haskell works, and more generally, how you can implement mutation with immutable APIs.
View stref.scala
object STRef {
/**
* Here is a container where we have a single "state thread" = ST.
* When we run this thread of type ST[T] we get a result of type T.
*/
sealed abstract class ST[+T] {
def map[R](fn: T => R): ST[R] = flatMap(t => Const(fn(t)))
def flatMap[R](fn: T => ST[R]): ST[R] = FlatMapped(this, fn)
}
You can’t perform that action at this time.