Skip to content

Instantly share code, notes, and snippets.

View superbobry's full-sized avatar

Sergei Lebedev superbobry

View GitHub Profile
@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 / 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;
def foo():
try:
foo()
finally:
foo()
# >>> foo()
# ???
@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
@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 / 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: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 / ChromHMM.java
Created October 13, 2014 15:48
Academic Java by example
/**
* ChromHMM - automating chromatin state discovery and characterization
* Copyright (C) 2008-2012 Massachusetts Institute of Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@superbobry
superbobry / gist:44276d49244c381be649
Created November 11, 2014 21:44
Python generators and 'throw'
>>> def g():
... yield 42
...
>>> gen = g()
>>> next(gen)
42
>>> gen.throw(RuntimeError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in g
@superbobry
superbobry / example.py
Created December 22, 2014 16:37
Python 2/3 buffer protocol inconsistency
# Python 2
>>> b = bytearray(8)
>>> v = memoryview(b)
>>> v[0] = 42
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' does not have the buffer interface
>>> b
bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')