Skip to content

Instantly share code, notes, and snippets.

View jelmervdl's full-sized avatar

Jelmer jelmervdl

View GitHub Profile
def expand(expr:str):
if (match := re.search(r"\{(.+?)\}", expr)):
prefix = expr[:match.start()]
for val in match.group(1).split(','):
for suffix in expand(expr[match.end():]):
yield prefix + val + suffix
else:
yield expr
import multiprocessing as mp
from functools import wraps
from typing import Callable, Iterable, ParamSpec, TypeVar, Union
class EndOfIter:
"""Signals end of the offloaded iterator"""
exc: Optional[Exception]
@jelmervdl
jelmervdl / npzpy.py
Created November 7, 2023 15:07
Inspect npz from a distance
#!/usr/bin/env python3
from zipfile import ZipFile
from numpy.lib.format import read_magic, _read_array_header
import httpio
import csv
import sys
out = csv.DictWriter(sys.stdout, ['name', 'shape', 'dtype'], dialect='excel-tab')
with httpio.open(sys.argv[1]) as zfh:
@jelmervdl
jelmervdl / seed-cache.html
Created April 15, 2017 14:05
Geoserver Tile Cache seeding tool
<!DOCTYPE html>
<html>
<head>
<title>Seed tool</title>
<style>
.seed-status {
display: inline-block;
padding; 2px;
background: #ccc;
}
def print_cells(*rows, format:Callable[[Any],str]=repr,file=None) -> None:
# Convert it all to text
text_rows = [
[format(cell) for cell in row]
for row in rows
]
# Calculate column width
widths = [
max(len(cell) for cell in column)
#!/usr/bin/env python3
# Script that reads sentences scored with hardrules
# prints the 0's directly to stdout
# and passes the sentences with 1 to the subprocess bicleaner score
import sys
import subprocess
from threading import Thread
from queue import SimpleQueue
from itertools import chain
@jelmervdl
jelmervdl / download.py
Created May 17, 2023 11:16
Resumeable downloads with plain Python
#!/usr/bin/env python3
import sys
import os
from argparse import ArgumentParser
from contextlib import ExitStack
from email.utils import parsedate_to_datetime
from http.client import HTTPResponse
from shutil import copyfileobj
from tempfile import TemporaryFile

Language models are not computers. I'd say, they're terrible at reasoning because they can't follow simple instructions correctly. If it can't do this, then why should it be able to do its own logical reasoning?

Jelmer:

Are there more ones or more zeros in the following sequence: 1111111100000111111110000000000

ChatGPT:

To determine whether there are more ones or zeros in the sequence "1111111100000111111110000000000", we can simply count the number of ones and zeros in the sequence and compare them.

Counting the number of ones in the sequence, we get:

@jelmervdl
jelmervdl / slog
Created April 11, 2023 11:28
Slurm utilities
#!/bin/bash
set -euo pipefail
scontrol show job $1 |
grep -oP '(?<=StdErr=).*' |
xargs less -SN
@jelmervdl
jelmervdl / readwritelock.py
Created March 22, 2023 11:51
Untested readwritelock for Python threading
class ReadWriteLock:
def __init__(self):
self.readers = 0
self.lock = threading.Condition(threading.Lock())
@contextmanager
def lock_for_reading(self):
self.lock.acquire()
try:
self.readers += 1