Skip to content

Instantly share code, notes, and snippets.

View iTrooz's full-sized avatar
💭
CODE

iTrooz

💭
CODE
View GitHub Profile
@iTrooz
iTrooz / timer.py
Created January 27, 2023 23:31
Simple Python timer module
import time
def dec(fun):
def decorator(*args, **kwargs):
return call(fun, *args, **kwargs)
return decorator
def call(fun, *args, **kwargs):
print(f"----- Function '{fun.__name__}' started!")
start = time.time()
@iTrooz
iTrooz / bezier3d.py
Last active March 1, 2023 18:38
Bezier curves graph in 3D
#!/bin/env python
# Bezier curves graph in 3D -- CC0 / Public Domain
import matplotlib.pyplot as plt
from matplotlib.ticker import AutoMinorLocator, MultipleLocator
import math
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
@iTrooz
iTrooz / snowflake.py
Last active February 8, 2023 15:04
discord snowflake data dump script
# discord snowflake data dump script
# specialised for attachement links but you should be able to input a snowflake for anything
import datetime
def ts_to_str(ts):
return datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S.%f')
def print_data(sf: int):
@iTrooz
iTrooz / main.py
Last active March 7, 2023 17:33
Working Flask-SQLAlchemy hello world, with models compatible with pure SQLAlchemy, and support for database disconnections
# CC0 / Public domain
import os
from flask import Flask
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import engine as eg
@iTrooz
iTrooz / example.png
Last active June 16, 2023 20:09
reorderable QListWidget with up/down buttons on items, using setItemWidget()
example.png
@iTrooz
iTrooz / utils.py
Created June 23, 2023 17:24
Auto generate __str__ for a python class, but with properties instead of attributes
"""
With help from:
https://python-forum.io/thread-12462.html
https://stackoverflow.com/a/33800620
"""
import inspect
def auto_str_props(cls):
properties = []
@iTrooz
iTrooz / infsleep.c
Created June 25, 2023 15:03
Infinite sleep
// Like https://gist.github.com/iTrooz/b0e932fc6e0382b1b90751af979d1aa0 but without stdin, and can't really be stopped from waiting
// CC0 / Public domain
#include<unistd.h>
#include<limits.h>
int main(){
sleep(UINT_MAX);
return 1;
}
@iTrooz
iTrooz / kubeenv.sh
Last active September 18, 2023 13:16
kubeenv
function kubeenv() {
DIR=$(realpath ~/.config/kube)
if [ $# -eq 0 ]; then
>&2 echo "$0: Please specify a config file or -l to list them"
return 1
fi
if [[ "$1" = "-l" ]]; then
@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 / 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