Skip to content

Instantly share code, notes, and snippets.

View iTrooz's full-sized avatar
💭
CODE

iTrooz

💭
CODE
View GitHub Profile
@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:
// 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 / main.py
Last active January 5, 2024 00:57
reMarkable 2 splash.dat converter
#!/usr/bin/env python3
"""
This script aims at converting an image to the custom format used by Remarkable 2
After running this script, move the output "splash.dat" file to /var/lib/uboot in the rM2 device
I tried this with PNG images but I guess other formats should work too since I use PIL
Syntax: ./main.py <file> [-x xOffset] [-y yOffset]
(-x and -y are the offsets of the image on the screen. If not set, the image will be centered on the screen)
Input images may need to be rotated 90 degrees before converting them
Licence: MPL 2.0
"""
@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
@iTrooz
iTrooz / main.py.php
Created December 4, 2023 21:05
python preprocessor
<?php # The voice in my head told me to. Run with `php main.py.php | python` ?>
def getOS():
<?php
if (PHP_OS == "Linux"){
?>
for line in open("/etc/os-release"):
key, value = line.split("=")
if key == "ID":
distro_id = value
@iTrooz
iTrooz / main.sh
Created November 14, 2023 21:49
bash_conditions
# Everything here prints "OK"
# 1 is true
if (( 1 )); then
echo "OK"
else
echo "NOT OK"
exit 1
fi
@iTrooz
iTrooz / chatgpt.py
Last active November 7, 2023 09:01
basic ChatGPT terminal client
#!/bin/python3
import sys
from openai import OpenAI
myPrompt = ' '.join(sys.argv[1:]).strip()
if not myPrompt:
print("Syntax : ", sys.argv[0], "prompt")
exit(1)
print("Me:", myPrompt, file=sys.stderr)
@iTrooz
iTrooz / cmd.txt
Created September 19, 2023 16:55
TMate anywhere
# Simple command combination to download + start tmate anywhere
wget https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-amd64.tar.xz -P /tmp && tar -xvf /tmp/tmate-2.4.0-static-linux-amd64.tar.xz -C /tmp && /tmp/tmate-2.4.0-static-linux-amd64/tmate
@iTrooz
iTrooz / .zshrc
Last active September 19, 2023 07:58
initdir
# rm -rf but with safeguards, and cd into the directory
# You should put this in a sourced script (e.g .bashrc, .zshrc, etc...)
RED="\e[1;31m"
ORANGE="\e[38;5;208m"
GREEN="\e[38;5;2m"
RESET="\e[0;0m"
function initdir() {
if [ $# -eq 0 ]; then