Skip to content

Instantly share code, notes, and snippets.

@indraniel
indraniel / toy-bleve-goleveldb-test.go
Last active January 22, 2020 09:02
A test bleve program that uses goleveldb as its backend storage
package main
// goleveldb test
// mentioned in bleve google group
// https://groups.google.com/forum/#!topic/bleve/aHZ8gmihLiY
//
// Based on an earlier toy program using bleve defaults (including BoltDB):
// https://gist.github.com/indraniel/8108bd7def9b5e222417
import (
@indraniel
indraniel / filter-sra-submission-receive-date.pl
Created June 4, 2015 17:08
Filter for NCBI SRA documents (produced by "srasearch init-dump/increment-dump") that have have been "Received" after a certain time point
#!/usr/bin/env perl
use warnings;
use strict;
use DateTime;
use DateTime::Format::Strptime;
use IO::Uncompress::Gunzip qw($GunzipError);
use JSON;
@indraniel
indraniel / tikz2pdf-notes.txt
Created July 27, 2015 17:53
Notes about using tikz2pdf
Including TikZ Pictures
=======================
In the following, I describe how I include TikZ pictures in my LaTeX
documents. I decided to put every figure into a separate file, which
I name e.g. "foo.tikz". The advantages of this approach are:
- One can compile the .tikz file on its own, i.e. editing and fiddling
around with it until the figure is "done", without compiling the whole
main document. (For this, I use tikz2pdf_, as described below.)
@indraniel
indraniel / poli-sci-gantt.r
Created July 27, 2015 18:49
A "hierarchical" gantt chart example
library(ggplot2)
# Taken from:
# http://stackoverflow.com/questions/24636031/ggplot-geom-segment-sorting-y-axis-labels-factors-according-to-value-of-var
# D A T A #####################################################################
CoW.tmp<-structure(
list(
conflict.end = structure(
c(788 , -2178, -1310, 3648 , 5921 , 6569 , 12793, 12793, 6496 , 8881 , 7695 , 9609 , 8354 ,
@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)
@indraniel
indraniel / setup-https.md
Last active August 29, 2015 14:25
A set of notes on setting up https

There are lots of buzzwords and acronyms. Here is a brief description of the main ones.

    https - http secure, uses TLS for transmission
    
    TLS - Transport Layer Security (successor to SSL), communications are encrypted
    
    Private Key - Generated key, known only to the host

Identity Certificate - digital file that provides assurance the host is not an imposter

@indraniel
indraniel / optionally-handle-gzip-files.py
Last active August 29, 2015 14:26
how to optionally handle and decompress gzipped input files on the fly with python
#!/usr/bin/python
from __future__ import print_function
import gzip
class GZopen(object):
def __init__(self, filename):
f = open(filename)
# the file type can be determined with the first 2 bytes
magic_number = f.read(2)
@indraniel
indraniel / bash-array-c-style-iteration.sh
Created August 20, 2015 17:16
A C-style loop iteration in bash
#!/bin/bash
declare -a arr=("echo 'hi'" "echo 'hello'")
for (( i = 0; i < ${#arr[@]} ; i++ )); do
printf "\n**** Running: ${arr[$i]} *****\n\n"
# Run each command in array
eval "${arr[$i]}"
done
@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 / vcf-subpopulation-annotate.go
Created September 10, 2015 14:28
annotate a VCF with allelic frequency information (AF, AC, & AN) on total and subpopulation sets
package main
/*
Building & Usage
----------------
go build -o foo subpopulation-annotate.go
./foo --in /path/to/input/test.vcf --sample-population-map /path/to/20120131-omni-2141-sample-superpopulation.dat --out /path/to/out.vcf.gz
Where "20120131-omni-2141-sample-superpopulation.dat" is a tsv file like: