Skip to content

Instantly share code, notes, and snippets.

@LucasMagnum
LucasMagnum / python.py
Created October 22, 2023 14:37
Python experiment
import time
def timeit(func):
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time() - start
import functools
import random
import time
import sys
def timeit(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
import functools
import random
import time
import sys
def timeit(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
"""
Dado um string S, retorne True se todos os caracters forem
únicos e False caso exista algum duplicado.
Valores em minúsculo e maiúsculo são considerados os mesmos.
Ex:
>> is_unique("lucas")
True
@LucasMagnum
LucasMagnum / app.py
Created May 16, 2019 22:36
Flask App - Prediction
import json
from flask import Flask, request
from fastai.vision import open_image, load_learner
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = "./uploads"
@LucasMagnum
LucasMagnum / pipeline_costs.py
Created March 29, 2019 08:43
Pipeline Costs
import datetime
from collections import defaultdict
from googleapiclient.discovery import build
from prettytable import PrettyTable
service = build("dataflow", "v1b3")
def get_costs(project_id, cpu_batch_rate, cpu_streaming_rate, memory_rate, pd_rate=0, ssd_rate=0):
"""
@LucasMagnum
LucasMagnum / System Design.md
Created March 15, 2019 13:57 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
"""
Pessoa no térreo, elevador no 3 andar, prédio com 5 andares,
pessoa do térreo chamou o elevador e pessoa no 5 andar
chamou elevador pra descer.
Primeiro no 5 andar e depois no térreo
"""
class Elevador:
andar = 1
import unittest
from words_analysis import get_most_common_words
class TestWordsAnalysis(unittest.TestCase):
def test_get_most_common_words_should_return_the_expected_words(self):
data = [
'python',
@LucasMagnum
LucasMagnum / priorityqueue.py
Created October 27, 2018 09:49
Priority Queue - Python
class PriorityQueue:
"""
This priority queue uses a given number as priority order.
The smallest number has the higher priority
"""
def __init__(self):
self.queue = []
def enqueue(self, value: str, priority: int) -> None:
"""Add the value the queue based on its priority"""