Skip to content

Instantly share code, notes, and snippets.

@endolith
endolith / Perfect_FFT.py
Last active June 16, 2023 08:25
Perfect FFT
from numpy import linspace, cos, pi, absolute
from numpy.fft import fft, fftfreq, fftshift
import matplotlib.pyplot as plt
# Sampling rate
fs = 64 # Hz
# Time is from 0 to 1 seconds, but leave off the endpoint, so
# that 1.0 seconds is the first sample of the *next* chunk
length = 1 # second
@mbostock
mbostock / .block
Last active December 6, 2016 11:39
Streamgraph
license: gpl-3.0
Jquick7490MLA:force jquick$ mkvirtualenv force
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 8, in <module>
load_entry_point('virtualenv==1.5.1', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.6/site-packages/virtualenv.py", line 558, in main
prompt=options.prompt)
File "/Library/Python/2.6/site-packages/virtualenv.py", line 647, in create_environment
site_packages=site_packages, clear=clear))
File "/Library/Python/2.6/site-packages/virtualenv.py", line 771, in install_python
copy_required_modules(home_dir)
@j2labs
j2labs / gist:898488
Created April 1, 2011 17:10
JSON vs cPickle in Python 2.7
#!/usr/bin/env python
# Average runs looks like this:
# $ ./serialization.py
# Starting json...
# done: 5.75292301178
# Starting simplejson...
# done: 6.66689586639
# Starting cjson...
# done: 2.09307098389
@avar
avar / 30-income-calculon.pl
Last active February 12, 2024 18:34
Calculate your income in The Netherlands with and without a 30% ruling.
# To check if this is up-to-date with the tax rates go to
# http://www.expatax.nl/tax-rates-2016.php and see if there's anything
# newer there.
#
# I make no guarantees that any of this is correct. I calculated this
# at the time and have been updating it when new tax rates come along
# because people keep finding this useful.
#
# There's also an interactive JS version of this created by
# @stevermeister at
@flashingpumpkin
flashingpumpkin / coroutine.py
Created March 1, 2012 16:55
Decorator for coroutine usage.
def coroutine(func):
"""
A decorator that turns a function with normal input into a coroutine.
This decorator takes care of priming the coroutine, doing the looping and
handling the closing.
The first argument of any decorated function is what was received when
data was sent to the coroutine via the ``.send`` method. All the other
``*args`` and ``**kwargs`` are what was passed to the decorated function
when instantiating the coroutine.
@kohlmeier
kohlmeier / ka_bnet_numpy.py
Created March 26, 2012 21:59
Bayes net example in Python with Khan Academy data
#!/usr/bin/env python
from numpy import asmatrix, asarray, ones, zeros, mean, sum, arange, prod, dot, loadtxt
from numpy.random import random, randint
import pickle
MISSING_VALUE = -1 # a constant I will use to denote missing integer values
def impute_hidden_node(E, I, theta, sample_hidden):
@kohlmeier
kohlmeier / ka_bnet_pandas.py
Created March 26, 2012 22:32
Bayes net example (Pandas version)
#!/usr/bin/env python
from pandas import DataFrame, Series
import numpy as np
import math
import random
import copy
NaN_Flag = -1 # pandas uses np.nan, but that coerces ints to floats :(
@mdengler
mdengler / garch.py
Created April 18, 2012 04:38
garch in python, from Peter von Tessin
#!/usr/bin/env python
# Trivial GARCH implementation in python
#
# From Peter Tessin's http://www.petertessin.com/TimeSeries.pdf
#
@jcreixell
jcreixell / gdoc.py
Created May 15, 2012 09:39
Google Doc pandas integration
import gspread
from pandas import *
import logging
class GDocError(Exception):
def __init__(self, value):
self.parameter = value
def __str__(self):