Skip to content

Instantly share code, notes, and snippets.

View iTrooz's full-sized avatar
💭
CODE

iTrooz

💭
CODE
View GitHub Profile
@iTrooz
iTrooz / list_open_ports.sh
Created November 13, 2025 20:28
List ports that can be used to
"""
List ports that can be used to connect to this host by dumping incoming connections
After running this command you will need to launch a scan against your host to try to connect to all ports. e.g. with:
nmap -sS -p1-49151 162.38.112.152
Detected new ports will be shown live and deduplicated
"""
tcpdump 'tcp' -l -nn | stdbuf -oL cut -d' ' -f 3 | stdbuf -oL cut -d'.' -f 5 | stdbuf -oL perl -ne '$|=1; print "$_" unless $seen{$_}++' | tee ports.txt
#!/usr/bin/env python3
"""
Show the swap usage of all processes in the system.
Note: This may not be reliable because of "shared pages". Source: https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/
"""
import os
import sys
import humanize
import psutil
import tabulate
@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
}