Skip to content

Instantly share code, notes, and snippets.

View matklad's full-sized avatar

Alex Kladov matklad

View GitHub Profile
@matklad
matklad / Foo.java
Created December 29, 2013 17:24
Pattern matching of a poor man
import java.io.Serializable;
public class TwoAvgProtocol implements Serializable {
interface MessageReceiver {
public void onHave(double val);
public void onAdjust(double delta);
}
static abstract class Message {
@matklad
matklad / combinat.py
Created October 16, 2013 17:53
brute force random combination
import functools
import collections
import random
@functools.lru_cache(maxsize=None)
def c(n, k):
if k == 0 or k == n:
return 1
else:
import std.stdio;
import std.conv;
class Vector(T, int S) {
static immutable size = S;
T[S] elemets;
public this(){
for(int i = 0; i < S; i++)
elemets[i] = i;
val p1 = Variable "x";
val p2 = TupleP [Variable "x", Variable "y"];
val p3 = ConstructorP ("Frac", Wildcard);
val p4 = ConstructorP ("Frac", ConstP 42);
val p5 = ConstructorP ("Comp", Variable "x");
val p6 = ConstructorP ("Comp", TupleP [Wildcard, Wildcard]);
val p7 = ConstructorP ("Comp", TupleP [ConstructorP ("Frac", TupleP [Wildcard, ConstP 42]),
ConstructorP ("Nat", Wildcard)]);
val pt1 = ConstructorP ("Nat", UnitP);
import sys
from multiprocessing import Process, Queue
from cStringIO import StringIO
import gc
def memory_safe(f):
def g(*args):
def h(q, aargs):
q.put(f(*aargs))
q = Queue()
@matklad
matklad / 0.suffixtree.cs
Created May 7, 2012 05:34 — forked from axefrog/0.suffixtree.cs
C# Suffix tree implementation based on Ukkonen's algorithm
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace SuffixTreeAlgorithm
{
public class SuffixTree
{