Skip to content

Instantly share code, notes, and snippets.

View luchiago's full-sized avatar
🚀
Learning

Lucas Hiago luchiago

🚀
Learning
View GitHub Profile
@luchiago
luchiago / abs_vs_con.md
Created July 9, 2020 23:20
Abstract Methods vs Concret Methods

Differences between abstract methods and concrete methods

What's abstract methods

One abstract method is a method that is declared, but contains no implementation. Abstract classes cannot be instantiated, and require subclasses to provide implementations for the abstract methods. It's kinda like Interfaces in Java. Even if the methods don't implements anything, the child classes should implemente those methods.

What's concret methods

Different thant an abstract method, a concret method does implement something even the class is an Abstract Class

@luchiago
luchiago / wsgi.md
Created July 10, 2020 13:36
[BACKEND][PYTHON][DJANGO] WSGI

WSGI

Web server gateway interface From Wikpedia: Is a simple calling convention for web servers to forward requests to web applications or frameworks written in Python. Originally specified as PEP-333

The wsgi.py file in Django

It is a file that we can barely write. Or need to.

What it does

Is a web server that communicates with out application and handle all requests and responses. The django project need it, to work as a web application.

@luchiago
luchiago / drf_views.md
Created July 25, 2020 22:15
DRF Views

DRF Endpoints, how to build it

In this gist, I will show the difference between three ways to build endpoints with Django Rest Framework. The pros and cons of each one, when you should use it and so on.

Class-based Views

A REST framework provides an APIView class, which subclasses Django's View class.

What's the Django's View class

According to the docs, the View class is a callable which takes a request and returns a response. Is more than the view function because we can wrappe better the request-response flow, following REST principles

@luchiago
luchiago / fetch_json.py
Created October 8, 2020 13:03
Fetch json from an API and saves in a file
import json
import requests
def save_file(file_name, data):
with open(file_name, 'w') as file:
json_data = json.dumps(data)
file.write(json_data)
def fetch_json(url, headers={}):
response = requests.get(url, headers=headers)
@luchiago
luchiago / mdc.py
Created January 24, 2024 02:55
MDC
# MDC Maximo Divisor Comum: Maior número que é divisor de dois ou mais números simultaneamente
# Input: Lista separada por virgula com os numeros a serem testados
# Output: Número divisor
from operator import mul
from functools import reduce
def get_prime_list(n: int) -> list:
# Sieve of Erastothenes
is_prime_list = {}