Skip to content

Instantly share code, notes, and snippets.

View joffilyfe's full-sized avatar

Joffily joffilyfe

  • 22:39 (UTC +01:00)
View GitHub Profile
@joffilyfe
joffilyfe / entry_point_action_authorizer_pattern.py
Created December 10, 2023 16:10
Implements the EntryPoint command pattern in Python
from typing import Any, List, Optional, TypeVar, Generic, Protocol, ClassVar, Sequence, Union, Iterable
from polls.models import Question
class BaseAuthorizer:
"""BaseAuthorizer defines how child classes should behavior
when called by EntryPoints"""
def __init__(self, entry_point: "BaseEntryPoint") -> None:
self.entry_point = entry_point
@joffilyfe
joffilyfe / query_object_pattern.py
Created December 10, 2023 13:53
Implementation of Query Object using Django ORM and python meta classes
import datetime
from django.utils import timezone
from polls import models
class Meta(type):
def __getattribute__(cls, name: str):
if name == "objects" and cls.MODEL:
return getattr(cls.MODEL, name)
# frozen_string_literal: true
require_relative 'counter'
module SmartParser
module Counters
# Count the most visited path
class MostVisitedCounter < Counter
# Parse the received line using the @line_regex and counts
# how many times the parsed `path` was received.
@joffilyfe
joffilyfe / System Design.md
Last active September 2, 2021 22:28 — 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?
import logging
from typing import List
import scrapy
LOGGER = logging.getLogger(__name__)
IGNORE_PATTERNS_LIST = ["pressreleases", "blog", "@", "#", "javascript"]
@joffilyfe
joffilyfe / resultado-das-consultas.md
Last active September 9, 2020 14:14
Tempo médio de processamento por task
           Task           | Média de execução em segundos |     Intervalo selecionado     
--------------------------+-------------------------------+-------------------------------
 register_update_docs_id  |              260.615122870588 | Entre 08-09-2020 e 09-09-2020
 link_documents_task_id   |              51.7884887882353 | Entre 08-09-2020 e 09-09-2020
 optimize_package_task_id |               45.316615255814 | Entre 08-09-2020 e 09-09-2020
 list_docs_task_id        |              29.0560280229885 | Entre 08-09-2020 e 09-09-2020
 delete_docs_task_id      |               28.986991954023 | Entre 08-09-2020 e 09-09-2020
S1517-106X2013000200012
S1517-106X2012000100007
S1414-753X2003000300008
S1414-753X2001000800007
S1414-753X1999000200004
S1414-753X2013000400006
S1414-753X2009000100004
S1414-753X2014000300005
S1414-753X2014000300013
S1414-753X2013000100006
5d4
< "_": "",
11d9
< "_": "",
17c15,19
< "_": "",
---
> "c": "CSP-hggd",
> "l": "en",
> "t": "Editorial"
import abc
import os
import re
import shutil
import logging
import tempfile
import zipfile
import threading
from datetime import datetime
@joffilyfe
joffilyfe / csv_to_sql.py
Last active May 20, 2020 18:13
Converts an CSV file to SQL insert file
import csv
import argparse
def translate_to_sql(source_file, output_file, table, skip_header=False, columns=[]):
if skip_header and len(columns) == 0:
raise TypeError(
"É preciso informar as colunas quando o cabeçalho do CSV é evitado"
)