Skip to content

Instantly share code, notes, and snippets.

View bbelderbos's full-sized avatar

Bob Belderbos bbelderbos

View GitHub Profile
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"]
city_coords = {
"Amsterdam": ["52.34996869", "4.916640176"],
"Barcelona": ["10.13037518", "-64.72001367"],
"Berlin": ["52.52181866", "13.40154862"],
"Biarritz": ["43.47327537", "-1.561594891"],
"Brussels": ["50.83331708", "4.333316608"],
"Bucharest": ["44.4333718", "26.09994665"],
"Edinburgh": ["55.94832786", "-3.219090618"],
"Florence": ["34.19567629", "-79.76279057"],
"København": ["55.67856419", "12.56348575"],
import csv
from urllib.request import urlretrieve
GEO_DATA = (
"https://raw.githubusercontent.com/pybites/"
"100DaysOfCode/master/050/simplemaps-worldcities-basic.csv"
)
CITIES = [
"Amsterdam",
"Paris",
<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>Time left till New Year:</h1>
<h2 id="showtime"></h2>
<py-config>
packages = ["python-dateutil"]
>>> from datetime import datetime
>>> import time
>>> import sched
>>> s = sched.scheduler(time.time, time.sleep)
>>> def hydrate(sc):
... print(datetime.now(), "Sip water!")
... s.enter(300, 1, hydrate, (sc,))
...
>>> s.enter(300, 1, hydrate, (s,))
Event(time=1611405298.4987588, priority=1, action=...