Simon Willison’s Weblog

Subscribe

TILs

Filters: Sorted by date

TIL Combining substr and instr to extract text — Derek Willis has [a Datasette instance full of political campaign emails](https://political-emails.herokuapp.com/) running on Heroku.
TIL nullglob in bash — I ran into a tricky problem while working [on this issue](https://github.com/simonw/datasette-publish-fly/issues/17): the following line was behaving in an unexpected way for me:
TIL Enabling a user to execute a specific command as root without a password — I wanted a script running as a non-root user to be able to restart a systemd service on my Ubuntu machine without needing a password.
TIL Annotated package.json for idb-keyval — Jake Archibald [pointed to](https://twitter.com/jaffathecake/status/1491771402294370306) his `package.json` for `idb-keyval` as a "modernish example" of NPM packaging on Twitter this morning.
TIL Ordered group_concat() in SQLite — I was trying to use `group_concat()` to glue together some column values into a stiched together Markdown document. My first attempt looked like this:
TIL Testing against Python 3.11 preview using GitHub Actions — I decided to run my CI tests against the Python 3.11 preview, to avoid the problem I had when Python 3.10 came out with [a bug that affected Datasette](https://simonwillison.net/2021/Oct/9/finding-and-reporting-a-bug/).
TIL get-graphql-schema — The GraphQL schema language is a concise way to represent the available schema provided by a GraphQL endpoint. It looks something like this:
TIL Opt-in integration tests with pytest --integration — For both [s3-credentials](https://github.com/simonw/s3-credentials) and [datasette-publish-fly](https://github.com/simonw/datasette-publish-fly) I have a need for real-world integration tests that actually interact with the underlying APIs (AWS or Fly) to create and destroy resources on those platforms.
TIL Using the undocumented Fly GraphQL API — [Fly](https://fly.io/) has a GraphQL API which is used by some of their own tools - I found it while [browsing around their code](https://github.com/superfly/flyctl/blob/603b0adccf5416188eabaa7dc73f9c0ec88fa6ca/api/resource_volumes.go#L5-L40) on GitHub.
TIL Linking from /latest/ to /stable/ on Read The Docs — [Read The Docs](https://readthedocs.org/) has a handy feature where documentation for older versions will automatically link to the latest release, for example [on this page](https://docs.datasette.io/en/0.56/spatialite.html):
TIL Promoting the stable version of the documentation using rel=canonical — I was thinking about documentation SEO today. Like many projects, Datasette offers multiple versions of the documentation:
TIL Pixel editing a favicon with Pixelmator — I wanted to [add a favicon](https://github.com/simonw/datasette/issues/1603) to Datasette, using a PNG image served from `/favicon.ico` as suggested in [this article by Adam Johnson](https://adamj.eu/tech/2022/01/18/how-to-add-a-favicon-to-your-django-site/).
TIL Helper function for pagination using AWS boto3 — I noticed that a lot of my boto3 code in [s3-credentials](https://github.com/simonw/s3-credentials) looked like this:
TIL json_extract() path syntax in SQLite — Several of the [SQLite JSON functions](), such as `json_extract()` and `json_array_length()`, take a path argument. This uses custom syntax along the lines of `$.a[2].b`, as described [in the documentation here](https://sqlite.org/json1.html#path_arguments).
TIL Streaming indented output of a JSON array — I wanted to produce the following output from a command-line tool:
TIL JavaScript date objects — A few notes on JavaScript `Date` object, based on trying to do some basic things with them in Observable notebooks.
TIL Configuring Dependabot for a Python project — GitHub's Dependabot can automatically file PRs with bumps to dependencies when new versions of them are available.
TIL Testing a Click app with streaming input — For [sqlite-utils#364](https://github.com/simonw/sqlite-utils/issues/364) I needed to write a test for a [Click](https://click.palletsprojects.com/) app which dealt with input streamed to standard input. I needed to run some assertions during that process, which ruled out the usual [CliRunner.invoke()](https://click.palletsprojects.com/en/8.0.x/testing/) testing tool since that works by running the command until completion.
TIL Writing pytest tests against tools written with argparse — I usually build command-line tools using [Click](https://click.palletsprojects.com/) (and my [click-app](https://github.com/simonw/click-app) cookiecutter template), which includes a really nice [set of tools](https://click.palletsprojects.com/en/8.0.x/testing/) for writing tests.
TIL Adding a CORS policy to an S3 bucket — Amazon S3 buckets that are configured to work as public websites can support CORS, allowing assets such as JavaScript modules to be loaded by JavaScript running on other domains.
TIL WebAuthn browser support — I [started exploring](https://twitter.com/simonw/status/1476249939516616704) **[WebAuthn](https://webauthn.guide/)** today - a set of browser standards that adds support for both Yubikey 2FA hardware devices and "platform" authentication using things like Touch ID and Face ID.
TIL kubectl proxy — Learned about this today as a way of accessing the Kubernetes REST API.
TIL Transferring a GitHub issue from a private to a public repository — I have my own private `notes` repository where I sometimes create research threads. Occasionally I want to transfer these to a public repository to publish their contents.
TIL Adding a robots.txt using Cloudflare workers — I got an unexpected traffic spike to https://russian-ira-facebook-ads.datasettes.com/ - which runs on Cloud Run - and decided to use `robots.txt` to block crawlers.
TIL Annotated explanation of David Beazley's dataklasses — David Beazley [on Twitter](https://twitter.com/dabeaz/status/1472742536649351173):
TIL Safely outputting JSON — Carelessly including the output of `json.dumps()` in an HTML page can lead to an XSS hole, thanks to the following:
TIL Creating a minimal SpatiaLite database with Python — When writing a test for [datasette-leaflet-freedraw](https://github.com/simonw/datasette-leaflet-freedraw) I realized I didn't have a simple tiny recipe for creating an in-memory SpatiaLite database in Python. I came up with this:
TIL Registering the same Pluggy hook multiple times in a single file — I found myself wanting to register more than one instance of a [Pluggy](https://pluggy.readthedocs.io/) plugin hook inside a single module.
TIL Using lsof on macOS — `lsof` stands for "list open files". Here are some very basic usage notes for the version that ships with macOS.
TIL Using C_INCLUDE_PATH to install Python packages — I tried to install my [datasette-bplist](https://github.com/simonw/datasette-bplist) plugin today in a fresh Python 3.10 virtual environment on macOS and got this error:

Years