Skip to content

Instantly share code, notes, and snippets.

@righthandabacus
righthandabacus / stdc++.h
Created December 2, 2023 08:00
bits/stdc++.h from GCC 13.2.0
// C++ includes used for precompiling -*- C++ -*-
// Copyright (C) 2003-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
@righthandabacus
righthandabacus / imagebrowser.py
Created November 18, 2023 04:15
Tkinter-based image browser
import argparse
import tkinter as tk
import PIL.Image
import PIL.ImageTk
class ImageBrowser:
"""Image browser using tkinter, two images are displayed sid-eby-side, with
aspect ratio preserved, and allows to navigate using left/right arrow keys
"""Read an Excel file -> Write a Python script that will use OpenPyXL to reproduce the Excel file
"""
import inspect
import copy
from typing import List
import openpyxl
imported = {"styles": set()}
@righthandabacus
righthandabacus / ISO25010.md
Created March 13, 2023 15:10
ISO/IEC 25010

Product Quality

Characteristics Sub-Characteristics Definition
Functional suitability Functional Completeness degree to which the set of functions covers all the specified tasks and user objectives.
@righthandabacus
righthandabacus / daemon.py
Created November 6, 2022 00:17
Python daemon template
#!/usr/bin/env python
"""
Python Daemon template from
https://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
"""
import atexit
import os
import sys
import time
@righthandabacus
righthandabacus / autoargparse.py
Created October 8, 2022 17:49
Generating a command line program from a function in Python. Using argparse to construct a command line and infer the argument schema using type hints and docstring.
"""Convert a function into a command line program automatically based on type hints and docstrings
"""
import argparse
import cmath
import math
import typing
from docstring_parser import parse
@righthandabacus
righthandabacus / brewrdeps.py
Last active September 23, 2022 23:42
Homebrew show reversed dependencies
"""
Reverse dependencies for homebrew
Homebrew gives the package dependencies with `brew deps --installed` which each line of output
is `package: dependencies`. It is easy to see which package depends on nothing but difficult to
tell if nothing depends on it. Output of this script reversed it. For example, if we want to tell
which package can be uninstalled without breaking anything else in homebrew (i.e., output of
`brew leaves`), we can get the list with
python brewrdeps.py | grep ': $'
@righthandabacus
righthandabacus / memoize.py
Created February 4, 2022 03:28
Memoization to disk
import os
import gzip
import pickle
import dbm
import hashlib
MYDIR = "." # dir to save files
def memoize(dbmfile=os.path.join(MYDIR, "memoize.db"), compress=True):
"help save time and bandwidth on heavy functions"
@righthandabacus
righthandabacus / seed_everything.py
Last active December 22, 2021 21:54
Random seeding
# Source: @kastnerkyle
import numpy as np
import torch
import random
import os
default_seed=4142
print("Setting all possible default seeds based on {}".format(default_seed))
# try to get deterministic runs
@righthandabacus
righthandabacus / autoclick.js
Created July 20, 2021 01:06
autocomplete NYC training
function make_clicks() {
var x = document.evaluate(
"//div[@role='button' and contains(@id,'SmartShape_') and @class='cp-frameset']",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
if (x) {
x.click();