1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-20 23:48:02 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Dylan Irlbeck
189f6826b4 Merge 5365e75267 into c8445c45a9 2025-03-06 12:02:18 -05:00
jbranchaud
c8445c45a9 Add Read Existing Dot Env File Into Env Vars as a Mise TIL 2025-03-05 13:19:08 -06:00
jbranchaud
497b0ff3b7 Add Files With Local Changes Cannot Be Removed as a Git TIL 2025-03-04 18:05:58 -06:00
jbranchaud
64df6d16d7 Add Find All Tool Version Files Containing Postgres as a Unix TIL 2025-03-04 17:41:03 -06:00
jbranchaud
7dac057246 Add List The Files Being Loaded By Mise as a Mise TIL 2025-03-04 09:24:27 -06:00
jbranchaud
8961c67026 Add Create Todo Items In Logseq as a Workflow TIL 2025-03-03 17:06:58 -06:00
jbranchaud
4ff24a7336 Add Restart Puma Server By Touching Restart File as a Rails TIL 2025-03-01 09:48:48 -06:00
jbranchaud
2916fbc3b5 Add Create And Jump Into A Directory as a Zsh TIL 2025-02-28 10:39:23 -06:00
Dylan Irlbeck
5365e75267 Update git show TIL 2020-04-29 22:17:44 -05:00
9 changed files with 260 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1602 TILs and counting..._ _1609 TILs and counting..._
See some of the other learning resources I work on: See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -54,6 +54,7 @@ If you've learned something here, support my efforts writing daily TILs by
* [Linux](#linux) * [Linux](#linux)
* [LLM](#llm) * [LLM](#llm)
* [Mac](#mac) * [Mac](#mac)
* [Mise](#mise)
* [MongoDB](#mongodb) * [MongoDB](#mongodb)
* [MySQL](#mysql) * [MySQL](#mysql)
* [Neovim](#neovim) * [Neovim](#neovim)
@@ -326,6 +327,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Exclude A File From A Diff Output](git/exclude-a-file-from-a-diff-output.md) - [Exclude A File From A Diff Output](git/exclude-a-file-from-a-diff-output.md)
- [Excluding Files Locally](git/excluding-files-locally.md) - [Excluding Files Locally](git/excluding-files-locally.md)
- [Extend Git With Custom Commands](git/extend-git-with-custom-commands.md) - [Extend Git With Custom Commands](git/extend-git-with-custom-commands.md)
- [Files With Local Changes Cannot Be Removed](git/files-with-local-changes-cannot-be-removed.md)
- [Find And Remove Files That Match A Name](git/find-and-remove-files-that-match-a-name.md) - [Find And Remove Files That Match A Name](git/find-and-remove-files-that-match-a-name.md)
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md) - [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
- [Find The Initial Commit](git/find-the-initial-commit.md) - [Find The Initial Commit](git/find-the-initial-commit.md)
@@ -686,6 +688,11 @@ If you've learned something here, support my efforts writing daily TILs by
- [View All Windows Of The Current App](mac/view-all-windows-of-the-current-app.md) - [View All Windows Of The Current App](mac/view-all-windows-of-the-current-app.md)
- [Write System Clipboard To A File](mac/write-system-clipboard-to-a-file.md) - [Write System Clipboard To A File](mac/write-system-clipboard-to-a-file.md)
### Mise
- [List The Files Being Loaded By Mise](mise/list-the-files-being-loaded-by-mise.md)
- [Read Existing Dot Env File Into Env Vars](mise/read-existing-dot-env-file-into-env-vars.md)
### MongoDB ### MongoDB
- [Determine The Database Version](mongodb/determine-the-database-version.md) - [Determine The Database Version](mongodb/determine-the-database-version.md)
@@ -1074,6 +1081,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Rescue From](rails/rescue-from.md) - [Rescue From](rails/rescue-from.md)
- [Rescue From With A Separate Method](rails/rescue-from-with-a-separate-method.md) - [Rescue From With A Separate Method](rails/rescue-from-with-a-separate-method.md)
- [Respond With JSON Regardless of Content Type](rails/respond-with-json-regardless-of-content-type.md) - [Respond With JSON Regardless of Content Type](rails/respond-with-json-regardless-of-content-type.md)
- [Restart Puma Server By Touching Restart File](rails/restart-puma-server-by-touching-restart-file.md)
- [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md) - [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md)
- [Rollback A Couple Migrations](rails/rollback-a-couple-migrations.md) - [Rollback A Couple Migrations](rails/rollback-a-couple-migrations.md)
- [Rollback A Specific Migration Out Of Order](rails/rollback-a-specific-migration-out-of-order.md) - [Rollback A Specific Migration Out Of Order](rails/rollback-a-specific-migration-out-of-order.md)
@@ -1533,6 +1541,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [File Type Info With File](unix/file-type-info-with-file.md) - [File Type Info With File](unix/file-type-info-with-file.md)
- [Find All Files Matching A Name With fd](unix/find-all-files-matching-a-name-with-fd.md) - [Find All Files Matching A Name With fd](unix/find-all-files-matching-a-name-with-fd.md)
- [Find All Files With A Specific Extension With fd](unix/find-all-files-with-a-specific-extension-with-fd.md) - [Find All Files With A Specific Extension With fd](unix/find-all-files-with-a-specific-extension-with-fd.md)
- [Find All Tool Version Files Containing Postgres](unix/find-all-tool-version-files-containing-postgres.md)
- [Find Any Dotfiles That Modify Path Env Var](unix/find-any-dotfiles-that-modify-path-env-var.md) - [Find Any Dotfiles That Modify Path Env Var](unix/find-any-dotfiles-that-modify-path-env-var.md)
- [Find A File Installed By Brew](unix/find-a-file-installed-by-brew.md) - [Find A File Installed By Brew](unix/find-a-file-installed-by-brew.md)
- [Find Duplicate Lines In A File](unix/find-duplicate-lines-in-a-file.md) - [Find Duplicate Lines In A File](unix/find-duplicate-lines-in-a-file.md)
@@ -1846,6 +1855,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Convert An ePub Document To PDF On Mac](workflow/convert-an-epub-document-to-pdf-on-mac.md) - [Convert An ePub Document To PDF On Mac](workflow/convert-an-epub-document-to-pdf-on-mac.md)
- [Create A Local Sanity Dataset Backup](workflow/create-a-local-sanity-dataset-backup.md) - [Create A Local Sanity Dataset Backup](workflow/create-a-local-sanity-dataset-backup.md)
- [Create A Public URL For A Local Server](workflow/create-a-public-url-for-a-local-server.md) - [Create A Public URL For A Local Server](workflow/create-a-public-url-for-a-local-server.md)
- [Create Todo Items In Logseq](workflow/create-todo-items-in-logseq.md)
- [Enable Dev Tools For Safari](workflow/enable-dev-tools-for-safari.md) - [Enable Dev Tools For Safari](workflow/enable-dev-tools-for-safari.md)
- [Forward Stripe Events To Local Server](workflow/forward-stripe-events-to-local-server.md) - [Forward Stripe Events To Local Server](workflow/forward-stripe-events-to-local-server.md)
- [Get URL For GitHub User Profile Photo](workflow/get-url-for-github-user-profile-photo.md) - [Get URL For GitHub User Profile Photo](workflow/get-url-for-github-user-profile-photo.md)
@@ -1896,6 +1906,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [A Better Way To Reload ZSH Configuration](zsh/a-better-way-to-reload-zsh-configuration.md) - [A Better Way To Reload ZSH Configuration](zsh/a-better-way-to-reload-zsh-configuration.md)
- [Add To The Path Via Path Array](zsh/add-to-the-path-via-path-array.md) - [Add To The Path Via Path Array](zsh/add-to-the-path-via-path-array.md)
- [Create And Jump Into A Directory](zsh/create-and-jump-into-a-directory.md)
- [Link A Scalar To An Array](zsh/link-a-scalar-to-an-array.md) - [Link A Scalar To An Array](zsh/link-a-scalar-to-an-array.md)
- [Use A Space To Exclude Command From History](zsh/use-a-space-to-exclude-command-from-history.md) - [Use A Space To Exclude Command From History](zsh/use-a-space-to-exclude-command-from-history.md)

View File

@@ -0,0 +1,26 @@
# Files With Local Changes Cannot Be Removed
This is a nice quality-of-life feature in `git` that should help you avoid
accidentally discarding changes that won't be retrievable.
```bash
git rm .tool-versions
error: the following file has local modifications:
.tool-versions
(use --cached to keep the file, or -f to force removal)
```
My `.tool-versions` file has some local changes. I don't realize that and I go
to issue a `git rm` command on that file. Instead of quietly wiping out my
changes, `git` lets me know I'm doing something destructive (these local
changes won't be in the diff or the reflog).
I can force the removal if I know what I'm doing with the `-f` flag. Or I can
take the two step approach of calling `git restore` on that file and then `git
rm`.
The `--cached` flag is also interesting because it doesn't actually delete the
file from my file system, but it does stage the file deletion with `git`. That
means the file now shows up as one of my untracked files.
See `man git-rm` for more details.

View File

@@ -2,16 +2,16 @@
Sometimes you want to view a file on another branch (without switching Sometimes you want to view a file on another branch (without switching
branches). That is, you want to view the version of that file as it exists branches). That is, you want to view the version of that file as it exists
on that branch. `git show` can help. If your branch is named `my_feature` and on that branch. `git show` can help. If the other branch is named `some_branch` and
the file you want to see is `app/models/users.rb`, then your command should the file you want to see is `app/models/users.rb`, then your command should
look like this: look like this:
``` ```
$ git show my_feature:app/models/users.rb $ git show some_branch:app/models/users.rb
``` ```
You can even tab-complete the filename as you type it out. You can even tab-complete the filename as you type it out.
See `man git-show` for more details. See `man git-show` for more details.
[source](http://stackoverflow.com/questions/7856416/view-a-file-in-a-different-git-branch-without-changing-branches) [source](https://stackoverflow.com/questions/7856416/view-a-file-in-a-different-git-branch-without-changing-branches)

View File

@@ -0,0 +1,29 @@
# List The Files Being Loaded By Mise
While running `mise` for the first time, after adding a `mise.toml` file to a
project, I noticed something strange. Instead of invoking the command I had
specified (`mise run dev`), several parellel tool downloads were kicked off. In
addition to Ruby, it was installing an older version of Postgres, and lua. What
gives?
By running `mise cfg`, I can list all the files being loaded by `mise` and get
to the bottom of this.
```bash
mise cfg
Path Tools
~/.tool-versions node, ruby, postgres, lua
~/code/still/.ruby-version ruby
~/code/still/Gemfile (none)
~/code/still/.tool-versions ruby
~/code/still/mise.toml (none)
```
I was only thinking about the files local to my project and I forgot that I
have a system-wide `.tool-versions` file. As we can see from the output, that
file specifies `postgres` and `lua` as well. Mise wanted to ensure that it had
downloaded the specified versions of each of those tools before running my
task.
[source](https://mise.jdx.dev/configuration.html)

View File

@@ -0,0 +1,28 @@
# Read Existing Dot Env File Into Env Vars
Just about any web app that I've worked on has had a `.env` file as a way of
configuring aspects of the app specific to that environment. These typically
are read into the environment with a language-specific
[dotenv](https://github.com/bkeepers/dotenv) tool.
Mise supports this convention. In addition to specifying individual non-secret
env vars, you can also instruct `mise` to read-in a `.env` file like so:
```toml
[env]
PORT=3344
_.file = ".env"
```
The `_.file` line tells `mise` that there is a file `.env` with key-value pairs
that it should read in. It can even handle `.env.json` and `.env.toml` file
formats.
To ensure that `mise` is picking up the values from the `.env` file, you can
run the following command and make sure they show up in the output:
```bash
$ mise env
```
[source](https://mise.jdx.dev/environments/secrets.html)

View File

@@ -0,0 +1,28 @@
# Restart Puma Server By Touching Restart File
Puma includes a plugin that allows us to restart the web server by touching the
`tmp/restart.txt` file.
In one terminal pane I have my Rails server running. In another terminal pane
from the Rails directory, where there exists a `tmp` folder, I run the
following command.
```bash
$ touch tmp/restart.txt
```
Then in the pane running the Rails server, I see the following after a second:
```
* Restarting...
=> Booting Puma
=> Rails 8.0.1 application starting in development
...
```
What is happening is that `touch` updates the modified time of that file, which
already exists in the `temp` directory. When the plugin notices (it checks
every 2 seconds) that the modified time is now fresher than the original
modified time when the plugin started, then it calls `launcher.restart`.
[source](https://github.com/puma/puma/blob/ca201ef69757f8830b636251b0af7a51270eb68a/lib/puma/plugin/tmp_restart.rb)

View File

@@ -0,0 +1,38 @@
# Find All Tool Version Files Containing Postgres
I've been using [`asdf`](https://asdf-vm.com/) for many years now which means I
have projects and directories all over my machine with `.tool-versions` files.
Many of them specify Ruby and Node versions. Some of them also include
PostgreSQL versions. I used to use `asdf` to manage Postgres versions, but no
longer do that for new or active projects.
I want to find all the places that a `.tool-versions` file declares `postgres`
as a tool. That way I can begin to clean up the left behind artifacts of
asdf-managed Postgres.
By combining [`fd`](https://github.com/sharkdp/fd) (a better `find`) and
[`rg`](https://github.com/BurntSushi/ripgrep) (a better `grep`), I'm able to
quickly track down the list of places.
```bash
$ fd --hidden .tool-versions ~/ | xargs rg postgres
/Users/jbranchaud/.local/state/nvim/undo/%Users%jbranchaud%.tool-versions: binary file matches (found "\0" byte around offset 9)
/Users/jbranchaud/code/fake-data/.tool-versions
2:postgres 13.1
/Users/jbranchaud/code/thirty_days/thirty_days_server/.tool-versions
1:postgres 13.1
/Users/jbranchaud/code/visualmode/.tool-versions
1:postgres 11.11
```
That first instance is a binary file as part of `nvim`'s undo history which I
can ignore. The other three are good results.
I tell the `fd` command to not exclude hidden files as it looks for all
occurrences of `.tool-versions` recursively from my home (`~/`) directory. I
then pipe that list of files to `xargs` which makes those filenames arguments
to the `rg postgres` command.

View File

@@ -0,0 +1,32 @@
# Create Todo Items In Logseq
Having used GitHub flavored markdown and tools like Roam Research and Obsidian,
I'm used to being able to add interactive todo items to a document with square
brackets, like so:
```
- [ ] Do this
- [ ] Do that
```
This exact syntax doesn't work in Logseq, but I've figured out two ways of
adding todo items.
First, you can access the todo syntax with a forward slash command. Type `/`
and then start typing `TODO`. It will show up as a top result. Hit enter and
you'll have a fresh todo item that you can add a description to.
Second, as the above hints at, we can get right to the todo syntax by typing
one of `TODO`, `NOW`, or `LATER` in all caps followed by a description. For
example:
```
TODO Send out invoices
NOW Reply to those emails
LATER Schedule that meeting
```
These will render as checkable boxes marked as either `TODO`, `NOW`, or
`LATER`, until they are checked off.
You can also search for blocks that match one of these three categories.

View File

@@ -0,0 +1,64 @@
# Create And Jump Into A Directory
[Oh My Zsh](https://github.com/ohmyzsh/ohmyzsh) defines a function `take` that
we can use to both create and `cd` into a directory. If the directory already
exists, it will simply `cd` into that directory.
```bash
~/code
take take-demo
~/code/take-demo
mkdir already-exists
~/code/take-demo
take already-exists
~/code/take-demo/already-exists
cd ..
~/code/take-demo
take one/two/three
~/code/take-demo/one/two/three
```
First `take` creates and `cd`s into `take-demo`. Then `take` only `cd`s into
`already-exists`. Then we see that `take` can create multiple levels of nested
directories.
With the help of `which` we can see how `take` is defined:
```bash
$ which take
take () {
if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]
then
takeurl "$1"
elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]
then
takegit "$1"
else
takedir "$@"
fi
}
```
We're not dealing with compressed files or git URLs, so we fall through to the
`else` block with invokes `takedir`.
```bash
$ which takedir
takedir () {
mkdir -p $@ && cd ${@:$#}
}
```
The `mkdir -p $@` is what allows it make new, nested directories and then we
`cd` to it. The `${@:$#}` is a way of [grabbing the last argument to the
function](https://stackoverflow.com/a/37601842/535590). This suggests that you
can pass multiple things to `take`, it will create all of them, and then `cd`
you into the last one.
[source](https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/functions.zsh#L75-L85)