Skip to content

Instantly share code, notes, and snippets.

View RHDZMOTA's full-sized avatar
👨‍💻
More info at: rhdzmota.com

Rodrigo H. Mota RHDZMOTA

👨‍💻
More info at: rhdzmota.com
View GitHub Profile
34.62365962451697 78.0246928153624 0
30.28671076822607 43.89499752400101 0
35.84740876993872 72.90219802708364 0
60.18259938620976 86.30855209546826 1
79.0327360507101 75.3443764369103 1
45.08327747668339 56.3163717815305 0
61.10666453684766 96.51142588489624 1
75.02474556738889 46.55401354116538 1
76.09878670226257 87.42056971926803 1
84.43281996120035 43.53339331072109 1
import io
import pandas as pd
import requests
data_url = "https://gist.githubusercontent.com/noamross/e5d3e859aa0c794be10b/raw/cars.csv"
data_string = requests.get(data_url).text
df = pd.read_csv(io.StringIO(data_string), index_col=0)
@RHDZMOTA
RHDZMOTA / hello-world.py
Last active November 8, 2021 06:06
PyCo Snippets: Hello world python script
import os
HELLO_WORLD_DEFAULT = os.environ.get(
"HELLO_WORLD_DEFAULT",
default="World"
)
def hello(world: str = HELLO_WORLD_DEFAULT) -> str:
return f"Hello, {world}!"
@RHDZMOTA
RHDZMOTA / pycosnippets-command.sh
Created November 8, 2021 06:06
PyCo Snippets: Commandline Usage Example
pycosnippets run-gist \
--user rhdzmota \
--file hello-world.py \
--gist-id 42bcb9e078cae8694f1240808232a2ac
@RHDZMOTA
RHDZMOTA / swapcase.py
Last active November 10, 2021 19:13
Swap-case in Python without using the swapcase built-in method.
# Challenge: implement swapcase without using the built-in method
def swapcase(string: str) -> str:
return "".join(
char.lower() if char.isupper() else char.upper()
for char in string
)
assert swapcase("AbCd") == "aBcD"
@RHDZMOTA
RHDZMOTA / scalene-profiler.sh
Created November 12, 2021 22:49
Example usage: Scalene python profiler
scalene \
--profile-all \
--reduced-profile \
--cpu-percent-threshold 1 \
my_script.py
@RHDZMOTA
RHDZMOTA / style-check.sh
Created November 12, 2021 23:32
Example: Pycodestyle command
pycodestyle . --max-line-length=120 --exclude venv
name: Check Python Style
on: [pull_request]
jobs:
build:
name: Style Check
runs-on: ubuntu-18.04
steps:
- name: clone-repo
from typing import List, Tuple, Optional
RETURN_TYPE = Optional[Tuple[List[int], List[int]]]
def bisect(my_list: List[int], max_val: int) -> RETURN_TYPE:
partial_sum = 0
for i, val in enumerate(my_list):
partial_sum += val
if partial_sum > max_val:
import inspect
import json
from typing import Dict, TypeVar
SerializableDataType = TypeVar(
"SerializableDataType",
bound="Serializable"
)