Skip to content

Instantly share code, notes, and snippets.

View mlsteele's full-sized avatar

Miles Steele mlsteele

View GitHub Profile
#!/usr/bin/env python
import sys
import subprocess
import netifaces
if __name__ == "__main__":
ipv4 = netifaces.ifaddresses('wlan0')[netifaces.AF_INET][0]['addr']
print ipv4
if len(sys.argv) > 1:
subprocess.Popen(["sm", "-f", "#000", "-b", "#DDD", " {} ".format(ipv4)])
@mlsteele
mlsteele / classifier.scala
Last active October 10, 2015 22:25
classifier.scala
object SententialCalculus {
// Here is a scala program which classifies an SC sentence.
// It recognizes whether the sentence is an SC sentence,
// and returns the parsed typed tree.
// You can run this with the following command, but here's
// an executive summary.
// fsc -d build classifier.scala && scala -classpath build SententialCalculus
// Executive summary:
// If the input is a single predicate atom, this is an atom.
// If the input starts with a NOT, this is a negation.
@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).
@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 / 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 / ec
Created February 4, 2016 02:11
Launch emacs real quick with `ec`
#!/usr/bin/env bash
(emacsclient -c "$@" &)
@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 / 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 / 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 / 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