Skip to content

Instantly share code, notes, and snippets.

View stefco's full-sized avatar
😳

Stefan Countryman stefco

😳
View GitHub Profile
@stefco
stefco / decorators.py
Created July 10, 2017 15:06
Some useful decorators and classes for Python
# (c) Stefan Countryman 2017
# useful classes and decorators for Python code, particularly python 2.7
def multiprocessing_traceback(func):
"""A decorator for formatting exception traceback into a string to aid in
debugging when using the ``multiprocessing`` module."""
import traceback, functools
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
@stefco
stefco / matlab_dependency_defs.sh
Created March 27, 2017 19:54
Little GNU/Linux shell scripts for finding MATLAB code dependencies real quick 'n dirty
# find filenames of MATLAB functions called in a given script or function; call
# from the MATLAB working directory where functions are defined. takes the
# script to be searched as its argument.
matlab-files-called () {
if (! [ $# -eq 1 ]) || [ "$1"c = -hc ]; then
echo "ERROR: 1 argument required"
echo "Usage: matlab-files-called MATLAB_Script_To_Search.m"
return 1
fi
find . -maxdepth 1 -iname '*.m' \
@stefco
stefco / navigate.sh
Last active January 31, 2017 17:27
Navigate forward and backward in bash like a browser
# functions for navigating forward and backward
NAVIGATION_FWD=()
NAVIGATION_BWD=()
navigate_forward () {
if [ ${#NAVIGATION_FWD[@]} -gt 0 ]; then
NAVIGATION_BWD+=("$(pwd)")
cd "${NAVIGATION_FWD[${#NAVIGATION_FWD[@]}-1]}"
unset NAVIGATION_FWD[${#NAVIGATION_FWD[@]}-1]
fi
}
@stefco
stefco / vigit.sh
Created November 3, 2016 21:36
Vim edit, git add, commit, push loop functions
# git add, commit, and push
gadcmtpu () {
if ! [ $# -eq 1 ]; then
echo "ERROR: 1 argument required"
echo "Usage: gadcmtpu filename"
exit 1
fi
echo 'COMMITTING AND PUSHING.'
echo 'CURRENT STATUS:'
echo
#!/usr/bin/env bash
sudo port install bash bash-completion
sudo port install vim
sudo port install git
sudo port install julia
sudo port install py27-jupyter
@stefco
stefco / macsetup.sh
Last active July 1, 2017 12:12
This installs everything you need to work with LIGO on a Mac
#!/usr/bin/env bash
# ligo stuff taken from https://wiki.ligo.org/DASWG/MacPorts and other sources
# run this as an admin but not as root.
# Use shellcheck for linting: http://www.shellcheck.net/#
set -o errexit
set -o nounset
set -o noclobber
cat <<NOTES
@stefco
stefco / newblanksite
Created July 15, 2016 16:33
Make a new website from a template in some folder, and replacing a placeholder string with the customer's name
#!/bin/bash
#------------------------------------------------------------------------------
# HELP INFO
#------------------------------------------------------------------------------
#
# example usage: make a new web site in a folder called "new_site" for someone
# named Rachel Bronstein:
#
# newblanksite new_site 'Rachel Bronstein'
@stefco
stefco / imessage
Created May 30, 2016 03:35 — forked from aktau/imessage
Send iMessage from the commandline
#!/bin/sh
if [ "$#" -eq 1 ]; then stdinmsg=$(cat); fi
exec <"$0" || exit; read v; read v; read v; exec /usr/bin/osascript - "$@" "$stdinmsg"; exit
-- another way of waiting until an app is running
on waitUntilRunning(appname, delaytime)
repeat until my appIsRunning(appname)
tell application "Messages" to close window 1
delay delaytime
end repeat
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# bash script template by Stefan Countryman
# fill in the blanks as you go, crossing out todos as you finish them
# check your code for common mistakes with ShellCheck linter!
# browser-based: http://www.shellcheck.net/#
# install: https://github.com/koalaman/shellcheck#user-content-installing
# TODO: WRITE SCRIPT SUMMARY HERE
#------------------------------------------------------------------------------
@stefco
stefco / sexpr.jl
Created May 10, 2016 00:36 — forked from toivoh/sexpr.jl
lispy AST printer and reader
# ---- @sexpr: S-expression to AST conversion ----
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head))
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n
macro sexpr(ex)
esc(sexpr_to_expr(ex))
end
sexpr_to_expr(ex) = expr(:quote, ex)