Skip to content

Instantly share code, notes, and snippets.

View superbobry's full-sized avatar

Sergei Lebedev superbobry

View GitHub Profile
@superbobry
superbobry / gist:ca00f2002fe4cc6cdfb5
Created May 17, 2014 19:08
'io' module in Python2.6.6
>>> import io
>>> f = io.open("./article_categories_en.nt")
>>> f = io.TextIOWrapper(f)
>>> next(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/io.py", line 1782, in next
line = self.readline()
File "/usr/lib64/python2.6/io.py", line 1858, in readline
while self._read_chunk():
@superbobry
superbobry / InitData.cpp
Created February 13, 2014 12:44
Idiomatic C++ code from hsmm R package
void InitParaAndVar(int CensoringPara, int tauPara, int JPara, int MPara, double dPara[],
double pPara[], double piPara[], double pdfPara[])
{
int i, j, u;
Censoring = CensoringPara;
tau = tauPara;
J = JPara;
M = MPara;
@superbobry
superbobry / gist:8228050
Last active June 14, 2022 11:30 — forked from debasishg/gist:8172796
Sketching References
  1. General Background and Overview
@superbobry
superbobry / gist:4041489
Created November 8, 2012 20:48
Python and +=
# -*- coding: utf-8 -*-
from collections import MutableSequence
def trace(f):
def inner(*args, **kwargs):
print(f.__name__)
return f(*args, **kwargs)
return inner
def foo():
try:
foo()
finally:
foo()
# >>> foo()
# ???
@superbobry
superbobry / ChromaSig_seq.pl
Created August 8, 2012 11:43
The Joy of Reading Code Written in Academia
# See http://bioinformatics-renlab.ucsd.edu/rentrac/wiki/ChromaSig
sub init_gibbs_seed {
# ...
# print("score = $score\n");
# my ($seed, $ave_dist) = tournament_sort($id, $profiles_c,
# $clusters_arrayref, $filtered_data);
# my $norm = $sorted_norm[$percentile + $i * $interval]->{norm};
# my $score = $norm / $ave_dist;
@superbobry
superbobry / task1.py
Created May 25, 2012 22:33
Bioinf. Algorithms Homework
# -*- coding: utf-8 -*-
# from __future__ import print_function
import csv
import itertools
import errno
import os
import os.path
import sys
@superbobry
superbobry / gist:1917188
Created February 26, 2012 15:00
Iterable unpacking in Python
>>> def f((x, y)): return x + y
...
>>> def gen():
... yield 1
... yield 2
...
>>>
>>> f(gen())
3
@superbobry
superbobry / rose.ml
Created February 15, 2012 20:08
Basic Rose Trees in OCaml
open StdLabels
type 'a tree = Node of ('a * 'a tree list)
let rec make ~f init =
let (label, forest) = f init in
Node (label, (List.map ~f:(make ~f) forest))
and draw ~f (Node (label, forest)) =
let rec inner = function
@superbobry
superbobry / gist:1617642
Created January 15, 2012 22:03
First class modules and functors
# module M = Map.Make((val (module String : Map.OrderedType) : Map.OrderedType));;
module M :
sig
type key
type +'a t
end
# module M = Map.Make(String);;
module M :
sig
type key = String.t