Skip to content

Instantly share code, notes, and snippets.

View mlsteele's full-sized avatar

Miles Steele mlsteele

View GitHub Profile
@mlsteele
mlsteele / script.sh
Created November 10, 2016 20:36
Bash Script Header
#!/usr/bin/env bash
set -e # errexit
set -u # nounset
set -x # echo
@mlsteele
mlsteele / ds
Created July 22, 2016 00:32
Detach and silence output while running.
#!/bin/sh
# Run a process silenced and disowned.
# Example Usage: ds firefox
if test -t 1; then
exec 1>/dev/null
fi
if test -t 2; then
exec 2>/dev/null
@mlsteele
mlsteele / observer.py
Created April 30, 2016 02:59
Observer magic
class SimpleStore(object):
"""Dead simple storage. Basically a dictionary."""
def __init__(self):
self.data = {}
def get(self, key):
return self.data[key]
def set(self, key, value):
self.data[key] = value
@mlsteele
mlsteele / zatc
Created March 3, 2016 01:08
Download a PDF from a url and view it in zathura.
#!/usr/bin/env bash
# Launch zathura from a link in your clipboard.
# Requires zatweb.
set -e
URL=$(xclip -selection clipboard -o)
zatweb "$URL"
@mlsteele
mlsteele / jon.sh
Last active March 2, 2016 02:40
Script to continously run go tests.
#!/usr/bin/env bash
# Script to continously run go tests.
# Courtesy of Jon Gjengset.
rm -f results.log
while true; do
echo "Starting trial."
go test -test.timeout 80s 2>run.err | tee run.log | grep -P '^(--- )?FAIL|Passed|^Test:|^ok' | tee -a results.log;
if grep FAIL run.log; then
@mlsteele
mlsteele / centroid.py
Created February 27, 2016 02:13
Find the centroid of a 2D array.
import numpy as np
print "\n\n"
# Width and height of the image.
W = 5
H = 5
# Generate a random image.
x = np.random.rand(W, H) > 0.5
@mlsteele
mlsteele / ec
Created February 4, 2016 02:11
Launch emacs real quick with `ec`
#!/usr/bin/env bash
(emacsclient -c "$@" &)
@mlsteele
mlsteele / ngrok-copy
Created January 15, 2016 16:49
Copy the url of the active ngrok connection to the clipboard.
#!/usr/bin/env bash
# Copy the url of the active ngrok connection to the clipboard.
# Usage:
# ngrok-copy # copies e.g. https://3cd67858.ngrok.io to clipboard.
# ngrok-copy -u # copies e.g. http://3cd67858.ngrok.io to clipboard.
if [[ "$1" == "-u" ]]; then
NGROK_URL=`curl -s http://127.0.0.1:4040/status | grep -P "http://.*?ngrok.io" -oh`
else
NGROK_URL=`curl -s http://127.0.0.1:4040/status | grep -P "https://.*?ngrok.io" -oh`
@mlsteele
mlsteele / google-chrome-touch
Created January 12, 2016 17:12
Start google chrome with the right X touch input device.
#!/usr/bin/env bash
# Start google-chrome with the right X touch input device.
TOUCHID=`xinput list | ag touchscreen | grep -P "id=\K\d+" -o`
google-chrome --touch-devices=$TOUCHID
@mlsteele
mlsteele / xorp.py
Created December 30, 2015 05:14
xorp: A wrapper for ssh reverse tunneling.
#!/usr/bin/env python
"""
Create a reverse proxy tunnel from a remote host back to localhost.
Useful for sharing local services with people who can only access the remote host.
You may need to add the line
GatewayPorts yes
to the /etc/ssh/sshd_config of the remote.
And then restart the ssh service (sudo service ssh restart).