Skip to content

Instantly share code, notes, and snippets.

View mplewis's full-sized avatar
🐕
柴犬

Matt Lewis mplewis

🐕
柴犬
View GitHub Profile
@mplewis
mplewis / snowjob.py
Created December 24, 2012 06:42 — forked from sontek/snowjob.py
#!/usr/bin/env python
import os
import random
import time
import platform
snowflakes = {}
try:
# Windows Support
@mplewis
mplewis / hue.py
Created December 24, 2012 07:53
gibe money plox. This is just for fun, really.
#!/usr/bin/python2
# GIBE MONY PLOX. -mplewis
import random
import sys
from time import sleep
from math import log
numHue = 100 # LOL THIS DOESN'T MATTER
@mplewis
mplewis / chanTube.py
Created December 26, 2012 05:21
Opens all YouTube links in a 4chan thread in a browser window.
#!/usr/bin/env python2
# this script grabs all youtube links in a 4chan thread and opens them in your browser.
# the regex is probably pretty shitty but it seems to work
# i dunno if it handles more than one youtube link in a post because i'm lazy
# usage:
# python chanTube.py [threadUrl]
# example:
# python chanTube.py http://boards.4chan.org/v/res/168482467
@mplewis
mplewis / threePipeDemo.c
Created March 31, 2013 01:31
Here's an example of how to pipe three commands together using C. This one uses `ps aux | grep root | grep sbin`. This topic is horribly documented online so hopefully this'll help someone else out.
// This program is an example of how to run a command such as
// ps aux | grep root | grep sbin
// using C and Unix.
#include <stdlib.h>
#include <unistd.h>
int pid;
int pipe1[2];
int pipe2[2];
import Image
from collections import Counter
IMAGE_FILE = 'testris_fb.png'
def get_tetris_vert_bounds_from_img(img):
'''Returns the left and right crop boundaries of an image of the player's Tetris Battle board.'''
img_width, img_height = img.size
left_tri_black_coords = []
@mplewis
mplewis / list_macs.py
Created June 10, 2013 21:44
quick and dirty python script (the best kind) to list all MACs on the LAN and their associated IPs
import os, time, subprocess
def run_command_silently(command):
with open(os.devnull, 'wb') as devnull:
subprocess.check_call(command.split(' '), stdout=devnull, stderr=subprocess.STDOUT)
run_command_silently('ping -c 1 255.255.255.255')
time.sleep(0.5)
arp_entries = subprocess.check_output(('arp','-na')).splitlines()
all_ip_and_macs = []
@mplewis
mplewis / google_latitude_api_access.py
Created July 14, 2013 03:54
A script that downloads your Google Latitude data and saves it into separate JSON files. Check out my blog post on this: http://www.mplewis.com/octopress/blog/2013/07/13/downloading-your-google-location-history-with-the-google-api-python-client-library/
#!/usr/bin/python
import httplib2
import json
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
from datetime import datetime
#!/usr/bin/env python
import os
import sys
# print_compact_dir recursively prints the contents of the directory with indentation and without stuttering.
# If the only contents of a given directory are another single directory, that single directory is concatenated instead of indented on the next line.
def print_compact_dir(root, route, level, spacing=4):
dir_path = os.path.join(root, route)
contents = os.listdir(dir_path)
@mplewis
mplewis / flask-uwsgi-nginx-primer.md
Last active October 24, 2022 19:20
Flask + uWSGI + nginx Primer. I've been having trouble with serving a Flask app via uWSGI and nginx, so I thought I'd put together some of the basics to help out others.

Flask + uWSGI + nginx Primer

I've been having trouble with serving a Flask app via uWSGI and nginx, so I thought I'd put together some of the basics to help out others.

How this shit works

  • Flask is managed by uWSGI.
  • uWSGI talks to nginx.
@mplewis
mplewis / dockerApi.js
Created December 31, 2013 00:03
doodling with node.js <—> Docker REST socket
var http = require('http');
var SOCKET_PATH = '/var/run/docker.sock';
var dockerConn = {
get: function(path, callback) {
var options = {
socketPath: SOCKET_PATH,