Skip to content

Instantly share code, notes, and snippets.

View srtopster's full-sized avatar

Topster_ srtopster

View GitHub Profile
@srtopster
srtopster / table.rs
Last active April 28, 2026 18:14
Exemplo de custom preset e style para comfy_table rust
use comfy_table::{Table,ContentArrangement,Cell,Color,Attribute};
//use comfy_table::TableComponent;
const COMFY_TABLE_CUSTOM_PRESET: &str = "││━─┡━╇┩│ ┳┴┏┓└┘"; //exportado usando .current_style_as_preset()
pub fn print_table() {
let headers = vec!["SKU","Descrição","ML P", "ML C", "ML P (Promo)", "ML C (Promo)","SH","SH (Promo)"];
let row = vec!["ISA59228","Pneu Pirelli Phantom Street 29x1.95 Preto","8.06","15.17","9.96","8.15","15.45","13.21"];
let headers: Vec<Cell> = headers.iter().map(|f|Cell::new(f).add_attribute(Attribute::Bold)).collect();
@srtopster
srtopster / file_grabber.py
Created June 4, 2024 17:32
Goofy ass tool to find and copy files from a folder using regex, to use at work
import os
import shutil
import re
import PySimpleGUI as sg
def config_file_deserializer(file_path: str) -> dict:
variables = {}
with open(file_path,"rb") as f:
for line in f.readlines():
key,val = line.decode().strip().split("=",1)
@srtopster
srtopster / mean.py
Last active June 4, 2024 10:38
An simple script to calculate random values that add up to some mean
#python mean.py <desired_mean> <samples_n>
#An simple script to calculate random values that add up to some mean
#Changing the play paramenter (#10) will dictate how wild the numbers will vary from each other
import random
import sys
mean = float(sys.argv[1])
samples = int(sys.argv[2])
play = 5.0 #5 good num
use std::fs::read_dir;
use std::io::{stdin,stdout};
use std::path::Path;
use std::fs::File;
use std::io::prelude::*;
use std::env;
use colored::*;
const VIDEO_EXTENSIONS: [&str;11] = ["mp4","mkv","mov","webm","vob","wmv","avi","ogg","ogv","m4v","3gp"];
const IMAGE_EXTENSIONS: [&str;5] = ["png","jpg","jpeg","webp","bmp"];
@srtopster
srtopster / fuzzy_score.rs
Created February 15, 2024 22:58
Some made up algorithmn to score a word based on the resemblance with a test word
//Probably broken fuzzy score made by me alone
fn fuzzy_score(search: &str, test: &str) -> i32 {
let s_chars: Vec<char> = search.chars().collect();
let t_chars: Vec<char> = test.chars().collect();
let mut found_idx = Vec::new(); //keep track of match indexes to not mess up with repeated chars
let mut score: i32 = 100;
for (i,c) in s_chars.iter().enumerate() {
if let Some(pos) = t_chars.iter().enumerate().position(|(i,p)|p == c && !found_idx.contains(&i)) {
score -= ((pos.max(i)-pos.min(i))*4) as i32; //measure the distance betwen match chars and multipy by 4 to punish char misplacement more
import sys
import zlib
import lzma
import bz2
file = sys.argv[1]
bytes_buf = open(file,"rb").read()
zlib_compressed_data = zlib.compress(bytes_buf,9)
@srtopster
srtopster / binary_search.rs
Created July 15, 2023 00:00
A binary search example written in rust.
//Returns the Some(index) of x if it exists, else returns None
fn binary_search(x: usize, vector: &Vec<usize>) -> Option<usize> {
let mut high: usize = vector.len() - 1;
let mut low: usize = 0;
while low <= high {
let mid = (high + low) / 2;
if vector[mid] < x {
low = mid - 1;
} else if vector[mid] > x {
high = mid + 1;
@srtopster
srtopster / ts3_installer.py
Created July 1, 2023 01:37
A simple TeamSpeak 3 installer for linux, will work on most distros.
# A simple TeamSpeak 3 installer for linux, will work on most distros
# Files will be installed under /opt/
# .desktop file is automatically created, so it shows up on your distro's start menu
# Credit: https://gist.github.com/srtopster
# Usage: sudo python3 ts3_installer.py
import os
import getpass
import requests
@srtopster
srtopster / sieve_of_eratosthenes.rs
Last active July 1, 2023 02:03
Prime finder using Sieve of Eratosthenes algorithm implemented in Rust (update using bitvec, ~10x less ram)
//Prime finder using Sieve of Eratosthenes algorithm
//https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
//
//-> Cargo.toml
//[dependencies]
//bitvec = "1"
use bitvec::prelude::*;
fn fast_aprox_u128_sqrt(val: u128) -> u128 {
@srtopster
srtopster / typewriter.rs
Created December 10, 2022 23:39
Typewriter effect on the cli using rust.
use std::io::stdout;
use std::io::prelude::*;
use std::{thread,time};
use std::env;
fn typewrite(msg: &str) {
let letters: Vec<char> = msg.chars().collect();
for letter in letters {
print!("{}",letter);
stdout().flush().unwrap();