Skip to content

Instantly share code, notes, and snippets.

View jnrbsn's full-sized avatar

Jonathan Robson jnrbsn

View GitHub Profile
@jnrbsn
jnrbsn / Jonathan_Robson_Resume.md
Created December 12, 2012 15:10
A Markdown version of my resume.

Jonathan Robson

8918 W 64th Pl, Apt 203 / Merriam, KS 66202
816-200-7301 / [email protected]

Objective

To obtain a position working with web technologies that leverages my skills,

@jnrbsn
jnrbsn / squarize.php
Created December 19, 2012 03:12
Calculates the "busiest" square area of an image to use for a thumbnail.
<?php
/**
* An example of how to use the `squarize()` function below.
*/
$path_input = 'input.png';
$path_output = 'output.png';
$thumb_w = 100;
$thumb_h = 100;
@jnrbsn
jnrbsn / AtomicParsley.php
Created December 19, 2012 03:27
Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files via PHP.
<?php
/**
* Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files.
*
* Dependencies:
* - Bunsen <http://github.com/jnrbsn/bunsen>
* - AtomicParsley <http://atomicparsley.sourceforge.net/>
*/
class AtomicParsley
@jnrbsn
jnrbsn / httpd.php
Created December 19, 2012 03:41
The beginnings of a really simple web server written in PHP.
<?php
error_reporting(-1);
set_time_limit(0);
$host = '0.0.0.0';
$port = 12345;
$max_clients = 10;
// Create the socket.
@jnrbsn
jnrbsn / Outy.php
Created December 19, 2012 03:56
Objected-oriented command line output library for PHP.
<?php
/**
* Objected-oriented command line output library for PHP.
*
* Dependencies:
* - Console_Color PEAR package
* - Bash
*
* PHP version 5
*
@jnrbsn
jnrbsn / sleep.java
Created May 28, 2013 14:13
Sleep in Java
try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); }
@jnrbsn
jnrbsn / privatemethod.py
Last active May 30, 2018 08:26
Python decorator for making an instance method private
import inspect
def privatemethod(func):
"""decorator for making an instance method private"""
def func_wrapper(*args, **kwargs):
"""decorator wrapper function"""
outer_frame = inspect.stack()[1][0]
if 'self' not in outer_frame.f_locals or outer_frame.f_locals['self'] is not args[0]:
raise Exception('%s.%s is a private method' % (args[0].__class__.__name__, func.__name__))
func(*args, **kwargs)
@jnrbsn
jnrbsn / gist:8062545
Created December 20, 2013 22:18
Install Python 2.7, easy_install, and pip on Amazon Linux
sudo yum update
sudo yum install python27
curl https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py | sudo /usr/bin/python27
sudo easy_install pip
echo "alias python='python27'" >> ~/.bashrc
source ~/.bashrc
@jnrbsn
jnrbsn / redis_pubsub.py
Created June 18, 2014 17:03
Re-establish a redis pubsub connection after losing it
import time
from redis import StrictRedis, ConnectionError
channels = ['test']
redis = StrictRedis()
pubsub = redis.pubsub()
pubsub.subscribe(channels)
while True:
try:
for item in pubsub.listen():
def degrees_to_direction(degrees):
"""Convert degrees to a compass direction."""
directions = [
'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW',
]
return directions[int(round(float(degrees) / 22.5)) % 16]