Skip to content

Instantly share code, notes, and snippets.

View bbelderbos's full-sized avatar

Bob Belderbos bbelderbos

View GitHub Profile
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)}
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)
}
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()
function openrepo {
url="$(git remote get-url origin)"
open "https://github.com/$(echo "$url" | sed 's,.*github.com[:/],,')"
}
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
}
from pprint import pprint as pp
import random
import requests
def get_random_tip():
url = "https://codechalleng.es/api/pytips/"
response = requests.get(url)
== 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'
import functools
@functools.cache
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
fib(35)
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()
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: