Nat Knight

til

#til #webdev #javascript #clipboard

I remember a time when there were whole libraries dedicated to clipboard management.

Turns out in browsers released after ~2020 you can do it with one line:

navigator.clipboard.writeText(text).then(console.log).catch(console.error);
Read more...

#til #javascript #webdev #customelements

I was working on a custom element today that replaces a textarea with CodeMirror in the UI while still updating the textarea in the background so that it can be submitted in a form. I ran across a wild footgun in custom elements.

StackOverflow eventually provided the solution. There's a solution on stack overflow, but Danny Engleman wrote up a more thorough explanation.

Read more...

#uv #python #til #scripting

I've known for a while that uv can run Python scripts that declare inline dependencies.

I learned today that you can also use uv to manage those dependencies.

Read more...

#til #python #uv

(via epistasis on HN)

Semantic versioning is difficult. Not everyone has the same idea of what “breaking change” means, and depending on your language and tooling “breaking” changes can sneak in despite your best efforts.

One possible mitigation is to record when you resolved your dependencies and ignore anything published after that date. It's crude, and relies on package dependencies not monkeying with stuff that's already been published, but it's easy to understand and you can do it with uv.

It's documented here.

Put a date in your pyproject.toml file and subsequent invocations of uv will ignore anything published after the cutoff:

[tool.uv]
exclude-newer = "2023-10-16T00:00:00Z"

You can also use it in the “inline metadata” format for scripting! From the uv docs:

# /// script
# dependencies = [
#   "requests",
# ]
# [tool.uv]
# exclude-newer = "2023-10-16T00:00:00Z"
# ///

import requests

print(requests.__version__)

This use case seems particularly valuable: if I write a quick script I probably care more about it not breaking than I care about it getting updated dependencies. It's nice that uv offers a way to keep code running rather than forcing me to update it or throw it out.

#til #s3 #dockercompose

I had to update a Django service to use S3 instead of local file storage recently. Here's how I set up Minio (a self-hostable S3-compatible data store) for local development.

Read more...

#til #llms #claude #modelcontextprotocol

I was checking out the Model Context Protocol, a spec from Anthropic that lets you expose external programs to an LLM, and discovered that you can extend the Claude desktop app in this way. There are a bunch of enterprisey tools (and you can write your own, more interesting stuff), but out-of-the box you can enable URL-fetching, which lets you grab and process arbitrary information with Claude.

Read more...

#til #django #djangorestramework #python

On a recent project I found myself needing one classic form-and-template style page in an otherwise API-driven project. I could, of course, [just do it] with a regular view function, but I had a bunch of authentication and suchlike set up for DRF APIViews.

Turns out it's actually pretty easy to make an APIView kick it oldschool!

Read more...