Skip to content

Instantly share code, notes, and snippets.

View bholt's full-sized avatar

Brandon Holt bholt

View GitHub Profile
bholt /
Last active February 7, 2016 00:08
String interpolation in Python 2 using `eval` and `inspect` to get caller's locals.
import inspect
import re
def fmt(s):
Interpolate arbitrary expressions inside '{}' in strings (similar to Ruby or Scala).
It should go without saying that because this uses `eval`, it is unsafe to use with any user-provided inputs.
It is also probably terribly slow because it's using `inspect` to get the caller's local variables.
bholt / .tmux.conf
Created October 28, 2015 00:45
Put this in your home directory (~/.tmux.conf). Make "ctrl+t" the global tmux shortcut, makes splits easier by creating shortcuts for "ctrl+t, -" to split horizontal and "ctrl+t, |" (pipe) for vertical.
View .tmux.conf
# start a new session if there isn't one to attach to already
# Make global tmux shortcut "ctrl+t"
set -g prefix ^t
# Renumber windows when they're closed so you don't have weird missing numbers.
set-option -g renumber-windows on
# Make colors work right.
bholt /
Created August 18, 2015 01:11
Slurm SSH Script
# usage: slurm-ssh [host] [shell]
# e.g.: salloc -N2 slurm-ssh
# n01 (salloc n[01,04]) >
# or:
# slurm-ssh n01
# or:
# slurm-ssh n01 zsh
bholt / color_scheme.r
Created August 12, 2015 17:49
Custom color scheme for ggplot
View color_scheme.r <- "#0072B2"
c.yellow <- "#E69F00" <- "#009E73" <- "#D55E00" <- "#CC79A7"
c.gray <- "#999999"
palette <- c(
bholt / ConcurrentQueue.hpp
Created July 30, 2015 16:00
Concurrent queue built for single-producer/single-consumer that uses a condition variable to signal consumer.
View ConcurrentQueue.hpp
#include <future>
using namespace std;
template< typename T >
class ConcurrentQueue {
Queue<T> q;
mutex m;
condition_variable cv;
bool closed;
bholt /
Created June 5, 2015 20:13
Keybase proof

Keybase proof

I hereby claim:

  • I am bholt on github.
  • I am bholt ( on keybase.
  • I have a public key whose fingerprint is AEAA C7A8 DE91 8434 B88F 88CD EE4E 54E0 0859 5279

To claim this, I am signing this object:

bholt / slurm-ssh
Created March 12, 2015 03:28
Ssh to first allocated node, passing Slurm environment variables through.
View slurm-ssh
# Usage: salloc <options> slurm-ssh
first=$(scontrol show hostname $SLURM_NODELIST | head -n1)
env=$(printenv | grep SLURM | sed -rn "s/=(.*)/='\1'/p" | paste -d' ' -s)
exec ssh $first -t "$env zsh"
View cpp_cases.cpp
template< typename T >
void work(T t) {
try { throw t; }
catch (int x) { printf("int\n"); }
catch (std::string x) { printf("string\n"); }
int main(int argc, char *argv[]) {
bholt / wc.cpp
Last active August 29, 2015 14:04
Word Count Example
View wc.cpp
forall(words, n, [=](string w) {
// hash partitioning
size_t idx = hash(w) % ncells;
delegate(cells+idx, [=](Cell& cell)
{ // runs atomically
if (cell.count(w) == 0) cell[w] = 1;
else cell[r] += 1;
bholt / graphlab.cpp
Last active August 29, 2015 14:03
Lata code snippet
View graphlab.cpp
GlobalAddress<Graph> g;
// GraphLab synchronous engine: scatter phase
// loop over all vertices in graph
forall(g, [=](Vertex& v){
// only scatter from vertices that have been signaled to do scatter
if (v->active_minor_step) {
v->active_minor_step = false;