Skip to content

Instantly share code, notes, and snippets.

View dempe's full-sized avatar
🔰

Chris Dempewolf dempe

🔰
View GitHub Profile
@dempe
dempe / notes_parse.py
Last active October 20, 2023 21:10
Convert Kindle HTML notes to Markdown
from bs4 import BeautifulSoup
import argparse
def clean_text(section) -> str:
return section.get_text().lstrip().replace('\n', '').replace('\t', '')
def parse_chapter(text):
# There is NO chapter number, but there is A page number. Example ->
@dempe
dempe / notes.md
Last active July 20, 2022 06:22
Notes about the book, The Little Schemer

Overview

The Little Schemer is fundamentally a book about reasoning using recursive logic. It uses the language, Scheme (a Lisp dialect), as a medium. It starts very simple, slowly acquainting the reader to thinking in terms of recursion, building more and more complex functions. By the final chapters, the authors begin to introduce ideas very fundamental to computer science such as the Y-combinator and the Halting problem.

Abstract theory aside, the book has practical benefits as well. Solving programming problems using only recursion (without for and while loops) forces the reader to think differently about problems than how they would normally think about them in day-to-day work. I found the challenge of working within the constraints of Scheme to be a lot of fun!

Notes

Scheme is made up of atoms and lists. Atoms and lists, together, are called S-expressions. Atoms are simple strings or digits (e.g., a, cat, 123). Lists are S-expressions with a pair of parentheses containing a

@dempe
dempe / pg_parse.py
Created January 19, 2022 14:33
Parse query plans from Postgres logs.
import json
from json import JSONDecodeError
PLAN_START_MSG = 'plan:'
REGULAR_LOG_PREFIX = '2022'
def print_buffer(filename: str, str_buffer: [str]):
plan_text = ''.join(str_buffer)
with open(filename, 'w') as f:
@dempe
dempe / find_duplicate_images.sh
Created May 27, 2020 02:29
Shell one-liner for finding duplicate images in a directory
for f in *; do sig=$(identify -verbose $f | grep signature | awk '{print $2}'); echo "$sig - $f"; done | sort | uniq -d
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/* Hide tabs bar */
#TabsToolbar {
visibility: collapse;
}
/* Hide forward and back buttons */
#back-button, #forward-button {
display: none;
@dempe
dempe / fugu_comands.sh
Last active March 20, 2019 15:03
A random assortment of educational shell script one-liners
# Strip terminal formatting
sed -e "s/\x1b\[.\{1,5\}m//g"
# Given a list of files named like this: 2019-01-02-1.md, 2019-01-04-3.md, etc.
# 1) Rename them 1.md, 3.md AND 2) add the lines "date: 2019-01-02T00:00:00" and "date: 2019-01-04T00:00:00" at line 2, respectively
# grep: "-o" selects only the matched portion, "-e" allows a regex to be passed in
# awk: "NR" is an internal variable for the current record, "-v" passes a shell var to awk
for f in *; do line="date: $(echo $f | grep -o -e '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}')T00:00:00"; fn="$(echo $f | grep -o -e '[0-9]\{1,2\}\.md' | sed 's/.md//g')"; awk -v var="$line" '(NR==2) {print var} {print $0}' $f > "$fn.md"; done
# Format video so that it is uploadable to Twitter
@dempe
dempe / punctuation_regex.kt
Created January 18, 2018 18:57
because i'm tired of searching the internet for this
private val PUNCTUATION_REGEX = Regex("[^\\p{L}0-9_]")
言葉 発音 意味
き・モク tree
もり forest
はやし grove
うめ plum
艸* くさ・そうこう grass
くさ・ソウ grass
こけ moss
@dempe
dempe / reflect_server.py
Last active May 22, 2017 19:34
Reflects incoming headers to stdout
import json
from flask import Flask, request
app = Flask(__name__)
@app.route("/reflect", methods=['PATCH', 'POST', 'GET'])
def reflect():
data = request.get_json()
print("DATA: %s" % data)
print("request: %s" % request)
@dempe
dempe / LeThreadPool.java
Last active August 19, 2016 03:28
Le Thread Pool
package com.datarank.krunch.datasources.services;
import com.datarank.krunch.lib.concurrent.ThreadPoolExecutor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
public class LeThreadPool {