Skip to content

Instantly share code, notes, and snippets.

@nhoffman
nhoffman / tmux-notes.org
Last active April 3, 2017 17:16
My tmux notes

tmux notes

sessions

Create a new session then rename it:

C-b :new
C-b $

Create a new named session:

@nhoffman
nhoffman / SConstruct.py
Last active March 18, 2019 20:45
SConstruct template
import os
import sys
# Ensure that a virtualenv is active before importing non-stdlib dependencies.
venv = os.environ.get('VIRTUAL_ENV')
if not venv:
sys.exit('--> an active virtualenv is required'.format(venv))
from SCons.Script import (Environment, Variables, Help, Decider)
@nhoffman
nhoffman / ssh-tunnel.sh
Last active August 28, 2017 16:40
open an ssh tunnel and point a browser to it
#!/bin/bash
# Requires argparse.bash (https://github.com/nhoffman/argparse-bash)
# in the same directory as this script
# Installation:
# cd ~/bin # or another location on your $PATH
# curl https://gist.githubusercontent.com/nhoffman/8636c6e267cb4403ac3a35ff0bc53f3d/raw/ > ssh-tunnel
# chmod +x ssh-tunnel
# curl -O https://raw.githubusercontent.com/nhoffman/argparse-bash/master/argparse.bash
#!/usr/bin/python2.7
"""
Performs a web BLAST query against NR using DNA sequences read from a fasta
file, storing the results in a SQLite database.
Dependencies: BioPython
BioPython may be installed using the Python package index:
$ sudo easy_install -f http://biopython.org/DIST/ biopython
@nhoffman
nhoffman / incremental_backup.sh
Last active June 16, 2016 21:51
Incremental backup using rsync
#!/bin/bash
# Incremental backup using rsync
# see http://www.mikerubel.org/computers/rsync_snapshots/#Incremental
set -e
BACKUP_DIR=backup
rot_cycle_days=7 # for example
@nhoffman
nhoffman / knitr-cli.R
Created March 17, 2016 04:08
knit R markdown files
#!/usr/bin/env Rscript
if(Sys.getenv("VIRTUAL_ENV") == ""){ stop("An active virtualenv is required") }
source(file.path(Sys.getenv('VIRTUAL_ENV'), 'bin', 'rvenv'))
suppressPackageStartupMessages(library(argparse, quietly = TRUE))
suppressPackageStartupMessages(library(rmarkdown, quietly = TRUE))
main <- function(arguments){
import os
import sys
import ConfigParser
from os import path, environ
import glob
import itertools
venv = environ.get('VIRTUAL_ENV')
if not venv:
sys.exit('--> an active virtualenv is required'.format(venv))
@nhoffman
nhoffman / sshmount
Last active August 29, 2015 14:10
bash function for mounting a directory via sshfs
sshmount () {
# Usage: sshmount host directory
host=$1
pth=$2
mountpoint=~/mnt/${host}+$(basename $pth)
mkdir -p $mountpoint
sshfs $host:$pth $mountpoint -oauto_cache,reconnect,defer_permissions,negative_vncache,volname=${host}+$(basename $pth)
cd $mountpoint
echo "unmount using: umount $mountpoint"
}
@nhoffman
nhoffman / script.R
Created April 24, 2014 19:11
An R script template
#!/usr/bin/env Rscript
suppressPackageStartupMessages(library(lattice, quietly = TRUE))
suppressPackageStartupMessages(library(latticeExtra, quietly = TRUE))
suppressPackageStartupMessages(library(argparse, quietly = TRUE))
main <- function(arguments){
parser <- ArgumentParser()
parser$add_argument('infile')
@nhoffman
nhoffman / build_wheels.py
Last active August 29, 2015 13:59
Create python wheels
#!/bin/bash
set -e
REQFILE="${1-requirements.txt}"
WHEELSTREET="${2-wheelstreet}" # base dir for wheel dirs
if [[ ! -f "$REQFILE" ]]; then
echo "Cannot find requirements file named $REQFILE"
echo "Usage: $(basename $0) [requirements.txt] [wheelstreet]"