Skip to content

Instantly share code, notes, and snippets.

View superbobry's full-sized avatar

Sergei Lebedev superbobry

View GitHub Profile
@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 / bbiRead.c
Created March 12, 2015 22:04
UCSC style
struct chromNameCallbackContext
/* Some stuff that the bPlusTree traverser needs for context. */
{
struct bbiChromInfo *list; /* The list we are building. */
boolean isSwapped; /* Need to byte-swap things? */
};
static void chromNameCallback(void *context, void *key, int keySize, void *val, int valSize)
/* Callback that captures chromInfo from bPlusTree. */
{
@superbobry
superbobry / gist:802449
Created January 30, 2011 02:27
a sketch of HTTP Digest Mixin for Tornado
# -*- coding: utf-8 -*-
"""
Incomplete RFC 2617 implementation for Tornado web server [1], originally
implemeted as `curtain` by Brian K. Jones [2].
[1] http://tornadoweb.org
[2] http://github.com/bkjones/curtain
"""
@superbobry
superbobry / gist:1104021
Created July 25, 2011 12:28
CoffeeScript awesomeness!
coffee> f = ([x, y]) -> x + y
[Function]
coffee> f([1, 2])
3
coffee> f = ({x, y}) -> x + y
[Function]
coffee> f({x: 1, y: 2})
3
>>> map(lambda (x, y): x + y, ([1, 2], [3, 4]))
[3, 7]
>>> map(lambda (x, y): x + y, [xrange(2)])
[1]
>>> def g():
... yield 1
... yield 2
...
>>> map(lambda (x, y): x + y, [g()])
[3]
@superbobry
superbobry / gist:1316541
Created October 26, 2011 14:39
fetch a list of depends from _oasis file
#use "topfind"
#require "oasis.base"
open OASISTypes
open OASISVersion
let (|>) x f = f x
let find_all_depends =
let rec inner acc = function
@superbobry
superbobry / gist:1362119
Created November 13, 2011 13:37
Small ints in PyPy and CPython
# PyPy
>>>> 0 is 0
True
>>>> x = 0
>>>> x is 0
False
# CPython
>>> 0 is 0
True