- color_eyre
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::marker::Copy; | |
fn main() { | |
let r1 = Retangle { | |
width: 50, | |
height: 30.5, | |
}; | |
println!("{:?}", r1.get_area()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn print_type<T>(_: &T) { | |
println!("{}", std::any::type_name::<T>()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unicodedata | |
def normalize_str(string: str) -> str: | |
non_ascii = ( | |
unicodedata.normalize("NFKD", string).encode("ascii", "ignore").decode() | |
) | |
string = non_ascii.lower().replace(" ", "_") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder