Skip to content

Instantly share code, notes, and snippets.

panzi /
Last active Sep 8, 2021
Compare values using JavaScript semantics in Python. Not sure if I got everything right. This is more of a demonstration that JavaScript equality semantics are crazy.
# Copyright 2021 Mathias Panzenböck
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
panzi /
Last active Jul 31, 2021
Python argparse help formatter that keeps new lines and doesn't break words (so URLs are preserved), but still wraps lines. Use with: `argparse.ArgumentParser(formatter_class=SmartFormatter)`
import argparse
from typing import List
class SmartFormatter(argparse.HelpFormatter):
def _split_lines(self, text: str, width: int) -> List[str]:
lines: List[str] = []
for line_str in text.split('\n'):
line: List[str] = []
line_len = 0
for word in line_str.split():
panzi /
Created Jul 5, 2021
Python: Convert PIL.Image to OpenCV BGR(A)/grayscale image (NumPy array). This supports the most common image modes, but there are more! Patches for those are welcome.
from PIL import Image
import numpy as np
import cv2
def pil2cv(image: Image) -> np.ndarray:
mode = image.mode
new_image: np.ndarray
if mode == '1':
new_image = np.array(image, dtype=np.uint8)
panzi / VideoScreenshot.js
Last active Aug 11, 2020
Make a screenshot of a video.
View VideoScreenshot.js
javascript:(function() {
function screenshot(video) {
var canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
context = canvas.getContext('2d');
var now = new Date();
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
var url = canvas.toDataURL('image/png');
var link = document.createElement('a');
panzi / enable_context_menu.js
Created Jul 22, 2020
Bookmarklet to re-enable context menus on sites that disable it.
View enable_context_menu.js
View YouTubeThumbs.js
(function() {
"use strict";
function padd(x) {
var x = String(x);
return x.length < 2 ? '0' + x : x;
var duration = +document.querySelector("video").duration;
var playerData = document.querySelector("ytd-watch-flexy").__data.playerData;
panzi /
Created Oct 2, 2019
convert a video into a GIF with optimal palette
panzi / no_blocking_overlay.js
Created Apr 9, 2019
A bookmarklet that removes these nasty overlays from websites that would work perfectly fine without a login, but still want you to create one.
View no_blocking_overlay.js
javascript:Array.forEach(document.body.querySelectorAll("*"), e => { var s = getComputedStyle(e); if (s.position !== 'static' && s.position !== 'relative') { var r = e.getBoundingClientRect(); if (r.x <= 0 && r.y <= 0 && r.width >= window.innerWidth && r.height >= window.innerHeight) { e.remove(); } } });"auto";void(0)
panzi / show_hide_passwords.js
Created Jan 19, 2019
Bookmarklets to make passwords in password fields readable and to hide them again.
View show_hide_passwords.js
// Show Passwords:
// Hide Passwords again:
panzi /
Last active Nov 20, 2018
Merge files useing kdiff3. Using git mergetool merges files one by one, this opens all files in kdiff3 at once. TODO: somehow git add merged files after kdiff3 exists
set -e
. "`git --exec-path`/git-sh-setup"