Skip to content

Instantly share code, notes, and snippets.

View bbelderbos's full-sized avatar

Bob Belderbos bbelderbos

View GitHub Profile
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 functools
@functools.cache
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
fib(35)
== 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'
from pprint import pprint as pp
import random
import requests
def get_random_tip():
url = "https://codechalleng.es/api/pytips/"
response = requests.get(url)
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
}
function openrepo {
url="$(git remote get-url origin)"
open "https://github.com/$(echo "$url" | sed 's,.*github.com[:/],,')"
}
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 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 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)}
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<h1>Some places I have visited over the years:</h1>
<div id="folium"></div>
<py-config>
packages = ["folium"]