Skip to content

Instantly share code, notes, and snippets.

@samuelsmal
samuelsmal / config.py
Created May 9, 2020
Simple Config class, basically a dict with some enhancements
View config.py
# 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 Apr 8, 2020
python imageio creation of video from matplotlib figures
View matplotlib_video.py
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 Mar 30, 2020
how to export notes and highlights from kobo
View how-to-enable-notes-export-from-kobo.md

steps

  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
samuelsmal / tf_helpers.py
Last active May 27, 2019
Tensorflow Eager Mode histogram and scaler logging helpers
View tf_helpers.py
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 Mar 1, 2019
jupyter notebook version control
View jupyter_notebook_config.py
# 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 Oct 11, 2016
PySpark DataFrame filtering using a UDF and Regex
View pyspark_udf_filtering.py
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 Aug 25, 2016
confusion, confidence, classification-report plots
View plots.py
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
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
samuelsmal / scala-reading-list.md
Last active Jun 22, 2016
Introduction to the world of Scala
View scala-reading-list.md

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.