Skip to content

Instantly share code, notes, and snippets.

View markandrus's full-sized avatar
🍊
orange

Mark Roberts markandrus

🍊
orange
View GitHub Profile
@Icelandjack
Icelandjack / NewtypeDeriving.markdown
Last active April 4, 2023 04:49
Newtype Deriving
@tonymorris
tonymorris / PureIO.java
Last active December 18, 2017 02:30
Pure-functional terminal I/O in java
import java.util.function.Function;
import java.util.function.BiFunction;
import java.util.Scanner;
abstract class TerminalOperation<A> {
// this ensures that there are no subclasses of TerminalOperation
// outside of this class
private TerminalOperation() {
}
@bellbind
bellbind / binding.gyp
Last active June 20, 2024 18:22
[nodejs]Native module with libuv and v8::Promise on node-4
# -*- mode: python -*-
{
"targets": [
{
"include_dirs": ["<!(node -e \"require('nan')\")"],
"target_name": "TimerAndPromise",
"sources": [
"timer-and-promise.cc"
],
"conditions": [
@stelleg
stelleg / hm_scott.lhs
Last active July 4, 2016 10:42
Hindley Milner + Scott Encoding Musings
Sometimes it would be nice if a type system could automatically "do it's best"
to restrict what a value will be. For example, the type `Bool` is the compiler
saying the value will either be `True` or `False`, but it doesn't know which.
What we want is the compiler to be able to be precise when possible, so instead
of always saying `Bool` (or "I don't know"), it could say `True`, `False`, or
`Bool`. This gist shows how Hindley Milner already has this capability that can
be exercised by using Church or Scott encodings of simple data types.
> {-# LANGUAGE RankNTypes #-}
> import qualified Data.Maybe as M
@lalinsky
lalinsky / fp-find.py
Created July 22, 2011 18:02
Locate audio snippets in a longer stream
def format_time(secs):
return "%d:%02d" % (secs / 60, secs % 60)
def invert(arr):
"""
Make a dictionary that with the array elements as keys and
their positions positions as values.
>>> invert([3, 1, 3, 6])
--
-- Play a song and flash LEDs on alternate notes.
-- Lee Pike <lee pike @ gmail . com> (remove spaces)
-- See http://leepike.wordpress.com/?p=427
-- BSD3 License
--
-- Note timing issues: http://www.arduino.cc/en/Tutorial/PlayMelody
--
module CopilotSing where