Skip to content

Instantly share code, notes, and snippets.

View rsnape's full-sized avatar

J. Richard Snape rsnape

  • De Montfort University
  • Leicester
View GitHub Profile

Keybase proof

I hereby claim:

  • I am rsnape on github.
  • I am snapey (https://keybase.io/snapey) on keybase.
  • I have a public key whose fingerprint is 64BC F1D9 9DBE FFA0 2B10 9C22 19F0 B086 51E8 132F

To claim this, I am signing this object:

// ==UserScript==
// @name Common Comments Box (Stack Overflow)
// @namespace about:blank
// @include http*://stackoverflow.com/questions/*
// @version 1
// @grant none
// ==/UserScript==
var common_comments = [
"It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the [FAQ] and [ask].",
import timeit
def to_base_7(n):
"""
Express an int as a base 7 string
If libraries are allowed - numpy.base_repr()
would almost certainly be faster
"""
s, n = [], int(n)
while n > 7:
import wx
#from wx.lib.pubsub.core import Publisher #If you want to manage your own publisher use this
from wx.lib.pubsub import pub
import threading
class ParcelData(object):
def __init__(self,count,current,message):
self.parcel_count = count
self.current_parcel = current
self.message = message
@rsnape
rsnape / check_arr_fail.py
Created August 27, 2015 11:27
Example of how the IncrementalPCA MemoryError failure can occur.
import numpy as np
from sklearn.utils import check_array
ut = np.memmap('D:\\my_array2.mmap', dtype=np.float16, mode='w+', shape=(140000,3504))
print repr(ut), ut.shape
res = check_array(ut)
print 'Memory check passed',repr(res),res.shape #This will print the same contents and shape as above
res = check_array(ut, dtype=np.float) # This is the actual line used in IncrementalPCA
# https://github.com/scikit-learn/scikit-learn/blob/0.16.X/sklearn/decomposition/incremental_pca.py#L165
from math import radians, sin, cos, sqrt, asin, factorial
from itertools import combinations, permutations
# by average circumference instead of authalic radius (assume planes)
# shouldn't actually matter for our purposes as we're using this to generate weights
# been nodes/vertices.
EARTH_RADIUS_KM = 6372.8
def haversine(lat1, long1, lat2, long2, planet_radius=EARTH_RADIUS_KM):
@rsnape
rsnape / colormap_calendar.py
Last active January 26, 2017 02:47
Fixed up version of calendar plot for Stack overflow question
import pandas, pdb, os, csv, datetime, numpy, brewer2mpl
import matplotlib.pyplot as plt
import matplotlib.colorbar as cbar
from matplotlib import rcParams
import palettable
from dateutil import rrule
import matplotlib
import calendar
def set_matplotlib_params():
# Natural Language Toolkit: Clusterer Utilities
#
# Copyright (C) 2001-2014 NLTK Project
# Author: Trevor Cohn <tacohn@cs.mu.oz.au>
# URL: <http://nltk.org/>
# For license information, see LICENSE.TXT
from __future__ import print_function, unicode_literals
import copy
from sys import stdout