Skip to content

Instantly share code, notes, and snippets.

bishboria /
Last active Jun 13, 2021
Springer made a bunch of books available for free, these were the direct links
paf31 / W.lhs
Last active Mar 22, 2021
Algorithm W
View W.lhs
## Principal type-schemes for functional programs
**Luis Damas and Robin Milner, POPL '82**
> module W where
> import Data.List
> import Data.Maybe
> import Data.Function
View gist:19901dd61263f0dd49ec
(define (unify a b)
(cond ((and (pair? a)
(pair? b)) (cons (unify (car a) (car b))
(unify (cdr a) (cdr b))))
((symbol? a) b) ; here i just return b, because a symbol matches anything. a more complex system would have a third argument
; , the environment, that tracks existing bindings for a, and prevents conflicts. then, instead of returning b
; we could update the environment with the binding for a = b, or issue a failure (in kanren language, #u)
((eq? a b) b) ; a and b trivially unify without updating any bindings. here I just return their mutual value
kaeluka / horr.erl
Last active Jul 2, 2019
Global mutable state in erlang.
View horr.erl
-export([malloc/0, free/1, read/1, write/2, test/0]).
% You can use `malloc` to get a globally sharable, mutable cell of memory.
% A difference to C's `malloc` is that such a cell doesn't have a certain size (you can't overflow)
% Memory is initialised with the atom `null`.
malloc() ->
spawn(fun() -> mem(null) end).
% As processes are not garbage collected, you have to call `free` when you're done with your memory:
cdiener /
Last active May 26, 2021
Convert image to ascii art
import sys; from PIL import Image; import numpy as np
chars = np.asarray(list(' .,:;irsXA253hMHGS#9B&@'))
if len(sys.argv) != 4: print( 'Usage: ./ image scale factor' ); sys.exit()
f, SC, GCF, WCF = sys.argv[1], float(sys.argv[2]), float(sys.argv[3]), 7/4
img =
S = ( round(img.size[0]*SC*WCF), round(img.size[1]*SC) )
img = np.sum( np.asarray( img.resize(S) ), axis=2)
anthonyeden / Python WExpect
Created Jan 18, 2014
Python's PExpect for Microsoft Windows: WExpect
View Python WExpect
"""Pexpect is a Python module for spawning child applications and controlling
them automatically. Pexpect can be used for automating interactive applications
such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup
scripts for duplicating software package installations on different servers. It
can be used for automated software testing. Pexpect is in the spirit of Don
Libes' Expect, but Pexpect is pure Python. Other Expect-like modules for Python
require TCL and Expect or require C extensions to be compiled. Pexpect does not
use C, Expect, or TCL extensions. It should work on any platform that supports
the standard Python pty module. The Pexpect interface focuses on ease of use so
that simple tasks are easy.
jameshfisher /
Last active Sep 7, 2017
A proof that the Halting problem is undecidable, using JavaScript and examples

Having read a few proofs that the halting problem is undecidable, I found that they were quite inaccessible, or that they glossed over important details. To counter this, I've attempted to re-hash the proof using a familiar language, JavaScript, with numerous examples along the way.

This famous proof tells us that there is no general method to determine whether a program will finish running. To illustrate this, we can consider programs as JavaScript function calls, and ask whether it is possible to write a JavaScript function which will tell us

View Graph.hs
-- | Some functions on directed graphs.
module Language.Coatl.Graph where
-- base
import Data.Maybe
-- containers
import Data.Map (Map)
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S
-- mtl
quchen / trolling_haskell
Last active May 20, 2021
Trolling #haskell
View trolling_haskell
13:16 <luite> | hello
13:16 <ChongLi> | somebody has a mental illness!
13:16 <merijn> | Wow...I suddenly see the error of my ways and feel
| compelled to write Node.js!
13:16 <genisage> | hi
13:16 <luite> | you might be pleased to learn that you can compile
| haskell to javascript now
washort / tutorial.rst
Created Aug 18, 2012
parsley tutorial
View tutorial.rst

Parsley Tutorial

From Regular Expressions To Grammars

Parsley is a pattern matching and parsing tool for Python programmers.