Skip to content

Instantly share code, notes, and snippets.

View timoklock's full-sized avatar

Timo Klock timoklock

View GitHub Profile
@timoklock
timoklock / gist:8f025b1e7d77f409bc5517d0d0165a5f
Last active January 26, 2024 14:13
Snippet to select last n words from a text in Postgres, which also works for version < 14 without negative indexing.
-- Create table and add a row
create table test_table (
some_text text
);
insert into test_table(some_text) values (
'this is a test'
);
-- Last word:
@timoklock
timoklock / image_manifold_generator.py
Last active July 7, 2021 21:17
Simple utilities for creating an image manifold from a base image by rotations around certain degrees. Can be easily extended to other create image manifolds from other types of transformations
import numpy as np
from skimage import transform
class TestImage(object):
"""
Handler class for generating test images from different source types
such as from the skimage built-in images or from academic examples defined
by some 2D function (evaluation = pixel values).
"""
@timoklock
timoklock / hermiteCoeffs_tanh.py
Created March 22, 2021 22:58
Computes Hermite coefficients of the tanh function using symbolic differentation (SymPy)
import numpy as np
import sympy as sym
import time
def hermiteCoeffsTanh(nCoeffs):
"""
Computes the first nCoeffs Hermite coefficients of the tanh function. The r-th
Hermite coefficients is defined by
H_r(g) = int_{-oo}^{oo}g(y)h_r(y) * 1/sqrt(2 * pi) * exp(-x^2/2) dy
@timoklock
timoklock / show_1dplots.py
Last active November 30, 2016 21:22
Conveniently plot multiple plots in a single figure with matplotlib.
def show_1dplots(plots, cols = 1, titles = None, xvals = None):
"""Display a list of plots in a single figure with matplotlib.
Parameters
---------
plots: List of np.arrays compatible with plt.plot.
cols (Default = 1): Number of columns in figure (number of rows is
set to np.ceil(n_plots/float(cols))).
@timoklock
timoklock / disp_multiple_images.py
Last active November 22, 2024 04:48
Plot multiple images with matplotlib in a single figure. Titles can be given optionally as second argument.
import matplotlib.pyplot as plt
import numpy as np
def show_images(images, cols = 1, titles = None):
"""Display a list of images in a single figure with matplotlib.
Parameters
---------
images: List of np.arrays compatible with plt.imshow.