Skip to content

Instantly share code, notes, and snippets.

View scottrogowski's full-sized avatar

Scott Rogowski scottrogowski

View GitHub Profile
@scottrogowski
scottrogowski / one_line_spiral.py
Last active August 29, 2015 14:15
Single expression one line python spiral
# This prints a spiral onto the terminal.
# It is composed of a few list comprehensions, a few ternary expressions, and a y-combinator
# The only python keywords used: print, join, in, lambda, if, else, int, and, or, range
# No libraries are used
# It is 308 characters although I think it would be possible to get it under 300
# with some further optimization of the spiral generator. Particularly I think
# it might be possible to build this without storing state recursively at the
# expense of some additional computation. This could be done by finding an
# expression that would map the element index of the spiral to the coordinates
@scottrogowski
scottrogowski / branch.py
Created March 26, 2015 15:44
Better git branch
#!/usr/bin/env python
# This is a better way to do git branch. This orders branches by last modified
# date and prints the branch notes along with the branch.
# Branches with '+' and '_' in front come first
import subprocess
import sys
from dateutil.parser import parse
import os
@scottrogowski
scottrogowski / curljson.py
Created March 26, 2015 15:48
Command line tool to load a json url endpoint into a python datastructure
#!/usr/bin/env python
# Loads json into a python datastructure from a url
# Usage: curljson http://example.com/json_endpoint
# Then the datastructure is accessible via jobj
import json
import sys
from IPython import embed
from subprocess import Popen, PIPE
@scottrogowski
scottrogowski / i.p
Created March 26, 2015 15:54
Open a IPython REPL using the arguments as libraries to be imported
#!/usr/bin/env python
# Open a IPython REPL using the arguments as libraries to be imported via `import *`.
# Also imports a few stdlib libraries
# For example:
# $ i lib/lib_to_be_imported.py
# does
# from lib.lib_to_be_imported import *
# before the REPL starts
@scottrogowski
scottrogowski / json_loader
Created March 26, 2015 15:56
Loads the json contents of the clipboard as a python datastructure
#!/usr/bin/env python
# Loads the json contents of the clipboard as a python datastructure called jobj
import sys
import json
from IPython import embed
if __name__ == "__main__":
f_name = sys.argv[1]
@scottrogowski
scottrogowski / memprof
Last active August 29, 2015 14:17
Continuously poll the memory usage of a process
#!/bin/bash
# Usage: memprof PID#
# Continuously poll the memory usage of a process
top -l 0 -s 1 -pid $1 -stats VSIZE | awk 'NR%13==0; fflush(stdout)' | ts
@scottrogowski
scottrogowski / note
Created March 26, 2015 16:01
Set a note on the current git branch using command line arguments
#!/usr/bin/env python
# Set a note on the current git branch using command line arguments
# Usage: note this branch is broken
import sys
import subprocess
import json
if __name__ == '__main__':
@scottrogowski
scottrogowski / sharefolder
Created March 26, 2015 16:04
Share the files in the folder over the network printing the ip address they can be found at
#!/bin/bash
ip=`ifconfig -r en0 inet | sed -E '/en0/d;s/inet[ \t]([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).+/\1/'`
ip=`echo $ip | tr -d '[:space:]'`
echo "The files in this directory are being served! Go to $ip:8000 in a browser on your local network. When you are done, use ctrl-c to exit"
python -m SimpleHTTPServer 8000
@scottrogowski
scottrogowski / safepush
Created March 26, 2015 16:08
Do some cursory checks before pushing the branch to `origin <branch_name>`
#!/usr/bin/env python
# Do some cursory checks before pushing the branch to `origin <branch_name>`
# Checks that no debuggers, TODOs, or print statements are in the branch diff before pushing
# Also checks that there are no saved but uncommitted files in git status
import subprocess
import sys
def execute(cmd):
@scottrogowski
scottrogowski / pixelate.py
Last active May 29, 2024 05:41
Pixelate image in python
#!/usr/bin/env python
# This script will pixelate most jpg and png images
# It will both show you the result and save it
import sys
import matplotlib.pyplot as plt
import numpy as np
import PIL.Image as Image