Skip to content

Instantly share code, notes, and snippets.

@spewil
spewil / load_from_clippings.py
Last active October 18, 2019 16:40
import Kindle "My Clippings.txt" into separate markdown files per author
import re
import sys
"""
This is a helpful little script for importing your kindle underlines from books.
Because I read multiple books at once, my underlines get mixed up and out of order.
This script untangles my underlines and puts each book into a nice neat markdown file.
Things to be wary of:
- Author names should be adjusted to be 3 words or less (including hyphenations)
@spewil
spewil / fts.sh
Created October 18, 2019 17:10
search files and their contents with fts <dir> <file term> <content term>
fts(){
find $1 -type f -print | grep $2 | xargs rg $3
}
@spewil
spewil / image_trace.sh
Created October 19, 2019 19:19
convert images to vectors
# png/jpg --(mogrify/magick)--> ppm --(mkbitmap)--> pbm --(potrace)--> svg
# mkbitmap parameters:
# -f n == Apply a highpass filter to the image.The parameter n is a radius (in pixels) which corresponds approximately to the size of details which should be preserved.
# -s n == Scale the image by an integer factor n>0.
# -3 == Use cubic interpolation when scaling to a higher resolution.
# -t n == Set the threshold grey value for bilevel conversion.
'''shell
mogrify -format ppm *.jpg
@spewil
spewil / image_adjust.sh
Created February 23, 2020 21:06
my goto image magick
mkdir adjusted
for f in *.JPG
do convert $f -normalize -modulate 100,130,100 adjusted/$f.jpg
done
@spewil
spewil / pyqt_mp_test.py
Created February 27, 2020 13:09
Pyqtgraph multiprocessing coordination example
import queue
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
import multiprocessing
import time
# This function is responsible for displaying the data
# it is run in its own process to liberate main process
@spewil
spewil / pyqt_shm_test.py
Last active March 7, 2020 23:56
pyqt with a background process updating shared memory block thanks to python 3.8
import time
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar, QPushButton
import multiprocessing
from multiprocessing import shared_memory
import numpy as np
DATA_SIZE = 1
DTYPE = np.int64
@spewil
spewil / parse_clippings.py
Created June 1, 2020 17:26
slightly better Kindle clippings parser
import pathlib
import re
import sys
# TODO
# - check if we're parsing raw clippings into
# - a new author file
# or
# - appending to existing author store
# - use markdown tree so we can add clips to existing books
@spewil
spewil / ignore_DS_Store.sh
Created December 2, 2021 13:03
ignore DS_Store everywhere
echo .DS_Store >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
@spewil
spewil / db_flowchart.py
Last active June 25, 2022 14:10
Flowcharts from Notion DBs
# WHAT IS IT
# This is a hacky little script to generate Mermaid flowcharts from Notion page relations across databases
# TO USE:
# - Grab your Notion API key and stick it in "token"
# - Make sure you've allowed your databases access via "Share" (for each database!)
# - Run the script, copypasta from command line into a code block
# TO DO:
# - Add filtering of relations (a kind of config)