Skip to content

Instantly share code, notes, and snippets.

View tillahoffmann's full-sized avatar

Till Hoffmann tillahoffmann

View GitHub Profile
@tillahoffmann
tillahoffmann / weighted_kde.ipynb
Last active June 24, 2023 07:39
Weighted kernel density estimation based on `scipy.stats.gaussian_kde`.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / 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 / 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.