Skip to content

Instantly share code, notes, and snippets.

samuelsmal /
Created May 9, 2020
Simple Config class, basically a dict with some enhancements
# Simple Config class, basically a dict with some enhancements
# Best used if you read your config only a couple of times. This version will read in the values everytime.
from functools import reduce
import os.path as path
import yaml
class ConfigValueError(ValueError):
samuelsmal /
Created Apr 8, 2020
python imageio creation of video from matplotlib figures
import warnings
import imageio
def gen_frames(data):
bandpower_over_time_index = data.index
frames = []
# loop over your images
for idx, time_index in enumerate(times_index_to_plot):
samuelsmal /
Last active Mar 30, 2020
how to export notes and highlights from kobo


  1. connect kobo to your device
  2. open a file browser
  3. navigate to the hidden folder .kobo/Kobo
  4. open the file Kobo eReader.conf
  5. navigate to the section [FeatureSettings]
  6. add the line ExportHighlights=true and save
  7. disconnect the device
  8. now you can long press on a book and export the note file into a .txt file which will be saved alongside your books. to get it connect your ereader.
samuelsmal /
Last active May 27, 2019
Tensorflow Eager Mode histogram and scaler logging helpers
def tf_clean_variable_name(var_name):
Usage example (and an example of how to log a histogram in eager mode)
with gradients_writer.as_default(), tfc.summary.always_record_summaries():
for g, var_name in zip(gradients, [tf_clean_variable_name( for v in model.trainable_variables]):
tfc.summary.histogram(f'gradient_{var_name}', g, step=epoch)
# example of a var_name: 'inf_dense_0_23/kernel:0'
samuelsmal /
Last active Mar 1, 2019
jupyter notebook version control
# jupyter config options go here
# usually goes into ~/.jupyter/
# use `$(jupyter --config-dir)/` to check
# custom code
import sys
import json
samuelsmal /
Created Oct 11, 2016
PySpark DataFrame filtering using a UDF and Regex
from pyspark.sql.functions import udf
from pyspark.sql.types import BooleanType
def regex_filter(x):
if x and x.strip():
for r in regexs:
if re.match(r, x, re.IGNORECASE):
return True
samuelsmal /
Created Aug 25, 2016
confusion, confidence, classification-report plots
import operator
import matplotlib.patches as mpatches
from itertools import groupby
import re
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def cm2inch(*tupl):
View gist:185d0c6b027c3d24b47a892f062cb9bc
import os
from subprocess import check_call
c = get_config()
def post_save(model, os_path, contents_manager):
"""post-save hook for converting notebooks to .py scripts"""
if model['type'] != 'notebook':
return # only do this for notebooks
d, fname = os.path.split(os_path)
samuelsmal / point_colour_access.h
Created Jul 23, 2016
accessing the colour information of a point in the point cloud library
View point_colour_access.h
// p is a point
const auto pv = p.getVector3fMap();
const uint32_t rgb = *reinterpret_cast<const int*>(&p.rgb);
int r = int((rgb >> 16) & 0x0000ff);
int g = int((rgb >> 8) & 0x0000ff);
int b = int((rgb) & 0x0000ff);
samuelsmal /
Last active Jun 22, 2016
Introduction to the world of Scala

As I just begun reading and learning Scala somethings might be outdated. If that is so, please leave a comment below. The order reflects the importance - or just my way of learning a new language.

Basically it is: overview, syntax, some usage, pitfalls, best practices.