Skip to content

Instantly share code, notes, and snippets.

View temporaer's full-sized avatar

Hannes Schulz temporaer

View GitHub Profile
@temporaer
temporaer / .pdbrc
Last active November 25, 2019 14:54
pdbhelpers
alias deltrace ipdb.set_trace = lambda: None
alias pshape (%1).shape
alias plen len(%1)
alias plshape for i in (%1): print(i.shape)
alias embed import IPython; IPython.embed()
alias ts from pprint import pprint; from pdbhelpers import tensor_shapes; A=tensor_shapes(%1); pprint(A)
@temporaer
temporaer / slave-timer.py
Created November 2, 2016 17:29
Time your progress on a monotonous task, print your ETA
import sys
import click
import shelve
import datetime
from prompt_toolkit.validation import Validator, ValidationError
from prompt_toolkit import prompt
class NumberValidator(Validator):
def validate(self, document):
text = document.text
@temporaer
temporaer / fromfile.cpp
Created September 24, 2015 08:29
Simple file-format for communicating dense n-dimensional matrices between matlab and C++
#include <algorithm>
#include <numeric>
#include <iostream>
#include <fstream>
#include <vector>
#include "boost/multi_array.hpp"
template<class T, long unsigned int D=2u>
boost::multi_array<T, D> fromfile(std::string f, bool convert_to_c_order=false){
typedef boost::multi_array<T, D> array_type;
@temporaer
temporaer / lp.png
Last active April 16, 2021 12:21
matplotlib log-polar plots seem to be quite buggy at the time of writing. They crash if rlim is not set before rscale, and they seem to have a magic 0.1 in there somewhere, where all values less than 0.1 are interpreted as 'negative' (whatever that means in a log-polar plot). This gist creates some spiral data, a polar and a log-polar plot using…
lp.png
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import fetch_mldata
from sklearn.decomposition import FastICA, PCA
from sklearn.cluster import KMeans
# fetch natural image patches
image_patches = fetch_mldata("natural scenes data")
X = image_patches.data
@temporaer
temporaer / gil_or_nogil.py
Created February 8, 2013 11:28
Observations on the effect of using nogil or not in Cython function declarations
#cython: boundscheck=False
#cython: cdivision=True
#cython: wraparound=False
# While learning about Cython, I found code which proudly adds
# 'nogil' to function heads wherever possible.
#
# In the generated C-Code, the effect is mainly three lines:
#
#
@temporaer
temporaer / random_palette.py
Created January 31, 2013 12:39
Create a random palette in LAB space and convert to RGB. For easy use as a infinite colormap in matplotlib.
# Create a random palette in LAB space and convert to RGB.
# For easy use as a infinite colormap in matplotlib.
# After an idea from @amueller and
# http://stackoverflow.com/questions/10254207/color-and-line-writing-using-matplotlib
import numpy as np
from colormath.color_objects import LabColor
def get_random_color(seed=3):