This file contains hidden or 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
# Para mais conteúdos de Python, acesse: https://instagram.com/gabrielsaldanha.dev | |
# É necessário ter Pillow instalado: | |
# $ python3 -m pip install Pillow | |
from PIL import Image, ImageDraw, ImageFont | |
image = Image.new("RGB", (1080, 1080), color=(41, 46, 48)) | |
img_draw = ImageDraw.Draw(image) | |
# Arquivo de fonte Helvetica.ttc deve estar no mesmo diretório | |
# que o programa está sendo executado |
This file contains hidden or 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 time # I will use it to simulate latency with time.sleep | |
from concurrent.futures import ThreadPoolExecutor, as_completed | |
def has_facebook_account(user_email): | |
time.sleep(5) # 5 seconds! That is bad. | |
print("Finished facebook after 5 seconds!") | |
return True | |
def has_github_account(user_email): | |
time.sleep(1) # 1 second. Phew! |
This file contains hidden or 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
''' | |
Important docs | |
https://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth.getTransaction | |
https://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth.getTransactionReceipt | |
''' | |
import hashlib | |
import json | |
import os |
This file contains hidden or 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
# truffle develop | |
Truffle Develop started at http://127.0.0.1:9545/ | |
Accounts: | |
(0) 0xdfb772fba7631b5bfde93cc3e2b0e488d1a17b2a | |
(1) 0xf2d6f135c743398e370fb865ea69d3ccfb96f123 | |
(2) 0xe5f0f5700e678bb92c9414773b9a9fad1f730d17 | |
(3) 0x69ffe89931711b15db6d5cd7b181c940dc83cabe | |
(4) 0x19f802fb5bda9631792e58208baba2e0ce7cc7ef |
This file contains hidden or 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 has_facebook_account(user_email): | |
print('calling Facebook service') | |
return False | |
def has_github_account(user_email): | |
print('calling Github service') | |
return True | |
def has_twitter_account(user_email): | |
print('calling Twitter service') |
This file contains hidden or 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 time | |
from functools import wraps | |
def timing(decorated): | |
@wraps(decorated) | |
def decorator(*args, **kwargs): | |
print(f'Calling {decorated.__name__} function') | |
start_time_time = time.time() | |
start_time_perf = time.perf_counter() |
This file contains hidden or 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 get_largest_prime_factor(number): | |
prime_factors = [] | |
divisor = 1 | |
i = 1 | |
while(i <= number // divisor): # integer division | |
if number % i == 0: # if number is divisible by i | |
divisor = i # found a divisor, is used in line 5 to "short" the stop clause | |
if is_prime(divisor): # filter only prime divisors (factors) | |
prime_factors.append(divisor) | |
i += 1 |
This file contains hidden or 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 find_factors(number): | |
factors = [] | |
for factor in range(1, number + 1): # makes range go from 1 to number (inclusive) | |
if number % factor == 0: | |
factors.append(factor) | |
return factors | |
# Or by using list comprehensions | |
def find_factors_comprehesion(number): | |
return [factor for factor in range(1, number + 1) if number % factor == 0] |
This file contains hidden or 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 flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello(): | |
return 'Hello, World!' | |
if __name__ == '__main__': | |
app.run() |
This file contains hidden or 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 dis | |
def non_empty_set_literal(): | |
return {1, 2, 3} # Build a set {1, 2, 3} | |
def non_empty_set_method(): | |
return set([1, 2, 3]) # Builds a set {1, 2, 3} from a list | |
def empty_set_literal(): |