Skip to content

Instantly share code, notes, and snippets.

View tillahoffmann's full-sized avatar

Till Hoffmann tillahoffmann

View GitHub Profile
@tillahoffmann
tillahoffmann / docstring_magic.ipynb
Created June 11, 2015 09:14
IPython line magic to generate numpy-style docstring stubs.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tillahoffmann
tillahoffmann / docstring_magic.py
Created June 11, 2015 09:30
IPython line magic to generate numpy-style docstring stubs.
from IPython.core.magic import Magics, magics_class, line_magic
import inspect, re
# The class MUST call this class decorator at creation time
@magics_class
class TahMagics(Magics):
@line_magic
def docstring(self, line):
"""
Generate a numpy-style docstring.
@tillahoffmann
tillahoffmann / conovleproblem.py
Created January 17, 2012 10:56
Problem with numerical convolution
import numpy as np
import scipy.signal as signal
import matplotlib.pyplot as plt
import math
import datetime
from matplotlib.font_manager import FontProperties
def convolveoriginal(x, y):
'''
The original algorithm from http://www.physics.rutgers.edu/~masud/computing/WPark_recipes_in_python.html.
@tillahoffmann
tillahoffmann / performancemodule.c
Created January 17, 2012 14:53
A quick implementation of a trapezoidal convolution in C.
#include <Python.h>
//Normally #include "arrayobject.h" should be sufficient. I need to fix my includes.
#include "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h"
/*
* Convolution method.
*/
static PyObject* convolve(PyObject* self, PyObject* args)
{
PyArrayObject *vec1, *vec2, *conv; //The python object proxies
@tillahoffmann
tillahoffmann / merge.py
Created March 6, 2012 14:35
Merging lists based on elementwise comparison
import timeit
setup = '''
from random import Random
from itertools import izip
import numpy as np
length = 1000
random = Random()
A_new = np.array([random.random() for _ in xrange(length)])
A_old = np.array([random.random() for _ in xrange(length)])
@tillahoffmann
tillahoffmann / mathjax_github_bitbucket.js
Created January 19, 2014 20:26
This is a modification of the script provided by Davide Cervone (http://stackoverflow.com/questions/11255900/mathjax-support-in-github-using-a-chrome-browser-plugin). The script URL is modified to load the script from *.github.com* in order to comply with the new [Content Security Policies](https://github.com/blog/1477-content-security-policy).
// ==UserScript==
// @name Run MathJax in Github or Bitbucket
// @namespace http://www.mathjax.org/
// @description Runs MathJax on any page in github.com or bitbucket.org
// @include http://github.com/*
// @include https://github.com/*
// @include http://bitbucket.org/*
// @include https://bitbucket.org/*
// ==/UserScript==
@tillahoffmann
tillahoffmann / citiesToCities.csv
Created March 1, 2016 12:37
Airport network for practical.
We can't make this file beautiful and searchable because it's too large.
"departure city","long. departure (decimal)","lat. departure (decimal)","departure country","arrival city","long. departure (decimal)","lat. departure (decimal)","arrival country","number of routes","distance"
"Sao Paulo",-46.116,-23.054,"Brazil","Rio De Janeiro",-42.74,-22.682,"Brazil",18,348
"Rio De Janeiro",-42.74,-22.682,"Brazil","Sao Paulo",-46.116,-23.054,"Brazil",18,348
"Beijing",116.974,40.133,"China","Shanghai",122.342,31.238,"China",18,1100
"Johannesburg",28.41,-25.566,"South Africa","Cape Town",19.002,-33.942,"South Africa",16,1299
"Honolulu",-157.871,21.531,"United States","Tokyo",140.643,36.274,"Japan",16,6103
"Tokyo",140.643,36.274,"Japan","Honolulu",-157.871,21.531,"United States",16,6103
"Tokyo",140.643,36.274,"Japan","Seoul",126.75,37.781,"South Korea",15,1243
"Seoul",126.75,37.781,"South Korea","Tokyo",140.643,36.274,"Japan",15,1243
"Tokyo",140.643,36.274,"Japan","Los Angeles",-118.014,34.57,"United States",15,8691
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tillahoffmann
tillahoffmann / tensorflow_serialisation.ipynb
Created July 28, 2016 13:48
Serialisation of tensorflow models without using collections
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.