Skip to content

Instantly share code, notes, and snippets.

Jonathan Robson jnrbsn

Block or report user

Report or block jnrbsn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jnrbsn
jnrbsn / whereivebeen.geojson
Last active Aug 29, 2015
This is everywhere I've ever checked in or tagged on Foursquare, Facebook, and/or Instagram.
View whereivebeen.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View markets.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View degrees_to_direction.py
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]
@jnrbsn
jnrbsn / redis_pubsub.py
Created Jun 18, 2014
Re-establish a redis pubsub connection after losing it
View redis_pubsub.py
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():
@jnrbsn
jnrbsn / gist:8062545
Created Dec 20, 2013
Install Python 2.7, easy_install, and pip on Amazon Linux
View gist:8062545
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 / privatemethod.py
Last active May 30, 2018
Python decorator for making an instance method private
View privatemethod.py
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 / sleep.java
Created May 28, 2013
Sleep in Java
View sleep.java
try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); }
@jnrbsn
jnrbsn / Outy.php
Created Dec 19, 2012
Objected-oriented command line output library for PHP.
View Outy.php
<?php
/**
* Objected-oriented command line output library for PHP.
*
* Dependencies:
* - Console_Color PEAR package
* - Bash
*
* PHP version 5
*
@jnrbsn
jnrbsn / httpd.php
Created Dec 19, 2012
The beginnings of a really simple web server written in PHP.
View httpd.php
<?php
error_reporting(-1);
set_time_limit(0);
$host = '0.0.0.0';
$port = 12345;
$max_clients = 10;
// Create the socket.
@jnrbsn
jnrbsn / AtomicParsley.php
Created Dec 19, 2012
Wrapper class for AtomicParsley for setting iTunes style meta data on MPEG-4 files via PHP.
View AtomicParsley.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
You can’t perform that action at this time.