Skip to content

Instantly share code, notes, and snippets.

@theodoregoetz
theodoregoetz / FasterNumpyHistogram.ipynb
Last active August 30, 2017 03:16
Faster numpy.histogram() implementation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theodoregoetz
theodoregoetz / test-anding.txt
Created August 11, 2017 23:01
anding: logical vs bitwise.
#include <iostream>
#include <vector>
#include <chrono>
namespace user {
namespace chrono = std::chrono;
using std::chrono::duration_cast;
using std::chrono::steady_clock;
@theodoregoetz
theodoregoetz / watch-file
Created July 20, 2017 20:41
python script to use linux kernel's inotify to monitor a single file, notifying the user through gnome shell's notification using notify2 python module.
#!/usr/bin/env python3
# coding: utf-8
import contextlib
import os
import sys
from inotify.adapters import Inotify
from inotify.constants import IN_DELETE, IN_MODIFY, IN_MOVED_TO
import notify2 as notify
@theodoregoetz
theodoregoetz / cmap-gen-cielab.py
Last active June 6, 2017 14:24
interactive colormap generator using CIELAB space (matplotlib, scikit-image, wxpython)
import matplotlib as mpl
mpl.use('wxAgg')
import numpy as np
import wx
from copy import copy
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.figure import Figure, SubplotParams
from numpy import random as rand
@theodoregoetz
theodoregoetz / cmap-gen-skimage.py
Created June 5, 2017 23:01
colormap defined in cielab space using scikit-image
import matplotlib as mpl
mpl.use('wxAgg')
from collections import Iterable
from copy import copy
from matplotlib import pyplot
import numpy as np
from scipy import interpolate
from skimage import color
from matplotlib.colors import LinearSegmentedColormap
@theodoregoetz
theodoregoetz / wxmpl-interactive-spline.py
Created June 5, 2017 18:17
matplotlib line plot with 1D spline and interactively adjustable control points using wxPython
import matplotlib as mpl
mpl.use('wxAgg')
import numpy as np
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.figure import Figure
from numpy import random as rand
from scipy import interpolate
@theodoregoetz
theodoregoetz / wxmpl.py
Last active June 5, 2017 17:51
matplotlib figure as a panel inside a frame using wxpython
import matplotlib as mpl
mpl.use('wxAgg')
import numpy as np
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
from matplotlib.figure import Figure
from numpy import random as rand
from scipy import interpolate
@theodoregoetz
theodoregoetz / cmap_comb.py
Last active May 25, 2017 18:21
colormap testing using sine-wave comb data.
"""
This function produces an image that can be used to
quickly determine the perceptual linearity of a colormap.
The idea behind this came from Peter Kovesi and
explained very well on his website:
http://peterkovesi.com/projects/colourmaps/
CET Perceptually Uniform Colour Maps
@theodoregoetz
theodoregoetz / accordion_shift.py
Last active May 24, 2017 23:53
bit-mask and shift bits individually to lowest position.
def accordion_shift(value, mask):
x = 0
to_bit = 0
for from_bit in range(len(bin(mask)) - 2):
if (1 << from_bit) & mask:
if (1 << from_bit) & value:
x |= 1 << to_bit
to_bit += 1
return x
@theodoregoetz
theodoregoetz / quick_sort_mt.cpp
Created May 1, 2017 15:54
parallel quicksort in C++11
/**
* g++ -std=c++14 quick_sort_mt.cpp -pthread && ./a.out 10000 1 1
*
*
* This works:
* ./a.out 10000 1 1
*
* This fails (unpredictably!):
* ./a.out 100000 1 1
**/