Skip to content

Instantly share code, notes, and snippets.

View willy-r's full-sized avatar
👋
Hello, there!

William Rodrigues willy-r

👋
Hello, there!
  • Pacujá, Ceará, Brazil
View GitHub Profile
@willy-r
willy-r / configurar_pyenv.md
Created October 16, 2022 20:41 — forked from luzfcb/configurar_pyenv.md
instalar pyenv no ubuntu
@willy-r
willy-r / comandos-docker
Created October 9, 2021 15:21 — forked from morvanabonin/comandos-docker
Comandos do Docker
Segue a lista de comandos docker e sua utilidade:
docker attach – Acessar dentro do container e trabalhar a partir dele.
docker build – A partir de instruções de um arquivo Dockerfile eu possa criar uma imagem.
docker commit – Cria uma imagem a partir de um container.
docker cp – Copia arquivos ou diretórios do container para o host.
docker create – Cria um novo container.
docker diff – Exibe as alterações feitas no filesystem do container.
docker events – Exibe os eventos do container em tempo real.
docker exec – Executa uma instrução dentro do container que está rodando sem precisar atachar nele.
@willy-r
willy-r / tmdb_api.py
Last active April 19, 2021 19:32
How to get some details of a movie using TMDB API.
# https://www.themoviedb.org/
from pprint import pprint
import requests
def get_json(path, **params):
url = f'https://api.themoviedb.org/3/{path}'
all_params = {'api_key': 'your_api_key'} | params
@willy-r
willy-r / ternario.py
Created December 30, 2020 03:48
Exemplo de ternário.
preco_maca = 2.5 * maca if maca <= 5 else 2.2 * maca
@willy-r
willy-r / find_2020.py
Created December 28, 2020 07:22
You’re given a string of characters that are only 2s and 0s. Return the index of the first occurrence of “2020” without using the indexOf (or similar) function, and -1 if it’s not found in the string.
def find(s: str) -> int:
if not isinstance(s, str) or not all(c in {'2', '0'} for c in s):
return -1
i = 0
while i < len(s):
if s[i:i + 4] == '2020':
return i
i += 1
return -1
@willy-r
willy-r / remove_folder.py
Created December 15, 2020 03:59
Given a list of folders in a filesystem and the name of a folder to remove, return the new list of folders after removal.
def remove_folder(folders: list[str], folder_to_rm: str) -> list[str]:
if not folders:
return folders
if not isinstance(folder_to_rm, str):
raise ValueError('Enter a valid folder name')
new_folders = []
for i, folder in enumerate(folders):
folder_names = folder.split('/')[1:]
@willy-r
willy-r / array_diff.py
Created December 1, 2020 18:16
Given an array of integers and a target value, return the number of pairs of array elements that have a difference equal to a target value.
def array_diff(arr: list[int], n: int) -> int:
count = 0
for i in range(len(arr)):
for j in range(i + 1, len(arr)):
if arr[i] - arr[j] == n or arr[j] - arr[i] == n:
count += 1
return count
def test_example():
@willy-r
willy-r / perfect_square.py
Last active November 26, 2020 23:44
Given a positive integer n, write a function that returns true if it is a perfect square and false otherwise. Don’t use any built-in math functions like sqrt.
def perfect_square(n: int) -> bool:
if n < 0 or not isinstance(n, int):
raise ValueError(f'{n} -> must be integer and non-negative')
return int(n ** 0.5) ** 2 == n
def perfect_square_binary_search(n: int) -> bool:
if n < 0 or not isinstance(n, int):
raise ValueError(f'{n} -> must be integer and non-negative')
@willy-r
willy-r / special_pairs.py
Created November 21, 2020 00:51
Given an array of integers arr, a pair (n,m) is called “special” if arr[n] == arr[m], and n < m. Return the number of special pairs.
def is_spair(arr: list[int], n: int, m: int) -> bool:
return arr[n] == arr[m] and n < m
def special_pairs_list_comprehension(arr: list[int]) -> int:
return len(
[(arr[i], arr[j])
for i in range(len(arr))
for j in range(i + 1, len(arr))
if is_spair(arr, i, j)]
@willy-r
willy-r / character_jump.py
Created November 2, 2020 18:07
You have a character who jumps forward n number of units at a time, and an array representing the road in front of them (where 0 is a flat piece of road, and 1 is an obstacle). Return true or false if your character can jump to the end without hitting an obstacle in front of them.
def character_jump(jump: int, road: list[int]) -> bool:
return 1 not in road[::jump]
if __name__ == '__main__':
CASES = (
(3, [0, 1, 0, 0, 0, 1, 0], True),
(4, [0, 1, 1, 0, 1, 0, 0, 0, 0], False),
(4, [0, 0, 0, 0, 0, 0, 0, 1], True),
(1, [0, 1, 0, 1, 0, 1], False),