Skip to content

Instantly share code, notes, and snippets.

View danmackinlay's full-sized avatar

dan mackinlay danmackinlay

View GitHub Profile
@danmackinlay
danmackinlay / quarto_thumbnail.py
Last active December 29, 2024 07:59
A post_render script for quarto which generates thumbnails for all .qmd files for which it can guess
#!/usr/bin/env python
r"""
Update doc metadata by parsing HTML version for images, generating thumbnails of the first admissible image, and updating the metadata with the thumbnail URL.
"""
from pathlib import Path
import subprocess
import argparse
import logging
from ruamel.yaml import YAML
@danmackinlay
danmackinlay / vscode_cleanup.sh
Created November 27, 2024 06:08
delete all but the latest copies of VS Code on the remote server.
#!/bin/bash
# === VSCode Server Cleanup Script ===
# Description:
# This script cleans up specified VSCode server directories by deleting all
# subdirectories except the two most recently modified ones.
#
# Usage:
# ./vscode_cleanup.sh [--dry-run]
#
@danmackinlay
danmackinlay / README.md
Last active December 11, 2024 03:07
Search rijksmuseum prints in English

Search rijksmuseum prints in english

Rijksmuseum's online collection is amazing but their search defaults do not suit me.

This script automates searching using my favourite options (restrict to prints, visible online)

Features

@danmackinlay
danmackinlay / LICENSE
Created October 24, 2024 08:37
Walk a list of Quarto or RMarkdown files, and tidy them up with the ChatGPT API
Copyright CSIRO 2024
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALI

Migrate from blogdown to quarto

As mentioned on my blog, it is helpful to process blog posts to get maximum benefit out of quarto when migrating from blogdown.

This is the script I used. Feel free to use it, modify it and so on.

(c) 2023 Dan Mackinlay

Released under the terms of the MIT license

@danmackinlay
danmackinlay / README.md
Last active October 1, 2024 23:34
try to kill and restart quarto

restart quarto preview server

As per my blog I think quarto is best if you turn it off an on again.

My fix to the many weird bugs and misfeatures in quarto preview is to continually restart preview server. I also try to turn off as much “smart” stuff as possible, disabling the file watcher and the browser navigation. This seems to help both in memory usage and making sure that it serves current content. Currently I do this manually, by running it in a shell and doing a ^C to kill it.

I attempted to define a helper function which kills the quarto process and restarts it automatically, but the wily quarto process seems to evade my attempts to kill it by spawning detached subprocesses or something, so it doesn’t work.

"""
An example of the score function gradient estimator, a.k.a.
[REINFORCE](http://stillbreeze.github.io/REINFORCE-vs-Reparameterization-trick/)
written to provide a concrete example to a blog post on
[Monte Carlo gradient estimation](https://danmackinlay.name/notebook/mc_grad.html).
This method can estimate very general estimands.
In this case we will try to find the parameters which minimises a difference
between the categorical distribution we sample from, and some target distrbution.
"""
@danmackinlay
danmackinlay / README.md
Last active September 23, 2024 06:13
Ax + SLURM via `submitit` and `asyncio`

async_ax

Asynchronous hyperparam search using Ax and the submitit executor, to run on SLURM.

Supports resumption of incomplete optimisations from disk, and incremental/partial optimisation, I think.

Note: slurm/submitit is now officially supported by Ax

Refs

@danmackinlay
danmackinlay / zot_bib.py
Last active August 15, 2021 23:51
script to decorate .Rmd files with bibliography files from my local zotero installation
#! /usr/bin/env python
"""
Export Zotero biblographies for my blog using betterbibtex export support
http://retorque.re/zotero-better-bibtex/exporting/pull
Usage:
From the root of a blogdown blog, run
```

Git pre-commit hook for large files

This hook warns you before you accidentally commit large files to git. It's very hard to reverse such an accidental commit, so it's better to prevent it in advance.

Since you will likely want this script to run in all your git repos, a script is attached to add this hook to all git repos you create / clone in the future.

Of course, you can just download it directly to the hooks in an existing git repo.