Skip to content

Instantly share code, notes, and snippets.

@indraniel
indraniel / tar-gz-reader.go
Created Feb 23, 2015
Reading through a tar.gz file in Go / golang
View tar-gz-reader.go
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
)
@indraniel
indraniel / python-call-method-from-string.py
Created Aug 31, 2015
Python: How to dynamically call a method/function given a string of its name
View python-call-method-from-string.py
# 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 / read-file.scm
Created Jul 17, 2017
An example file reading script with chicken scheme
View read-file.scm
#!/usr/bin/env csi -ss
;; An example file reading script with chicken scheme
(use extras)
(define (read-it file)
(let ((fh (open-input-file file)))
(let loop((c (read-line fh)))
(if (eof-object? c)
@indraniel
indraniel / style_guide.md
Created Sep 10, 2021 — forked from scottfrazer/style_guide.md
WDL Best Practices / Style Guide
View style_guide.md

"My First WDL" Template

task name {
  String in
  command {
    echo '${in}'
  }
  output {
    String out = read_string(stdout())
@indraniel
indraniel / tumblr-download.go
Last active Sep 5, 2021
A golang program to download pictures from a tumblr blog page
View tumblr-download.go
/*
This is a go program to download pictures from a tumblr blog page.
To Build:
go build -o tumblr-download tumblr-download.go
To Run:
# download the photos on the first page of tumblr blog
@indraniel
indraniel / leveldb.go
Created Jul 27, 2015
A simple example of using LevelDB in golang
View leveldb.go
package main
import (
"fmt"
"github.com/syndtr/goleveldb/leveldb"
"log"
)
func main() {
db, err := leveldb.OpenFile("/tmp/foo.db", nil)
@indraniel
indraniel / toy-bleve-example.go
Last active Apr 21, 2021
This is a toy search example using bleve. It also highlights how to retrieve the orignal input document(s) from the KV store.
View toy-bleve-example.go
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"
View jupyter_notebooks_collections.md

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 / sort-list-of-dictionaries.py
Created Sep 23, 2015
python: approaches to sort a list of dictionaries
View sort-list-of-dictionaries.py
#!/usr/bin/python
from __future__ import print_function
# from https://wiki.python.org/moin/SortingListsOfDictionaries
def multikeysort(items, columns):
from operator import itemgetter
comparers = [ ((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
def comparer(left, right):
for fn, mult in comparers:
@indraniel
indraniel / download-1000-genomes-vcf.py
Created May 26, 2017
Python example to download files from an anonymous FTP server (example case from 1000 Genomes)
View download-1000-genomes-vcf.py
#!/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)