Skip to content

Instantly share code, notes, and snippets.

View crackcell's full-sized avatar

Menglong TAN crackcell

View GitHub Profile
@bryanhunter
bryanhunter / build-erlang-r16b.sh
Created April 30, 2013 09:26
Build Erlang R16B on Ubuntu
#!/bin/bash
# Pull this file down, make it executable and run it with sudo
# wget https://raw.github.com/gist/5487621/build-erlang-r16b.sh
# chmod u+x build-erlang-r16b.sh
# sudo ./build-erlang-r16b.sh
if [ $(id -u) != "0" ]; then
echo "You must be the superuser to run this script" >&2
exit 1
fi
@ThiporKong
ThiporKong / tsort.scala
Last active October 5, 2020 21:35
Topological sorting: simple implementation in pure Scala
def tsort[A](edges: Traversable[(A, A)]): Iterable[A] = {
@tailrec
def tsort(toPreds: Map[A, Set[A]], done: Iterable[A]): Iterable[A] = {
val (noPreds, hasPreds) = toPreds.partition { _._2.isEmpty }
if (noPreds.isEmpty) {
if (hasPreds.isEmpty) done else sys.error(hasPreds.toString)
} else {
val found = noPreds.map { _._1 }
tsort(hasPreds.mapValues { _ -- found }, done ++ found)
}