Skip to content

Instantly share code, notes, and snippets.

@indraniel
indraniel / gist:865818e29fb806c5907e
Created January 26, 2015 04:06
Playing around with golang's reflection package. Based on reading http://blog.golang.org/2011/09/laws-of-reflection.html
package main
import "reflect"
import "fmt"
type T struct {
A int
B float64
C int32
D string
@indraniel
indraniel / confusion-matrix.tex
Last active August 29, 2015 14:14
A basic bare-bones 2x2 contingency table, or confusion matrix
\documentclass{standalone}
% setup an alternative font
\usepackage[T1]{fontenc}
\usepackage[charter]{mathdesign} % Math font
\usepackage[sfdefault]{FiraSans} % Sans-serif font
% for the drawings
\usepackage{tikz}
@indraniel
indraniel / serve.go
Last active August 29, 2015 14:15
A rudimentary file and directory server
/* See other alternatives as well:
https://github.com/rif/spark
https://github.com/mholt/caddy
https://github.com/GokulSrinivas/go-http
*/
package main
import (
"flag"
@indraniel
indraniel / check.go
Last active August 29, 2015 14:16
check if a file exists on the file system
// approach 1
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
// approach 2
if _, err := os.Stat("/path/to/whatever"); err == nil {
// path/to/whatever exists
}
@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 / 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)
#!/usr/bin/perl
print "Hello World!\n";
exit(0);