Skip to content

Instantly share code, notes, and snippets.

@takluyver
takluyver / README.md
Created September 6, 2014 21:44
Flatten notebooks for git diff

Copy nbflatten.py to somewhere on $PATH. Then, in the root of a git repository, run these commands:

echo "*.ipynb diff=ipynb" >> .gitattributes 
git config diff.ipynb.textconv nbflatten.py

When you change a notebook and run git diff, you'll see the diff of flattened, simplified notebooks, rather than the full JSON. This does lose some information (metadata, non-text output), but it makes it easier to see simple changes in the notebook.

This doesn't help with merging conflicting changes in notebooks. For that, see nbdiff.org.

@electronut
electronut / ldr.py
Created May 4, 2014 06:14
Display analog data from Arduino using Python (matplotlib animation)
"""
ldr.py
Display analog data from Arduino using Python (matplotlib)
Author: Mahesh Venkitachalam
Website: electronut.in
"""
import sys, serial, argparse
@f4ktrh
f4ktrh / python3scientificstack.sh
Last active April 23, 2020 17:11
Isolated Python 3 (from source) with Scientific Stack in a Virtual-Environment (double isolation) on Ubuntu Precise (As of Feb 2014)
# DISCLAIMER:
# - Code is provided "as is" and any expressed or implied warranties are disclaimed.
# - Errors and omissions excepted.
# NOTE:
# - Read it carefully, some commands might have to be changed for your system.
# - BLAS/LAPACK compilation commands will most likely have to be changed based on the
# stackoverflow link below.
# - Running this shell file as a script is NOT recommended. Copy/pasting one command at a time is
# okay as long as you monitor the output for any possible errors/warnings.
@thomasgohard
thomasgohard / .travis.yml
Last active December 21, 2015 19:49
How to enable Jekyll+Prose on a GitHub repository.
language: ruby
branches:
only:
- master
script:
- "bundle exec jekyll build"
- ./build.sh

#LaTeX in IPython Notebook

With this extension you can use LaTeX-style references within IPython (Notebook) while still using markdown for formatting.

Required:

  • ipython-dev
  • biblio-py
  • markdown
import numpy as np
import scipy.linalg.blas
cdef extern from "f2pyptr.h":
void *f2py_pointer(object) except NULL
ctypedef int dgemm_t(
char *transa, char *transb,
int *m, int *n, int *k,
double *alpha,
@evansd
evansd / gist:1639992
Created January 19, 2012 13:09
Global find and replace using ack
function substitute {
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: substitue FROM_STRING TO_STRING [OPTION]..."
echo
echo "Replace all occurances of FROM_STRING (a sed-compatible regular"
echo "expression) with TO_STRING in all files for which ack-grep matches"
echo "FROM_STRING."
echo
echo "Any additional options are passed directly to ack-grep (e.g.,"
echo " --type=html would only run the substitution on html files)."
@tkafka
tkafka / peakdetect.py
Created January 17, 2012 23:10 — forked from sixtenbe/analytic_wfm.py
Peak detection in Python
import numpy as np
def peakdetect(y_axis, x_axis = None, lookahead = 500, delta = 0):
"""
Converted from/based on a MATLAB script at http://billauer.co.il/peakdet.html
Algorithm for detecting local maximas and minmias in a signal.
Discovers peaks by searching for values which are surrounded by lower
or larger values for maximas and minimas respectively
@sixtenbe
sixtenbe / analytic_wfm.py
Last active February 24, 2024 23:45 — forked from endolith/peakdet.m
Peak detection in Python
#!/usr/bin/python2
# Copyright (C) 2016 Sixten Bergman
# License WTFPL
#
# This program is free software. It comes without any warranty, to the extent
# permitted by applicable law.
# You can redistribute it and/or modify it under the terms of the Do What The
# Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See
@endolith
endolith / frequency_estimator.py
Last active October 30, 2023 18:08
Frequency estimation methods in Python
from __future__ import division
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
from scipy.signal import blackmanharris, correlate
from time import time
import sys
try:
import soundfile as sf
except ImportError:
from scikits.audiolab import flacread