Skip to content

Instantly share code, notes, and snippets.

View sgraaf's full-sized avatar

Steven van de Graaf sgraaf

View GitHub Profile
@sgraaf
sgraaf / Chrome_versions.ipynb
Created September 15, 2022 12:54
Scrape recent Chrome and Firefox version numbers
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sgraaf
sgraaf / pdutils.py
Last active July 2, 2022 13:46
Pandas utility functions
import csv
from pathlib import Path
from typing import Optional, Union, Sequence, List, Literal
import pandas as pd
from tqdm import tqdm
def read_csv(
file: Path,
@sgraaf
sgraaf / ISO 4217-1 with currency symbols.ipynb
Created August 9, 2021 19:36
ISO 4217 w/ currency symbols
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sgraaf
sgraaf / ISO 3166-1 table.html
Last active August 9, 2021 19:33
ISO 3166-1 countries w/ common names
<table role="grid" aria-rowcount="250">
<thead role="rowgroup" class="v-grid-header">
<tr class="v-grid-row" role="rowheader" style="width: 1445.62px;">
<th style="height: 30px; width: 361.367px;" class="v-grid-cell sortable sort-asc" role="columnheader" colspan="1" aria-sort="ascending">
<div class="v-grid-column-header-content v-grid-column-default-header-content">English short name</div>
</th>
<th style="height: 30px; width: 401.983px;" class="v-grid-cell sortable" role="columnheader" colspan="1" aria-sort="none">
<div class="v-grid-column-header-content v-grid-column-default-header-content">French short name</div>
</th>
<th style="height: 30px; width: 236.717px;" class="v-grid-cell sortable" role="columnheader" colspan="1" aria-sort="none">
@sgraaf
sgraaf / PyPI_available_package_names.txt
Last active May 29, 2021 12:53
Find available PyPI package names of a certain length.
z
ak
al
fl
fm
gi
gu
gv
hj
hk
@sgraaf
sgraaf / matplotlib_animated_gif.py
Created November 23, 2020 09:55
Create an animated gif using matplotlib (& PIL)
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation, PillowWriter
# initialize the figure
fig, ax = plt.subplots()
fig.set_tight_layout(True)
ax.set_xlim(0, 2 * np.pi)
ax.set_ylim(-1, 1)
from typing import Tuple
def quadkey_to_xy(quadkey: str) -> Tuple[int, int]:
x, y = (0, 0)
level = len(quadkey)
for i in range(level):
bit = level - i
mask = 1 << (bit - 1)
if quadkey[level - bit] == '1':
x |= mask
@sgraaf
sgraaf / rotatingproxysession.py
Created October 14, 2020 16:46
A requests Session that rotates (free) proxies for GET-requests.
from itertools import cycle
from lxml import html
from requests import Response, Session
class RotatingProxySession(Session):
def __init__(self) -> None:
super().__init__()
@sgraaf
sgraaf / rotatinguasession.py
Last active December 26, 2022 00:26
A requests Session that rotates its user-agent for GET-requests.
# coding: utf-8
from itertools import cycle
from pathlib import Path
from typing import Optional
from lxml import html
from requests import Response, Session
class RotatingUASession(Session):
@sgraaf
sgraaf / concurrentsession.py
Created October 14, 2020 15:06
A requests Session that can make concurrent GET and POST-requests.
import os
from concurrent.futures import Future, ThreadPoolExecutor
from functools import partial
from itertools import repeat
from typing import Any, Dict, List, Optional, Union
from requests import Response, Session
class ConcurrentSession(Session):