Skip to content

Instantly share code, notes, and snippets.

@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 March 21, 2024 09:54
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 / makefile
Last active July 1, 2023 20:55
Generic clang++ (or c++ for that matter) makefile with directory structure
# Requires the following project directory structure:
# /bin
# /obj
# /src
# Use 'make remove' to clean up the hole project
# Name of target file
TARGET = foooooooobar
@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 / 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 / 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 / sam-on-enter.directive.js
Created January 14, 2016 10:21
onEnter angular directive
/* global angular: false */
(function () {
'use strict'
angular
.module('sam.utils')
.directive('onEnter', onEnter)
function onEnter () {
@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)