Skip to content

Instantly share code, notes, and snippets.

View scottrogowski's full-sized avatar

Scott Rogowski scottrogowski

View GitHub Profile
@scottrogowski
scottrogowski / add_gradient.cpp
Last active October 10, 2021 07:21
Add a gradient to an image using c++ and opencv
/*
To compile:
$ g++ gradient_adder.cpp -lm -lopencv_core -lopencv_highgui -lopencv_imgproc -o gradient_adder
To run:
$ ./gradient_adder non_grad_image.png
This will take a black and white input image and seperately apply opposite up/down
gradients to the white and the black portions
*/
@scottrogowski
scottrogowski / pixelate_to_nes
Created July 15, 2015 19:34
Pixelate to NES colors
#!/usr/bin/env python
# This script will take a jpg or png image, pixelate it, and convert those "pixels" to NES colors
# NES colors are the 54 colors available in the original Nintendo color palette
#
# To calculate which color to lock to, the LAB color space is used which is
# better than RGB for calculating the "distance" between two colors
#
# Still, the distance metric could use some work. Some colors choices are puzzling.
# It is a TODO
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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