Skip to content

Instantly share code, notes, and snippets.

import requests
from bs4 import BeautifulSoup
import pandas as pd
import re
from datetime import datetime
# Function to parse dates with different formats
def parse_date_flexible(date_str):
for fmt in ("%b %d %Y", "%B %d %Y", "%b %d, %Y", "%B %d, %Y"):
@jkbjh
jkbjh / jax_cookbook.md
Created June 24, 2025 10:41
jax cookbook

One-time differentiable function (locally linearized function):

def f_linearized(x):
    _, f_lin = jax.lax.stop_gradient(jax.linearize(f, x))
    return f_lin(x)

Differentiate with respect to internal variable ("perturbation trick"):

@jkbjh
jkbjh / pdfstatistics.py
Created February 11, 2025 14:07
Download all pdfs from a page/ check pdf file statistics -- pages, word count, characters
#!/usr/bin/env python3
import os
import tempfile
import subprocess
import fitz # PyMuPDF for reading PDFs
import re
import statistics
import argparse
@jkbjh
jkbjh / load-mujoco-210.sh
Last active October 27, 2023 11:45
load-mujoco-210.sh
#!/bin/bash
set -e
# you can directly run this with: bash <(curl -Ls "https://gist.githubusercontent.com/jkbjh/c83e5bf6d708f590f77ccdd6b2ef0a40/raw/mujoco-210-user-install.sh?$(date +%s)")
# (the date query parameter is to to prevent caching when downloading through curl.)
export START_DIR=$(pwd)
export MJ_DIR=$HOME/.mujoco
# Check if the file exists
if [ -e "$MJ_DIR/mujoco210/bin/compile" ]; then
echo "mujoco already there, not downloading."
@jkbjh
jkbjh / git-copush
Last active February 8, 2023 19:47
push to a remote checked out repository (by pushing into a temporary branch and then ssh-ing to the repository and performing the merge)
#!/usr/bin/env python
import argparse
import re
import subprocess
import sys
import uuid
url_rex = re.compile(
"^(?P<user>.*?)@(?P<host>.*?):(?:(?P<port>[0-9]*?))?(?P<path>.*?/.*?)$"
)
@jkbjh
jkbjh / arxivit.py
Created November 10, 2022 16:08
helper util to package arxiv submissions
#!/usr/bin/env python
import argparse
import subprocess
import shlex
import shutil
import sys
def check_programs(*progs):
all_success = True
@jkbjh
jkbjh / at-covid19.py
Last active November 19, 2021 12:38
Plot covid incidence / death numbers for selected countries (austria+neighbors+uk)
#!/usr/bin/env python3
import pandas as pd
import matplotlib.pyplot as plt
import countryinfo # for populations
FUTURE = 28
POPULATION = {
"Czechia": countryinfo.CountryInfo("Czech Republic").population(),
}
#!/bin/bash
set -e
set -x
# you can directly run this with: bash <(curl -Ls "https://gist.githubusercontent.com/jkbjh/c83e5bf6d708f590f77ccdd6b2ef0a40/raw/mujoco-210-user-install.sh?$(date +%s)")
# (the date query parameter is to to prevent caching when downloading through curl.)
export START_DIR=$(pwd)
export MJ_DIR=$HOME/.mujoco
mkdir -p $MJ_DIR
pushd $MJ_DIR
curl -LJ 'https://github.com/deepmind/mujoco/releases/download/2.1.0/mujoco210-linux-x86_64.tar.gz' -o $MJ_DIR/mujoco210_linux.tgz
import collections
JointInfo = collections.namedtuple(
"JointInfo",
[
"index",
"name",
"type",
"q_index",
# a selection of small numpy helper functions
import joblib
def apply_along_axes(func, data, axes):
"""
apply function along axes and use joblib parallel to execute the function on the selections.
might result in a large allocation for reconstructing the result.
only makes sense if the sub-executions are sufficiently costly.
"""