This file contains 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 pathlib import Path | |
import concurrent.futures | |
from fake_useragent import UserAgent | |
import requests | |
ARTICLE_ENDPOINT = "https://codechalleng.es/api/articles/" | |
ARTICLE_LINKS = Path("links") | |
DOWNLOADS_FOLDER = Path("downloads") | |
HEADERS = {"User-Agent": str(UserAgent().chrome)} |
This file contains 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
function pys { | |
if [ "$#" -eq 1 ]; then | |
# show source of module | |
search=$1 | |
else | |
# show source of module -> object | |
search=$1:$2 | |
fi | |
(python -m inspect $search|less) | |
} |
This file contains 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 time import time, sleep | |
from functools import wraps | |
def timeit(func): | |
@wraps(func) | |
def wrapped(*arg, **kwargs): | |
start = time() | |
result = func(*arg, **kwargs) | |
end = time() |
This file contains 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
function openrepo { | |
url="$(git remote get-url origin)" | |
open "https://github.com/$(echo "$url" | sed 's,.*github.com[:/],,')" | |
} |
This file contains 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
function openrepo { | |
git_url=$(git remote -v | grep "^origin\s" | awk '{print $2}' | head -n1) | |
git_url_https=$(echo $git_url | sed 's@.*\.com[:/]@https://github.com/@g') | |
open $git_url_https | |
} |
This file contains 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 pprint import pprint as pp | |
import random | |
import requests | |
def get_random_tip(): | |
url = "https://codechalleng.es/api/pytips/" | |
response = requests.get(url) |
This file contains 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
== 1. save time == | |
alias python3=python3.11 | |
alias ae='source venv/bin/activate' | |
alias pvenv='python3 -m venv venv && ae' | |
alias pipall="python -m pip install -r requirements.txt" | |
alias pipfr="python -m pip freeze >|requirements.txt" | |
alias dl='cd ~/Downloads' |
This file contains 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 functools | |
@functools.cache | |
def fib(n): | |
if n < 2: | |
return n | |
return fib(n-1) + fib(n-2) | |
fib(35) |
This file contains 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 functools import wraps | |
from time import time, sleep | |
def timing(f): | |
"""A simple timer decorator""" | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
start = time() | |
result = f(*args, **kwargs) | |
end = time() |
This file contains 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 ast | |
from pathlib import Path | |
import sys | |
def check_for_else_in_module(module_path): | |
with open(module_path, "r") as file: | |
try: | |
tree = ast.parse(file.read()) | |
except SyntaxError: |