This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(channels). | |
-compile(export_all). | |
make() -> | |
Ref = make_ref(), | |
Pid = spawn(?MODULE, channel, [Ref]), | |
{channel, Pid, Ref}. | |
channel(Ref) -> | |
receive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir p1 | |
$ cd p1/ | |
$ rebar create-app appid=hotdo | |
$ ls | |
$ mkdir deps | |
$ touch rebar.config | |
$ # feeling rebar config file | |
$ wget -O rebar.config https://gist.github.com/kachayev/5657307/raw/fb9b0cd0d62e053efe54774bf2033e6e651c6622/hotdo.rebar.config | |
$ rebar get-deps | |
$ tree -L 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define stream | |
(letrec ((next | |
(lambda (n) | |
(cons n (delay (next (+ n 1))))))) | |
(next 0))) | |
(define head car) | |
(define (tail st) (force (cdr st))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## More infromation about SkipList data structure one can find: | |
## on Wikipedia http://en.wikipedia.org/wiki/Skip_list | |
## on Stackoverflow http://stackoverflow.com/questions/256511/skip-list-vs-binary-tree | |
from math import log | |
from random import randint, random | |
class SkipNode(object): | |
__slots__ = "value", "next" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tkinter as tk | |
import time | |
from operator import itemgetter | |
from math import sqrt | |
from random import randint | |
from Queue import Queue | |
from threading import Thread | |
def vdist(q, (x1,y1), (x2,y2)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple: | |
# a --> b | |
# --> c --> d | |
# --> d | |
graph1 = { | |
"a": ["b", "c", "d"], | |
"b": [], | |
"c": ["d"], | |
"d": [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Union-Find (Disjoint Set Union) | |
# more information on wiki: | |
# http://en.wikipedia.org/wiki/Disjoint-set_data_structure | |
class UF(object): | |
def __init__(self, size): | |
self.p = [None]*size | |
self.rank = [1]*size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Pairing Heap implementation | |
%% more information on wiki: | |
%% http://en.wikipedia.org/wiki/Pairing_heap | |
%% pq :: {pq, heap(), int()} | |
%% heap :: nil | {Item, [heap()]} | |
%% ============================= | |
%% API | |
%% ============================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## Pairing heap data structure | |
## More information on wiki: | |
## http://en.wikipedia.org/wiki/Pairing_heap | |
## | |
## Data types | |
## Heap :: (Elem | None, Subs) | |
## Subs :: None | (Heap, Subs) | |
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from heapq import * | |
def dijkstra(edges, f, t): | |
g = defaultdict(list) | |
for l,r,c in edges: | |
g[l].append((c,r)) | |
q, seen, mins = [(0,f,())], set(), {f: 0} | |
while q: |