mirror of
https://github.com/jbranchaud/til
synced 2026-01-20 15:38:02 +00:00
Compare commits
8 Commits
ed9c31c259
...
c2dda60ca8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2dda60ca8 | ||
|
|
c06bb2ea7b | ||
|
|
7dad6508d0 | ||
|
|
5bcdbbb3c7 | ||
|
|
41f5b526d2 | ||
|
|
e974a184c6 | ||
|
|
c832b9a70d | ||
|
|
15337dfd71 |
@@ -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).
|
||||||
|
|
||||||
_1418 TILs and counting..._
|
_1423 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -410,6 +410,7 @@ _1418 TILs and counting..._
|
|||||||
|
|
||||||
### Inngest
|
### Inngest
|
||||||
|
|
||||||
|
- [Ensure Lookup Can Be Retried](inngest/ensure-lookup-can-be-retried.md)
|
||||||
- [Exit Function Early Without Retries](inngest/exit-function-early-without-retries.md)
|
- [Exit Function Early Without Retries](inngest/exit-function-early-without-retries.md)
|
||||||
|
|
||||||
### Internet
|
### Internet
|
||||||
@@ -672,6 +673,7 @@ _1418 TILs and counting..._
|
|||||||
- [Capitalize All The Words](postgres/capitalize-all-the-words.md)
|
- [Capitalize All The Words](postgres/capitalize-all-the-words.md)
|
||||||
- [Change The Current Directory For psql](postgres/change-the-current-directory-for-psql.md)
|
- [Change The Current Directory For psql](postgres/change-the-current-directory-for-psql.md)
|
||||||
- [Change The Owner Of A Sequence](postgres/change-the-owner-of-a-sequence.md)
|
- [Change The Owner Of A Sequence](postgres/change-the-owner-of-a-sequence.md)
|
||||||
|
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
||||||
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
||||||
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
||||||
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||||
@@ -736,6 +738,7 @@ _1418 TILs and counting..._
|
|||||||
- [Group By The Result Of A Function Call](postgres/group-by-the-result-of-a-function-call.md)
|
- [Group By The Result Of A Function Call](postgres/group-by-the-result-of-a-function-call.md)
|
||||||
- [Idempotent Inserts](postgres/idempotent-inserts.md)
|
- [Idempotent Inserts](postgres/idempotent-inserts.md)
|
||||||
- [Include All Queries In The Log File](postgres/include-all-queries-in-the-log-file.md)
|
- [Include All Queries In The Log File](postgres/include-all-queries-in-the-log-file.md)
|
||||||
|
- [Include Columns In A Covering Index](postgres/include-columns-in-a-covering-index.md)
|
||||||
- [Include Multiple Tables In A pg_dump](postgres/include-multiple-tables-in-a-pg-dump.md)
|
- [Include Multiple Tables In A pg_dump](postgres/include-multiple-tables-in-a-pg-dump.md)
|
||||||
- [Insert A Bunch Of Records With Generate Series](postgres/insert-a-bunch-of-records-with-generate-series.md)
|
- [Insert A Bunch Of Records With Generate Series](postgres/insert-a-bunch-of-records-with-generate-series.md)
|
||||||
- [Insert Just The Defaults](postgres/insert-just-the-defaults.md)
|
- [Insert Just The Defaults](postgres/insert-just-the-defaults.md)
|
||||||
@@ -905,6 +908,7 @@ _1418 TILs and counting..._
|
|||||||
- [Load A File When Starting Rails Console](rails/load-a-file-when-starting-rails-console.md)
|
- [Load A File When Starting Rails Console](rails/load-a-file-when-starting-rails-console.md)
|
||||||
- [Load Records In Batches With find_each](rails/load-records-in-batches-with-find-each.md)
|
- [Load Records In Batches With find_each](rails/load-records-in-batches-with-find-each.md)
|
||||||
- [Log SQL Queries Executed By ActiveRecord](rails/log-sql-queries-executed-by-activerecord.md)
|
- [Log SQL Queries Executed By ActiveRecord](rails/log-sql-queries-executed-by-activerecord.md)
|
||||||
|
- [Look Up Time Zone Info For Identifier](rails/look-up-time-zone-info-for-identifier.md)
|
||||||
- [Mark A Migration As Irreversible](rails/mark-a-migration-as-irreversible.md)
|
- [Mark A Migration As Irreversible](rails/mark-a-migration-as-irreversible.md)
|
||||||
- [Make A String Attribute Easy To Inquire About](rails/make-a-string-attribute-easy-to-inquire-about.md)
|
- [Make A String Attribute Easy To Inquire About](rails/make-a-string-attribute-easy-to-inquire-about.md)
|
||||||
- [Make ActionMailer Synchronous In Test](rails/make-action-mailer-synchronous-in-test.md)
|
- [Make ActionMailer Synchronous In Test](rails/make-action-mailer-synchronous-in-test.md)
|
||||||
@@ -1625,6 +1629,7 @@ _1418 TILs and counting..._
|
|||||||
- [Add The VSCode CLI To Your Path](vscode/add-the-vscode-cli-to-your-path.md)
|
- [Add The VSCode CLI To Your Path](vscode/add-the-vscode-cli-to-your-path.md)
|
||||||
- [Advance Through Search Results](vscode/advance-through-search-results.md)
|
- [Advance Through Search Results](vscode/advance-through-search-results.md)
|
||||||
- [Enable Breadcrumbs For Version 1.26 Release](vscode/enable-breadcrumbs-for-version-126-release.md)
|
- [Enable Breadcrumbs For Version 1.26 Release](vscode/enable-breadcrumbs-for-version-126-release.md)
|
||||||
|
- [Find The Location Of User Settings JSON File](vscode/find-the-location-of-user-settings-json-file.md)
|
||||||
- [Open An Integrated Terminal Window](vscode/open-an-integrated-terminal-window.md)
|
- [Open An Integrated Terminal Window](vscode/open-an-integrated-terminal-window.md)
|
||||||
- [Pop Open The Quick Fix Window](vscode/pop-open-the-quick-fix-window.md)
|
- [Pop Open The Quick Fix Window](vscode/pop-open-the-quick-fix-window.md)
|
||||||
- [Step Through Project-Wide Search Results](vscode/step-through-project-wide-search-results.md)
|
- [Step Through Project-Wide Search Results](vscode/step-through-project-wide-search-results.md)
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ version from my `.tool-versions` file with a step that uses `set-output`.
|
|||||||
- name: Read Node.js version to install from `.tool-versions`
|
- name: Read Node.js version to install from `.tool-versions`
|
||||||
id: nodejs
|
id: nodejs
|
||||||
run: >-
|
run: >-
|
||||||
echo "::set-output name=NODE_VERSION::$(
|
echo "NODE_VERSION=$(
|
||||||
cat .tool-versions |
|
cat .tool-versions |
|
||||||
grep nodejs |
|
grep nodejs |
|
||||||
sed 's/nodejs \(.*\)$/\1/'
|
sed 's/nodejs \(.*\)$/\1/'
|
||||||
)"
|
)" >> $GITHUB_OUTPUT
|
||||||
```
|
```
|
||||||
|
|
||||||
`echo` runs the command in the string which sets `NODE_VERSION` as an output
|
`echo` runs the command in the string which sets `NODE_VERSION` as an output
|
||||||
@@ -45,4 +45,4 @@ This output value can be referenced in a later step.
|
|||||||
`steps` has a reference to the `nodejs` step (note the `id` above) which then
|
`steps` has a reference to the `nodejs` step (note the `id` above) which then
|
||||||
has `outputs` like the `NODE_VERSION`.
|
has `outputs` like the `NODE_VERSION`.
|
||||||
|
|
||||||
[source](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions)
|
[source](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter)
|
||||||
|
|||||||
57
inngest/ensure-lookup-can-be-retried.md
Normal file
57
inngest/ensure-lookup-can-be-retried.md
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# Ensure Lookup Can Be Retried
|
||||||
|
|
||||||
|
A common thing to do in a workflow step is to look up a record. This might be a
|
||||||
|
record that was created or updated around the time that the workflow was
|
||||||
|
triggered.
|
||||||
|
|
||||||
|
You need to be sure the record was found before proceeding. That might end up
|
||||||
|
looking like this:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export default inngest.createFunction(
|
||||||
|
{ id: "record-user-purchase" },
|
||||||
|
{ event: "app/record.purchase" },
|
||||||
|
async ({ event, step }) => {
|
||||||
|
const checkoutSession =
|
||||||
|
await step.run("find checkout session", async () => {
|
||||||
|
const cs = provider.lookupSession(event.checkoutSessionId)
|
||||||
|
|
||||||
|
return cs;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!checkoutSession) {
|
||||||
|
throw new Error('Checkout session not found')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
This approach has a subtle problem which is that the error for a missing
|
||||||
|
checkout session is raised _outside_ the step that sets `checkoutSession`. As
|
||||||
|
inngest does a series of retries, the memorized `checkoutSession` step won't be
|
||||||
|
rerun and the error will continue to be thrown.
|
||||||
|
|
||||||
|
It is better to raise the error _within_ the lookup step:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
export default inngest.createFunction(
|
||||||
|
{ id: "record-user-purchase" },
|
||||||
|
{ event: "app/record.purchase" },
|
||||||
|
async ({ event, step }) => {
|
||||||
|
const checkoutSession =
|
||||||
|
await step.run("find checkout session", async () => {
|
||||||
|
const cs = provider.lookupSession(event.checkoutSessionId)
|
||||||
|
|
||||||
|
if(!cs) {
|
||||||
|
throw new Error('Checkout session not found')
|
||||||
|
}
|
||||||
|
|
||||||
|
return cs;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
If the checkout session is missing on the first couple tries, the step will
|
||||||
|
have a chance to retry the lookup and maybe eventually find what it is looking
|
||||||
|
for.
|
||||||
42
postgres/check-if-clusters-are-upgrade-compatible.md
Normal file
42
postgres/check-if-clusters-are-upgrade-compatible.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Check If Clusters Are Upgrade Compatible
|
||||||
|
|
||||||
|
One of the ways to upgrade a PostgreSQL database from one server version to
|
||||||
|
another is to use the built-in `pg_upgrade` command. This can be faster and
|
||||||
|
require fewer manual steps than something like a `pg_dump` and `pg_restore`.
|
||||||
|
|
||||||
|
However, before you run the `pg_upgrade` command for real, you should check
|
||||||
|
that the target database is compatible with the current database. To do this,
|
||||||
|
write your `pg_update` command with all the flags you need and then tack on
|
||||||
|
`--check` at the end. This does a dry-run reporting the results of a series of
|
||||||
|
consistency checks.
|
||||||
|
|
||||||
|
Here is what a successful _check_ looks like:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ /usr/local/opt/postgresql@13/bin/pg_upgrade \
|
||||||
|
--old-bindir $HOME/.asdf/installs/postgres/12.3/bin \
|
||||||
|
--new-bindir /usr/local/opt/postgresql@13/bin \
|
||||||
|
--old-datadir $HOME/.asdf/installs/postgres/12.3/data \
|
||||||
|
--new-datadir ./postgres/data \
|
||||||
|
--check
|
||||||
|
|
||||||
|
Performing Consistency Checks
|
||||||
|
-----------------------------
|
||||||
|
Checking cluster versions ok
|
||||||
|
Checking database user is the install user ok
|
||||||
|
Checking database connection settings ok
|
||||||
|
Checking for prepared transactions ok
|
||||||
|
Checking for system-defined composite types in user tables ok
|
||||||
|
Checking for reg* data types in user tables ok
|
||||||
|
Checking for contrib/isn with bigint-passing mismatch ok
|
||||||
|
Checking for presence of required libraries ok
|
||||||
|
Checking database user is the install user ok
|
||||||
|
Checking for prepared transactions ok
|
||||||
|
Checking for new cluster tablespace directories ok
|
||||||
|
|
||||||
|
*Clusters are compatible*
|
||||||
|
```
|
||||||
|
|
||||||
|
If there is an issue, such as mismatched collation settings, the output will
|
||||||
|
report the issue. You'll have to decide how to resolve those on a case-by-case
|
||||||
|
basis.
|
||||||
33
postgres/include-columns-in-a-covering-index.md
Normal file
33
postgres/include-columns-in-a-covering-index.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Include Columns In A Covering Index
|
||||||
|
|
||||||
|
A _covering index_ is a special type of B-Tree index that, in addition to
|
||||||
|
indexing on a certain field, also _includes_ one or more columns as extra data
|
||||||
|
in the leaves of the tree. When created correctly, this can speed up the
|
||||||
|
queries it targets by achieving an _index-only scan_.
|
||||||
|
|
||||||
|
Let's say we have a frequently run query on a large `events` table that looks
|
||||||
|
like this:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select user_id, identifier, type
|
||||||
|
from events
|
||||||
|
where user_id = $1;
|
||||||
|
```
|
||||||
|
|
||||||
|
Here is what it looks like to create an index for this query with the `include`
|
||||||
|
keyword:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
create index user_id_on_events_idx
|
||||||
|
on (user_id)
|
||||||
|
include (identifier, type);
|
||||||
|
```
|
||||||
|
|
||||||
|
An index on its own can already cause a significant speed up to the queries it
|
||||||
|
targets, but may still need to retrieve some `select` attributes from the
|
||||||
|
table. For hot-path queries with a set of specific columns always included in
|
||||||
|
the select, there can be significant additional speed ups by having the index
|
||||||
|
_cover_ those columns.
|
||||||
|
|
||||||
|
For more details, check out [A Close Look At The Index Include
|
||||||
|
Clause](https://use-the-index-luke.com/blog/2019-04/include-columns-in-btree-indexes).
|
||||||
33
rails/look-up-time-zone-info-for-identifier.md
Normal file
33
rails/look-up-time-zone-info-for-identifier.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Look Up Time Zone Info For Identifier
|
||||||
|
|
||||||
|
The `ActiveSupport::TimeZone` class overrides the `#[]` method to be a lookup
|
||||||
|
mechanism for IANA Time Zone Identifier strings. These are strings like
|
||||||
|
`America/Chicago` (or anything else listed under `TZInfo::Timezone.all`).
|
||||||
|
|
||||||
|
Let's get an instance for `America/Chicago`.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
> chi = ActiveSupport::TimeZone['America/Chicago']
|
||||||
|
=> #<ActiveSupport::TimeZone:0x00000001099d8140
|
||||||
|
@name="America/Chicago",
|
||||||
|
@tzinfo=#<TZInfo::DataTimezone: America/Chicago>,
|
||||||
|
@utc_offset=nil>
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice it has a `tzinfo` instance variable that we can access. That object
|
||||||
|
contains all kinds of useful things.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
> chi.tzinfo.name
|
||||||
|
=> "America/Chicago"
|
||||||
|
> chi.tzinfo.friendly_identifier
|
||||||
|
=> "America - Chicago"
|
||||||
|
> chi.tzinfo.abbr
|
||||||
|
=> "CDT"
|
||||||
|
> chi.tzinfo.utc_offset
|
||||||
|
=> -18000
|
||||||
|
> chi.tzinfo.dst?
|
||||||
|
=> true
|
||||||
|
```
|
||||||
|
|
||||||
|
All of these and more. Run `ls chi.tzinfo` in a `pry` session to see what else.
|
||||||
31
vscode/find-the-location-of-user-settings-json-file.md
Normal file
31
vscode/find-the-location-of-user-settings-json-file.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Find The Location Of User Settings JSON File
|
||||||
|
|
||||||
|
There are a ton ways to customize and fine-tune VS Code. All of the settings
|
||||||
|
have defaults which can then be customized on a workspace and user level.
|
||||||
|
Typically you'll access these files within VS Code via the Command Palette. I
|
||||||
|
was curious though: since it is just a JSON file, surely I can view and modify
|
||||||
|
it with any editor.
|
||||||
|
|
||||||
|
On a Mac, the user-level `settings.json` file is located at
|
||||||
|
`~/Library/Application\ Support/Code/User/settings.json`.
|
||||||
|
|
||||||
|
Open it up and you might see something like this:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"window.zoomLevel": 1,
|
||||||
|
"workbench.editor.showTabs": "single"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A handful of settings with specific overrides.
|
||||||
|
|
||||||
|
Feel free to edit what is in here or add other settings that you want to set.
|
||||||
|
Just make sure you know what you're doing and that you set valid values.
|
||||||
|
|
||||||
|
The VS Code docs list [the locations of these files on other operating
|
||||||
|
systems](https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations).
|
||||||
|
|
||||||
|
[source](https://stackoverflow.com/questions/53840644/location-of-vs-code-preferences)
|
||||||
Reference in New Issue
Block a user