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
| # O interpretador Python vai sempre procurar pela variável no escopo "local" | |
| # antes de olhar para o escopo global. Por exemplo, veja as funções abaixo `somar` e `somar_2` | |
| a = 10 # Variável global | |
| def somar(a, b): | |
| # a, b: variáveis locais – parâmetros da função | |
| return a + b | |
| def somar_2(b): # Apenas um parâmetro "b" |
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
| # https://www.django-rest-framework.org/api-guide/fields/#error_messages | |
| from rest_framework import serializers as s | |
| class User(s.Serializer): | |
| name = s.CharField(error_messages={"blank": "This is a custom message! Yeah!"}) | |
| user = User(data={"name": ""}) | |
| user.is_valid() |
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
| #include <cs50.h> | |
| #include <stdio.h> | |
| int main(void) | |
| { | |
| int n; | |
| do | |
| { | |
| n = get_int("Size: "); | |
| } |
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 |