Skip to content

Instantly share code, notes, and snippets.

View luabida's full-sized avatar
🌙
路安

Luã B. Vacaro luabida

🌙
路安
  • FGV Rio
  • Brazil
  • 01:33 (UTC -03:00)
View GitHub Profile
@luabida
luabida / rust_frameworks.md
Created February 19, 2024 01:09
Rust Frameworks

Debugging

  • color_eyre
@luabida
luabida / generic_retangle.rs
Created February 18, 2024 09:48
[rs] Generic Types // Retangle
use std::marker::Copy;
fn main() {
let r1 = Retangle {
width: 50,
height: 30.5,
};
println!("{:?}", r1.get_area())
}
@luabida
luabida / get_type.rs
Last active February 19, 2024 17:43
[rs] Get type
fn print_type<T>(_: &T) {
println!("{}", std::any::type_name::<T>())
}
@luabida
luabida / normalize.py
Created May 18, 2023 18:08
Normalize string
import unicodedata
def normalize_str(string: str) -> str:
non_ascii = (
unicodedata.normalize("NFKD", string).encode("ascii", "ignore").decode()
)
string = non_ascii.lower().replace(" ", "_")
@luabida
luabida / smallest_webserver.py
Last active February 11, 2023 18:58
Smallest Python Webserver - by Dr. Charles Severance
from socket import *
def createServer():
serversocket = socket(AF_INET, SOCK_STREAM)
try:
serversocket.bind(('localhost',9000))
print('Starting server at http://127.0.0.1:9000/')
serversocket.listen(5)
while(1):
(clientsocket, address) = serversocket.accept()
@luabida
luabida / last_month_range.py
Created January 15, 2023 13:31
Calculates the first and the last day of previous datetime month.
from datetime import datetime
import calendar
def calc_last_month_range(date: datetime) -> tuple:
if date.month == 1:
ini_date = datetime(date.year - 1, 12, 1)
else:
ini_date = datetime(date.year, date.month - 1, 1)
end_date = datetime(
@luabida
luabida / bisect.py
Created January 10, 2023 22:02
Bisect: bisect() & insort()
import bisect
import random
# bisect()
def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'):
i = bisect.bisect(breakpoints, score)
return grades[i]
[grade(score) for score in [33, 99, 77, 70, 89, 90, 100]]
# ['F', 'A', 'C', 'C', 'B', 'A', 'A']
@luabida
luabida / approximation_algorithm.py
Created January 6, 2023 22:50
Square root calculator with Recursion.
def next_(n, x):
return (x + n / x) / 2
# Repeats infinitely
def repeat(f, a):
yield a
for v in repeat(f, f(a)):
yield v
# Delimiter
@luabida
luabida / primes.py
Created January 3, 2023 14:48
Recursion & Laziness Evaluation | First 100 positive prime numbers
def positives(n):
yield n
yield from positives(n+1)
def primes(s):
n = next(s)
yield n
yield from primes(i for i in s if i%n != 0)
@luabida
luabida / repeat.py
Last active November 29, 2022 14:19
Profiling using `timeit.repeat()`, with Min, Mean and Max
from timeit import repeat
from statistics import mean
def stats(stmt, r=100):
res = repeat(stmt, globals=globals(), repeat=r)
print(f'Avg: {mean(res)}\nMin: {min(res)}\nMax: {max(res)}')
"""
def foo():
return 1+1