Skip to content

Instantly share code, notes, and snippets.

View iTrooz's full-sized avatar
💭
CODE

iTrooz

💭
CODE
View GitHub Profile
@iTrooz
iTrooz / tiktoken_count
Created June 25, 2024 11:40
CLI to count number of tokens in files using tiktoken
#!/usr/bin/env python3
import tiktoken
import sys
if len(sys.argv) == 1:
print(f"Syntax: {sys.argv[0]} <file>")
exit(1)
enc = tiktoken.get_encoding("cl100k_base")
@iTrooz
iTrooz / main.py
Last active June 21, 2024 13:29
Run python shell command, return merged stdout and stderr, and exit code
import subprocess
from typing import Tuple
def run_cmd(cmd: str) -> Tuple[int, str]:
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = p.communicate()
return p.returncode, output.decode("utf-8")
print(run_cmd("ls /"))
print(run_cmd("ls /does-not-exist"))
@iTrooz
iTrooz / java-bytecode.py
Last active June 18, 2024 12:10
Simple script to map java versions and java bytecode versions
#!/usr/bin/env python3
RESET='\033[0m'
COLOR='\033[0;36m' # Cyan
# List from https://javaalmanac.io/bytecode/versions/
JAVA_TO_BYTECODE = {
1.0: 45.0,
1.1: 45.3,
1.2: 46.0,
@iTrooz
iTrooz / CVE-2024-37865.md
Created June 17, 2024 12:48
CVE-2024-37865

Description

An issue in S3Browswer v.11.4.5 and v.10.9.9 and fixed in v.11.5.7 allows a remote attacker to obtain sensitive information via the S3 compatible storage component.

Vulnerability type:

Missing SSL certificate validation

Affected product:

S3Browser - Versions 11.4.5 and 10.9.9 for sure. Older versions are not downloadable but are probably vulnerable too. Issue fixed in 11.5.7

@iTrooz
iTrooz / httpcache.py
Last active May 29, 2024 10:05
varnish_httpcache
#!/usr/bin/env python3
# Easier Frontend for varnishd
# Example: ./httpcache.py -u google.com
# Then, requests to localhost:8080 forwarded to google.com and cached
# Licence: MIT
import os
import tempfile
import subprocess
import shutil
@iTrooz
iTrooz / secsize
Created May 25, 2024 00:16
Print the size of sections in a ELF object file/binary
#!/bin/sh
# Print the size of sections in a ELF object file/binary. Thx ChatGPT
size -A -d $1 | awk 'NR > 2 {print $2, $1}' | sort -n | awk '{
size=$1;
if (size >= 1024*1024*1024) {
printf "%7.2f GB %-20s\n", size / (1024*1024*1024), $2;
} else if (size >= 1024*1024) {
printf "%7.2f MB %-20s\n", size / (1024*1024), $2;
} else if (size >= 1024) {
// can be replace by std::iter::from_fn(): https://doc.rust-lang.org/std/iter/fn.from_fn.html
struct EitherIterator<A, B, C>
where
A: Iterator<Item = C>,
B: Iterator<Item = C>,
{
either: itertools::Either<A, B>,
}
impl<A, B, C> Iterator for EitherIterator<A, B, C>
@iTrooz
iTrooz / main.go
Created February 8, 2024 13:07
Run C code from Go
package main
/*
#include <stdio.h>
static void foo() {
printf("Hello from C\n");
}
*/
import "C"
@iTrooz
iTrooz / to_tldr.py
Created January 26, 2024 21:24
Check commands that you can add to tldr
#!/usr/bin/env python3
# This script will check for commands that you could most easily contribute to tldr (https://tldr.sh/)
# Run it in the root of the https://github.com/tldr-pages/tldr repository
import os
import sys
def get_used_commands():
used_cmds = {}
for filepath, complex in {"~/.zsh_history": True, "~/.bash_history": False}.items():
with open(os.path.expanduser(filepath), "rb") as file:
@iTrooz
iTrooz / binattrs.py
Created December 12, 2023 12:07
cleaner alternative syntax for python ctypes structures, allowing autocompletion
def binattrs(cls):
cls._fields_ = tuple(cls.__annotations__.items())
return cls