Skip to content

Instantly share code, notes, and snippets.

View bholt's full-sized avatar

Brandon Holt bholt

View GitHub Profile
@bholt
bholt / slurm-ssh
Created March 12, 2015 03:28
Ssh to first allocated node, passing Slurm environment variables through.
#!/bin/bash
# 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"
@bholt
bholt / fmt.py
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.
Example:
@bholt
bholt / spawn.cpp
Created November 19, 2013 03:18
Experimenting with async/balancing syntax for task spawn, parallel loop, etc.
#include <accel-cpp/log.hpp>
#include <boost/variant.hpp>
#include <map>
#include <vector>
#include <sstream>
using namespace std;
enum SyncMode { async, blocking };
enum BalancingMode { none, balancing };
@bholt
bholt / glog.diff
Last active December 25, 2015 13:39
Patch for installing `google-glog` using Clang on OSX.
diff --git a/trunk/src/stl_logging_unittest.cc b/trunk/src/stl_logging_unittest.cc
--- a/trunk/src/stl_logging_unittest.cc (revision 137)
+++ b/trunk/src/stl_logging_unittest.cc (working copy)
@@ -31,17 +31,20 @@
#ifdef HAVE_USING_OPERATOR
-#ifdef __GNUC__
+#include <iostream>
+
#include <mpi.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSWorkspace</key>
<key>SystemConfiguration</key>
<dict>
<key>State:/Network/Global/IPv4</key>
<dict>
<key>command</key>
source ~/grappa/system/grappa_gdb.macros
# blue (gdb) prompt
set prompt \033[0;34m(gdb)\033[0m
shell mkfifo /tmp/bholt_gdb_color_pipe
define hook-backtrace
shell cat /tmp/bholt_gdb_color_pipe | sed -e 's/\(^#[0-9]*.*in \|^#[0-9]*\) \(.*\) \((.*)\)/\1 '$(echo -e '\033[0;33m')'\2 '$(echo -e '\033[0;36m')'\3'$(echo -e '\033[0m')'/' | sed -e 's/\/sampa\/home\/bholt\(\/.*:[0-9]*\)/'$(echo -e '\033[0;32m')'~\1'$(echo -e '\033[0m')'/' &
set logging redirect on
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if git rev-parse --verify HEAD >/dev/null 2>&1
@bholt
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.
# start a new session if there isn't one to attach to already
new-session
# 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
bholt / viz.rb
Created November 16, 2012 20:31
#!/usr/bin/env ruby
require "rubyvis"
vis = Rubyvis::Panel.new do
width 150
height 150
bar do
data [1, 1.2, 1.7, 1.5, 0.7, 0.3]
width 20
height {|d| d * 80}