Skip to content

Instantly share code, notes, and snippets.

View hartwork's full-sized avatar

Sebastian Pipping hartwork

View GitHub Profile
@hartwork
hartwork / 1_percent_loss_gain.py
Created June 8, 2024 16:15
Plot 1% loss/gain per day for one year
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license
import math
import pylab
from matplotlib import pyplot
START = 100
DAYS = 365
@hartwork
hartwork / headless.py
Created November 25, 2023 01:08
Allow running e.g. asciinema in headless CI
#! /usr/bin/env python3
# Copyright (c) 2015 by pyte authors and contributors
# Copyright (c) 2023 by Sebastian Pipping <sebastian@pipping.org>
#
# Licensed under LGPL v3, see pyte's LICENSE file for more details.
#
# Based on pyte's example "capture.py"
# https://raw.githubusercontent.com/selectel/pyte/master/examples/capture.py
import os
@hartwork
hartwork / find_local_orphan_branches.py
Created November 22, 2023 16:41
Finds Git branches that were tracking a remote branch that no longer exists today
# Finds Git branches that were tracking a remote branch that no longer exists today.
# For Python >=3.8, all else is end-of-life.
#
# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
# Licensed under GPL v3 or later
import re
from subprocess import check_output
# NOTE: See "man git-check-ref-format" for colon (":") being disallowed in references
@hartwork
hartwork / exe2version_info.py
Created November 3, 2023 15:17 — forked from spookyahell/exe2version_info.py
Using the python pefile lib to extract version information from an exe file
'''Licensed under the MIT License :)'''
import pefile
import pprint
pe = pefile.PE('example.exe')
string_version_info = {}
for fileinfo in pe.FileInfo[0]:
@hartwork
hartwork / checkpass.py
Created May 27, 2023 18:39
Test a password against the Have-I-Been-Pwned database API interactively with ease and k-anonymity (Python 3)
#! /usr/bin/env python3
# Copyright (C) 2023 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license
#
# Version 2023-05-27 20:38 UTC+2
#
# Inspired by https://github.com/weddige/django-hibp/blob/main/django_hibp.py
# of django-hibp by Konstantin Weddige (@weddige).
import getpass
# Demo of finding the nth permutation of a list in-place in Python >=3.8
# Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
# SPDX-License-Identifier: GPL-3.0-or-later
from copy import copy
from math import factorial
from typing import List
from unittest import TestCase, TestLoader, TextTestRunner
# Copyright (c) 2022 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the Apache license version 2.0
#
# Needs Python >=3.6
# Version 2022-02-01 17:50 UTC+1
_full_block_char = '\u2588'
_ansi_escape = '\u001b'
_ansi_reset = f'{_ansi_escape}[0m'
_demo_text = 2 * _full_block_char
@hartwork
hartwork / write_many_atts.py
Last active December 30, 2021 23:49
Creates an XML file with a given number of prefixed XML attributes on a single XML tag.
# Copyright (c) 2021 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the Apache license version 2.0
#
# Creates an XML file with a given number of prefixed XML attributes
# on a single XML tag.
# Needs Python >=3.6 and PyPI package "base58"
#
# 2021-12-31 00:47 UTC+1
import argparse
// Copyright (c) 2021 Sebastian Pipping <sebastian@pipping.org>
// Licensed under the Apache license version 2.0
//
// Compile and run with:
// # gcc -std=gnu99 -Wall -Wextra -pedantic bisect_malloc.c && ./a.out
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
@hartwork
hartwork / pgn_find_pirc_defence.py
Created August 18, 2021 22:54
Extract Lichess game URLs from a PGN download for games where Black played the Pirc Defence
#! /usr/bin/env python3
# Copyright (C) 2021 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the Apache 2.0 License
# Version 2021-08-19 00:51 UTC+2
import argparse
from typing import List
import chess
import chess.pgn # https://python-chess.readthedocs.io/en/latest/pgn.html