Skip to content

Instantly share code, notes, and snippets.

View walkerh's full-sized avatar

Walker Hale IV walkerh

  • Baylor College of Medicine, HGSC
  • Houston, TX
View GitHub Profile
@walkerh
walkerh / scanner.py
Created March 15, 2016 22:52
Recursively scan the specified directory, emitting manifest of files.
#!/usr/bin/env python3
"""Recursively scan the specified directory, emitting manifest of files.
Writes to file or stdout.
Requires Python 2.7+
"""
import argparse
from hashlib import md5 as hash
@walkerh
walkerh / wh_lib.py
Created March 15, 2016 22:56
Utility code for data wrangling
import collections
import csv
import glob
import itertools
import locale
import operator
import os
import pprint
import re
import sys
@walkerh
walkerh / tar_demo.sh
Last active August 9, 2016 19:45
Demonstration of copying files from disparate directories into a synthetic directory inside a new tarball. Note that most of this code is just setting up some files and directories to demonstrate the power. Focus your attention on the "xargs tar" command on line 19.
# Copying files from disparate directories into a single tarball
# with a synthetic root directory:
# Setup some dummy directory structure for the demo:
DEMO_DIR=/tmp/tar-demo
mkdir -p $DEMO_DIR
cd $DEMO_DIR
mkdir -p a/1/d a/1/e b/2 b/3 c
xargs touch <<EOD
a/1/d/foo
@walkerh
walkerh / test_demo.py
Created January 10, 2018 16:56
Demonstrate pytest fixture scoping and parameterization
# Just run 'pytest' from the directory containing this file.
from pytest import fixture
def test_a(foo):
assert 0, foo
def test_b(foo):
@walkerh
walkerh / pbedit.sh
Last active July 31, 2018 14:28 — forked from TooTallNate/pbedit.sh
`pbedit` command: Edit the clipboard in your $EDITOR
#!/bin/bash
# macOS tool to edit the contents of the clipboard in the default text editor
# If your editor supports pipelining it can simplify to:
# pbpaste | $EDITOR | pbcopy
# pbpaste | mate -w | pbcopy # example
tmpfile=`mktemp`
pbpaste > $tmpfile
$EDITOR $tmpfile
@walkerh
walkerh / context_manager_demo.py
Created January 21, 2019 01:59
Context manager demo in Python 3.7
# Using this bash function (for color):
# color()(set -o pipefail;"$@" 2>&1>&3|sed $'s,.*,\e[31m&\e[m,'>&2)3>&1
# repeat each section by pasting after this:
# color python; echo $?
#
# Notice how ctx1 never does the correct cleanup by printing "exiting".
# Defining a context manager class.
class CTX:
@walkerh
walkerh / repeating_letters.ipynb
Last active April 7, 2019 14:13
Demonstration of grouping by repeating letters in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@walkerh
walkerh / issues.ipynb
Last active August 12, 2020 16:06
A generic class for issues based on addict
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@walkerh
walkerh / group_by.ipynb
Last active March 30, 2022 16:22
Combining Aggregation With Column Update
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@walkerh
walkerh / fillna.ipynb
Created March 31, 2023 21:21
Attempts to fix missing data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.