Skip to content

Instantly share code, notes, and snippets.

@indraniel
indraniel / gist:865818e29fb806c5907e
Created Jan 26, 2015
Playing around with golang's reflection package. Based on reading http://blog.golang.org/2011/09/laws-of-reflection.html
View gist:865818e29fb806c5907e
package main
import "reflect"
import "fmt"
type T struct {
A int
B float64
C int32
D string
@indraniel
indraniel / confusion-matrix.tex
Last active Aug 29, 2015
A basic bare-bones 2x2 contingency table, or confusion matrix
View confusion-matrix.tex
\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 Aug 29, 2015
A rudimentary file and directory server
View serve.go
/* 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 Aug 29, 2015
check if a file exists on the file system
View check.go
// 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 Jun 4, 2015
Filter for NCBI SRA documents (produced by "srasearch init-dump/increment-dump") that have have been "Received" after a certain time point
View filter-sra-submission-receive-date.pl
#!/usr/bin/env perl
use warnings;
use strict;
use DateTime;
use DateTime::Format::Strptime;
use IO::Uncompress::Gunzip qw($GunzipError);
use JSON;
@indraniel
indraniel / setup-https.md
Last active Aug 29, 2015
A set of notes on setting up https
View setup-https.md

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 / poli-sci-gantt.r
Created Jul 27, 2015
A "hierarchical" gantt chart example
View poli-sci-gantt.r
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 / tikz2pdf-notes.txt
Created Jul 27, 2015
Notes about using tikz2pdf
View tikz2pdf-notes.txt
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 / optionally-handle-gzip-files.py
Last active Aug 29, 2015
how to optionally handle and decompress gzipped input files on the fly with python
View optionally-handle-gzip-files.py
#!/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 Aug 20, 2015
A C-style loop iteration in bash
View bash-array-c-style-iteration.sh
#!/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