Skip to content

Instantly share code, notes, and snippets.

View nvictus's full-sized avatar

Nezar Abdennur nvictus

  • UMass Chan Medical School
  • Greater Boston Area
View GitHub Profile
@nvictus
nvictus / discreternd.py
Last active September 5, 2016 21:38
Sample a discrete distribution (i.e. simulate a loaded die) efficiently via the "alias sampling" method
"""
Alias sampler
=============
See : <http://www.keithschwarz.com/darts-dice-coins/> by Keith Schwarz.
References
----------
+ Vose, Michael D.
@nvictus
nvictus / ucsc.py
Created August 26, 2016 21:02
UCSC fetcher
# -*- coding: utf-8 -*-
"""
Request snapshots from the UCSC Genome Browser.
"""
from __future__ import division, print_function, unicode_literals
from collections import OrderedDict
import sys
import re
@nvictus
nvictus / loadnpy.js
Last active November 4, 2023 18:47
NumPy binary file parser for javascript
// Client-side parser for .npy files
// See the specification: http://docs.scipy.org/doc/numpy-dev/neps/npy-format.html
var NumpyLoader = (function () {
function asciiDecode(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
function readUint16LE(buffer) {
var view = new DataView(buffer);
var val = view.getUint8(0);
@nvictus
nvictus / post_mortem_hook.py
Created August 7, 2016 07:15
Post mortem exception hook with ipdb
def set_postmortem_hook():
import sys, traceback, ipdb
def _excepthook(exc_type, value, tb):
traceback.print_exception(exc_type, value, tb)
print()
ipdb.pm()
sys.excepthook = _excepthook
@nvictus
nvictus / runlength.py
Last active October 7, 2023 19:54
NumPy run-length encoding / decoding
"""Run Length Encoding utilities for NumPy arrays.
Authors
-------
- Nezar Abdennur
- Anton Goloborodko
"""
from __future__ import division, print_function
import numpy as np
@nvictus
nvictus / cooler_example.ipynb
Last active August 11, 2016 00:23
cooler-example
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nvictus
nvictus / lexbisect.py
Last active January 14, 2016 03:35
Bisection search on lexically sorted sequences in Python.
def lexbisect(arrays, values, side='left', lo=0, hi=None):
"""
Bisection search on lexically sorted arrays.
Parameters
----------
arrays : sequence of k 1-D array-like
Each "array" can be any sequence that supports scalar integer indexing,
as long as the arrays have the same length and their values are
lexsorted from left to right.
@nvictus
nvictus / example-ucsc.ipynb
Last active September 2, 2016 06:56
UCSC genome browser to matplotlib
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nvictus
nvictus / gist:240c9e9ee33e20d02a36
Created October 9, 2014 23:19
conda "workon" alias
CONDA_DIR="$HOME/miniconda"
alias workon='source $CONDA_DIR/bin/activate'
# function workon () {
# source "$CONDA_DIR/bin/activate" "$1"
# }
function __conda_user_setup () {
_workon_tab_completion_bash () {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.