Skip to content

Instantly share code, notes, and snippets.

View matklad's full-sized avatar

Alex Kladov matklad

View GitHub Profile
@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
{
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()
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 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;
@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:
@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 / execv.rs
Last active September 30, 2015 10:12
mod ffi {
use libc::{c_int, c_char};
extern {
pub fn setns(fd: c_int, nstype: c_int) -> c_int;
pub fn execvp(path: *const c_char, arg: *const *const c_char) -> c_int;
}
}
Can I use namedtuple?
| YES
|------------------------- Use namedtuple
| |Only two/three fields, forever?
| |---------------------------------- Consider tuples
|
|
|
|
|--Do I need order?
pub mod references {
pub mod psi_ref {
// Unit like struct, the type with only one member
pub struct Ref;
impl Ref {
pub fn resolve(&self) -> &Ref {
// resolve is not pub, but we can use anything from the parent module's scope
super::resolve::do_resolve(self)