Skip to content

Snippets

Quick flashes of insight — snippets, links, quotes, and things I've learned.

Install dependencies at runtime with uv

When working with uv, you can have dependencies installed automatically at runtime (if they’re not already available) by adding a small script metadata block at the top of your Python file.

For example, if you run the script below with uv, it will install duckdb and then execute a simple query:

# /// script
# dependencies = [
#   "duckdb"
# ]
# ///

import duckdb

con = duckdb.connect()

con.sql("SELECT 'Hello, uv with duckdb!' AS greeting").show()

Simply save the above snippet as a script locally and then run it with uv run your_script.py

#shell #tooling

One command to open any repo in your browser

One frustration I used to have regularly when working on coding projects was this constant need to navigate to a repository in my browser, for a project I was working on locally. You follow standard gitflows locally and then… it was just tedious.

So I wrote a simple shell function to assist in this process:

get_git_url -o

From any directory inside a git repo, it instantly opens that repository in your browser. No copying URLs, no bookmark hunting.

function get_git_url() {
    local open_url=false

    if [[ "$1" == "-o" || "$1" == "--open" ]]; then
        open_url=true
        shift
    fi

    local remote_url
    remote_url=$(git remote get-url origin 2>/dev/null) || {
        echo "Error: could not get remote URL (are you in a git repo?)" >&2
        return 1
    }

    # Convert SSH to HTTPS for common providers
    local https_url="$remote_url"
    if [[ $remote_url =~ ^git@([^:]+):(.+)$ ]]; then
        local host="${BASH_REMATCH[1]}"
        local path="${BASH_REMATCH[2]}"
        https_url="https://${host}/${path}"
    fi

    https_url="${https_url%.git}"

    if $open_url; then
        if [[ -n "${WSL_DISTRO_NAME:-}" ]]; then
            wslview "$https_url" 2>/dev/null || explorer.exe "$https_url"
        elif [[ "$OSTYPE" == "darwin"* ]]; then
            open "$https_url"
        elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
            cmd.exe /c start "" "$https_url" 2>/dev/null
        elif command -v xdg-open >/dev/null 2>&1; then
            xdg-open "$https_url" >/dev/null 2>&1 &
        else
            echo "$https_url"
            return 1
        fi
    else
        echo "$https_url"
    fi
}

Why it’s great:

  • Works with SSH or HTTPS remotes (auto-converts SSH → HTTPS)
  • Cross-platform: macOS, Linux, WSL, Git Bash
  • Without -o, just prints the URL (useful for piping)
  • Works with GitHub, GitLab, Bitbucket—any git host

I use this dozens of times a day. Add it to your .zshrc or .bashrc and thank yourself later.

#shell #git #tooling

On the importance of Art

— Oscar Wilde

I’ve been reading the Picture of Dorian Gray by Oscar Wilde lately and reflecting on the role of art in society:

“Art is a means of union among men, joining them together in the same feelings, and indispensable for the life and progress toward well-being of individuals and of humanity.” - Oscar Wilde.

#art

TIL: Git worktrees are amazing

Finally tried git worktree properly today. Instead of stashing or committing half-done work to switch branches, you can just:

git worktree add ../feature-branch feature-branch

Now you have both branches checked out simultaneously in different directories. Perfect for reviewing PRs while in the middle of something else.

#git #tooling