Skip to content

Instantly share code, notes, and snippets.

View iTrooz's full-sized avatar
💭
CODE

iTrooz

💭
CODE
View GitHub Profile
@iTrooz
iTrooz / panel.json
Created August 7, 2024 20:48
Alternative UnifiedMetrics (Minecraft server Prometheus exporter) Grafana panel
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "datasource",
"uid": "grafana"
},
"enable": true,
@iTrooz
iTrooz / swapstats.py
Last active August 9, 2024 00:53
Show swap usage of processes
#!/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 / ssh_udp.py
Last active August 9, 2024 21:29
Utility to setup SSH UDP port forwarding easily
#!/usr/bin/env python3
"""
This script setups the UDP translators in order to enable UDP traffic forwarding over SSH.
-L example usage: `py ssh_udp.py -L 53000:8.8.8.8:53 your_ssh_host` an then `dig @127.0.0.1 -p 53000 google.com` locally
-R example usage: `py ssh_udp.py -R 53000:8.8.8.8:53 your_ssh_host` an then `dig @127.0.0.1 -p 53000 google.com` on the server
Note: I know this code is ugly.
Thanks to https://stackpointer.io/network/ssh-port-forwarding-tcp-udp/365/ for the help
"""
import subprocess
import time
@iTrooz
iTrooz / main.py
Created July 30, 2024 11:07
pacman package upgrade size verbose
#!/usr/bin/env python
"""
This script shows the individual size changes of upgradable packages in Arch Linux.
You can use it to understand, e.g. why your upgrade size is negative.
"""
import typing
import subprocess
import sys
@iTrooz
iTrooz / FILE.md
Last active August 1, 2024 10:57
Map of Sodium and Lithium forks

This document is about the Minecraft mods Sodium and Lithium, and their forks. These are mods to help performance.

The Sodium stuff

What is it

Sodium optimizes the client rendering pipeline. It does nothing for the server.

Table

@iTrooz
iTrooz / stdout_breakpoint.gdb
Last active July 24, 2024 22:39
Make a breakpoint when a certain text is written to stdout
# Make a breakpoint when a certain text is written to stdout
# Note: only work with C/C++ binaries
set width 0
set height 0
set verbose off
# Modify this to search for a different string
# Case sensitive
set $STR_SEARCH = "hello world"
@iTrooz
iTrooz / main.py
Created July 22, 2024 04:12
Reads stdin from the user console and stops input with Ctrl+C
"""
Reads stdin from the user console and stops input with Ctrl+C. Also support piped stdin.
Works only on Linux (and maybe MacOS ?)
"""
import sys
import os
import time
import fcntl
def read_user_stdin() -> bytes:
@iTrooz
iTrooz / main.c
Last active July 8, 2024 09:12
Manual implemenation of a split() function in C
#include<stdlib.h>
#include<stdio.h>
#define bool short
#define false 0
#define true 1
bool my_contains(char *charset, char c) {
for (int i = 0; charset[i] != '\0'; i++) {
if (charset[i] == c) {
@iTrooz
iTrooz / live_processes.py
Last active July 5, 2024 14:15
Show processes lifecycle in real time
#!/usr/bin/env python3
# Simple monitoring script to print processes being created/stopped in real-time
import time
from typing import Optional
import psutil
import shutil
import sys
import argparse
@iTrooz
iTrooz / live_processes.sh
Created July 5, 2024 14:02
OLD BUGGY IMPLEMENTATION - Show processes lifecycle in real time
#!/bin/sh
get_running_processes() {
processes=$(ps -eo ppid,pid,cmd)
echo "$processes" |
grep -v "\[.*\]" | # Filter out kernel processes
awk -v pid="$$" '$1 != pid' | # Remove children of current script
awk '{print $1 " " $2 " " $3}' | # Remove ppid + command params
sort
}