Skip to content

Instantly share code, notes, and snippets.

@indraniel
indraniel / python-call-method-from-string.py
Created August 31, 2015 20:31
Python: How to dynamically call a method/function given a string of its name
# Based on reading : http://stackoverflow.com/questions/7936572/python-call-a-function-from-string-name
# http://stackoverflow.com/questions/3061/calling-a-function-of-a-module-from-a-string-with-the-functions-name-in-python
class Foo(object):
def dynamic_call(self, attribute_name):
method_name = 'calculate_' + attribute_name # e.g. given attribute name "baz" call method "calculate_baz"
func = getattr(self, method_name) # find method that located within the class
func() # execute the method
@indraniel
indraniel / toy-bleve-example.go
Last active October 9, 2023 13:05
This is a toy search example using bleve. It also highlights how to retrieve the orignal input document(s) from the KV store.
package main
// mentioned in bleve google group
// https://groups.google.com/forum/#!topic/bleve/-5Q6W3oBizY
import (
"encoding/json"
"fmt"
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/document"
@indraniel
indraniel / tar-gz-reader.go
Created February 23, 2015 19:05
Reading through a tar.gz file in Go / golang
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
)
@indraniel
indraniel / b37-annotate-w-gnomAD.sh
Last active June 30, 2023 03:45
A bash script to annotate a large VCF (i.e. containing many samples) with gnomAD (build 37 edition)
#!/bin/bash
# Usage:
# bash b37-annotate-w-gnomAD.sh </path/to/input.vcf.gz> </path/to/output.vcf.gz>
#
# Note:
# 1. This script with create a "scratch" directory to hold intermediate file
# states created during the annotation process. The scratch directory will
# be created next to the /path/to/outvcf.vcf.gz .
#
@indraniel
indraniel / leveldb.go
Created July 27, 2015 19:21
A simple example of using LevelDB in golang
package main
import (
"fmt"
"github.com/syndtr/goleveldb/leveldb"
"log"
)
func main() {
db, err := leveldb.OpenFile("/tmp/foo.db", nil)

This page is a curated collection of Jupyter/IPython notebooks that are notable for some reason. Feel free to add new content here, but please try to only include links to notebooks that include interesting visual or technical content; this should not simply be a dump of a Google search on every ipynb file out there.

Important contribution instructions: If you add new content, please ensure that for any notebook you link to, the link is to the rendered version using nbviewer, rather than the raw file. Simply paste the notebook URL in the nbviewer box and copy the resulting URL of the rendered version. This will make it much easier for visitors to be able to immediately access the new content.

Note that Matt Davis has conveniently written a set of bookmarklets and extensions to make it a one-click affair to load a Notebook URL into your browser of choice, directly opening into nbviewer.

@indraniel
indraniel / git-bitbucket-with-custom-ssh-key.sh
Created January 18, 2023 20:59
example on how to use a custom ssh key for accessing a bitbucket repository
ssh-keygen -t ed25519 -C "information@food.com"
export GIT_SSH_COMMAND='ssh -i /Users/me/.ssh/id_ed25519_food_bitbucket -o IdentitiesOnly=yes'
@indraniel
indraniel / fork-exec-monitor-eagle.py
Created January 18, 2023 20:55
how to run an external program, in this case the statistical genetics eagle program, and monitor its memory usage with python
#!/opt/hall-lab/python-3.7.0/bin/python -u
import os, sys, time, datetime
import psutil
# add eagle to PATH
os.environ['PATH'] = os.pathsep.join(['/opt/hall-lab/eagle-2.4.1/bin', os.environ['PATH']])
def log(msg):
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %T")
# http://flask.pocoo.org/snippets/88/
import os, sqlite3
from cPickle import loads, dumps
from time import sleep
try:
from thread import get_ident
except ImportError:
from dummy_thread import get_ident
@indraniel
indraniel / download-1000-genomes-vcf.py
Created May 26, 2017 23:08
Python example to download files from an anonymous FTP server (example case from 1000 Genomes)
#!/usr/bin/env python
from __future__ import print_function
import ftplib, datetime, sys
# ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/release/20130502/ALL.chr14.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz
def log(msg):
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %T")
print('[-- {} --] {}'.format(timestamp, msg), file=sys.stderr)