Skip to content

Instantly share code, notes, and snippets.

View iTrooz's full-sized avatar
💭
CODE

iTrooz

💭
CODE
View GitHub Profile
@iTrooz
iTrooz / gen-openapi.ts
Last active October 11, 2025 16:05
NestJS CLI tool to dump openapi.json
// Help: https://stackoverflow.com/questions/72852736/generating-swagger-json-file-without-running-nest-js-server
// NestJS 11
import * as path from 'path';
import { writeFileSync } from 'fs';
import { DataType, newDb } from 'pg-mem';
import { DataSource } from 'typeorm';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { Test } from '@nestjs/testing';
import { AppModule } from '../src/app.module';
@iTrooz
iTrooz / README.md
Last active October 11, 2025 12:43
Script to backup a list of folders using restic, and notify user
@iTrooz
iTrooz / pre-commit-push.sh
Last active August 31, 2025 18:32
Ensures you don't commit/push with the wrong git identity
#!/bin/bash
# This script ensures you don't commit/push with the wrong git identity. My remotes are like this: gitperso:iTrooz/repo.git, gitschool:SomeUser/repo.git
# This script should be installed as both pre-commit and pre-push hook (symlink it)
# To use it as a global hook, see https://gist.github.com/iTrooz/551f779af2096912baa9d2e395e2642a
verify_author() {
local author="$1"
local url="$2"
case "$url" in
@iTrooz
iTrooz / setup-global-git-hooks.sh
Last active August 29, 2025 09:54
Setup global git hooks that forward to local hooks
#!/bin/sh
# This script sets up global git hooks (for global actions), that by default forward to local repository hooks if they exist.
# You can then edit these global hooks (make sure to keep the forwarding logic !)
HOOKS="applypatch-msg fsmonitor-watchman prepare-commit-msg pre-receive update post-update pre-commit pre-push push-to-checkout commit-msg pre-applypatch pre-merge-commit pre-rebase sendemail-validate"
HOOKS_DIR="$HOME/.config/git/hooks"
mkdir -p "$HOOKS_DIR"
git config --global core.hooksPath "$HOOKS_DIR"
@iTrooz
iTrooz / main.rs
Created August 26, 2025 17:12
Error handling based on thiserror type, with a variant to catch "all other errors" using anyhow
//! Error handling based on thiserror type, with a variant to catch "all other errors" using anyhow.
use std::fs::read_to_string;
#[derive(thiserror::Error, Debug)]
pub enum MyError {
#[error("some other error")]
FileNotFound,
#[error("anyhow error: {0}")]
Anyhow(#[from] anyhow::Error),
@iTrooz
iTrooz / find_common_password.py
Last active July 5, 2025 14:09
Find words that can be typed in the same way from azerty and qwerty keyboards (e.g. for early boot password prompts)
#!/usr/bin/env python3
# Find words that can be typed in the same way from azerty and qwerty keyboards (e.g. for early boot password prompts)
A="azertyuiopqsdfghjklmwxcvbn"
Q="qwertyuiopasdfghjkl;zxcvbn"
# Common letters: ['e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'x', 'c', 'v', 'b', 'n']
common = []
for a, q in zip(A, Q):
if a == q:
@iTrooz
iTrooz / x64.bat
Created June 10, 2025 20:00
run msvc compilation environment from cmd.exe
%comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
@iTrooz
iTrooz / bad.swift
Last active April 4, 2025 10:40
Swift is bad
// wdym structs and classes have different assignment semantics, and it still persists with protocols ??
protocol P {
var data: Int { get set }
}
struct A: P {
var data = 0
}
@iTrooz
iTrooz / iceandfire-common.toml
Created March 8, 2025 22:19
IceAndFire 1.20.1 default upstream config
[Generation]
[Generation.Dragon]
#Whether to generate dragon skeletons or not
"Generate Dragon Skeletons" = true
#1 out of this number chance per chunk for generation
#Range: 1 ~ 10000
"Generate Dragon Skeleton Chance" = 300
#1 out of this number chance per chunk for generation
#Range: 1 ~ 10000
@iTrooz
iTrooz / main.py
Created February 12, 2025 20:34
Sort authors in a git repository by total contributed lines (I know it's useless)
import os
import re
output = os.popen('git shortlog -s -n').read()
lines = {}
for line in output.split("\n"):
if not line:
continue