Skip to content

Instantly share code, notes, and snippets.

@samuelsmal
samuelsmal / config.py
Created May 9, 2020 12:56
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):
pass
@samuelsmal
samuelsmal / matplotlib_video.py
Created April 8, 2020 12:11
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
samuelsmal / how-to-enable-notes-export-from-kobo.md
Last active October 19, 2024 12:36
how to export notes and highlights from kobo

Steps

  1. connect kobo to your device
  2. open a file browser and navigate to the mounted kobo folder
  3. navigate to the hidden folder .kobo/Kobo
  4. open the file Kobo eReader.conf
  5. navigate to the section [FeatureSettings], if it doesn't exist, create it.
  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
samuelsmal / tf_helpers.py
Last active May 27, 2019 18:06
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(v.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
samuelsmal / jupyter_notebook_config.py
Last active March 1, 2019 14:24
jupyter notebook version control
# jupyter config options go here
# usually goes into ~/.jupyter/jupyter_notebook_config.py
# use `$(jupyter --config-dir)/jupyter_notebook_config.py` to check
#-------
# custom code
#-------
import sys
import json
@samuelsmal
samuelsmal / pyspark_udf_filtering.py
Created October 11, 2016 14:10
PySpark DataFrame filtering using a UDF and Regex
from pyspark.sql.functions import udf
from pyspark.sql.types import BooleanType
def regex_filter(x):
regexs = ['.*ALLYOURBASEBELONGTOUS.*']
if x and x.strip():
for r in regexs:
if re.match(r, x, re.IGNORECASE):
return True
@samuelsmal
samuelsmal / plots.py
Created August 25, 2016 09:00
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):
@samuelsmal
samuelsmal / gist:185d0c6b027c3d24b47a892f062cb9bc
Created July 25, 2016 21:26
jupyter notebook saving hook
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
samuelsmal / point_colour_access.h
Created July 23, 2016 13:06
accessing the colour information of a point in the point cloud library
// 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
samuelsmal / scala-reading-list.md
Last active June 22, 2016 09:09
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.