Skip to content

Instantly share code, notes, and snippets.

View oprypin's full-sized avatar

Oleh Prypin oprypin

View GitHub Profile
@oprypin
oprypin / matcher.py
Created April 11, 2026 11:57
Rebrickable: Find all minifigs that can be built from an exported part list
import collections
import csv
inventory_id_to_fig_num: dict[int, str] = {}
print('Reading inventories') # From https://rebrickable.com/downloads/
with open('inventories.csv', encoding='utf-8') as f:
for row in csv.DictReader(f):
if row['set_num'].startswith('fig-'):
inventory_id_to_fig_num[int(row['id'])] = row['set_num']
@oprypin
oprypin / split_parts_rules.py
Created April 5, 2026 17:36
Patterns for part names in Rebrickable that are "splittable"
SPLIT_PART_PATTERNS = r"""
Cylinder Half 2 x (4) x 5 with 1 x 2 [Cc]utout
Cylinder Quarter 2 x (2) x 5(?: \(.+\))?
Bracket 1 x (\d+) - 1 x \1
Bracket 1 x (\d+) - 1 x \1 Inverted
Bracket 1 x (\d+) - \1 x 2
@oprypin
oprypin / drop_async.py
Last active November 23, 2025 14:47
Replace Quart with Flask in code - drop async features
import pathlib
import re
import subprocess
for fn in subprocess.check_output(["git", "ls-files"], encoding="utf-8").splitlines():
f = pathlib.Path(fn)
if not f.match("*.py"):
continue
content = f.read_text()
@oprypin
oprypin / import_rebrickable.sql
Created October 6, 2025 16:15
Import rebrickable.com/downloads into an SQLite database using a pure-SQLite script
-- Usage:
-- 1. Download and extract all files from https://rebrickable.com/downloads/
-- 2. Pipe this script into SQLite CLI with this command:
-- cat import_rebrickable.sql | sqlite3 output_rebrickable_database.db
.bail on
.mode csv
.separator ","
PRAGMA foreign_keys = ON;
@oprypin
oprypin / script.js
Last active December 1, 2023 16:12
Add a selector with checkboxes to https://docs.astral.sh/ruff/rules/
// Create checkbox to hide preview rules
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = true;
checkbox.addEventListener("change", function () {
for (var span of document.querySelectorAll(
'span[title="Rule is in preview"]',
)) {
span.closest("tr").style.display = event.currentTarget.checked
? null
@oprypin
oprypin / merge_branch.sh
Created September 8, 2023 13:05
Merge cimgui docking_inter branch into master and re-generate
#!/bin/bash
set -ex
to_merge="${1:-docking_inter}"
imgui_branch="${2:-master}"
git merge --no-ff --no-commit "$to_merge" || true # Always fails
# But double-check that we really ended up in a merge status
git rev-list -1 MERGE_HEAD
# Reset everything to be like the merged branch
@oprypin
oprypin / __init__.py
Created September 2, 2022 22:17
Disallow unexpected logging messages in Python unittest
import logging
class DisallowLogsHandler(logging.Handler):
def emit(self, record):
raise AssertionError(f'Unexpected log: "{self.format(record)}"')
logging.lastResort = DisallowLogsHandler(level=logging.WARNING)
@oprypin
oprypin / S3 config api.json
Last active December 14, 2021 22:49 — forked from straight-shoota/S3 config api
Crystal S3 Config
{
"IndexDocument": {
"Suffix": "index.html"
},
"ErrorDocument": {
"Key": "api/1.2.2/404.html"
},
"RoutingRules": [
{
"Condition": {
@oprypin
oprypin / cleanup_generate.sh
Last active April 19, 2020 11:07
Unused code deletion based on the output not being affected
#!/bin/bash
set -x -e
check() {
mkdir -p /tmp/a /tmp/b
cp generate.cr /tmp/a/
sed -i -e "${1}d" generate.cr
cp generate.cr /tmp/b/
(cd /tmp/b && crystal build --warnings=none generate.cr) || return 4
(cd /tmp/a && crystal build --warnings=none generate.cr) || return 5