mirror of
https://github.com/jbranchaud/til
synced 2026-01-20 07:28:02 +00:00
Compare commits
5 Commits
e00ae58d87
...
cab482c7e6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cab482c7e6 | ||
|
|
95115c7ebc | ||
|
|
4e859b93d2 | ||
|
|
23c20e99bf | ||
|
|
295fe153ad |
@@ -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).
|
||||||
|
|
||||||
_1491 TILs and counting..._
|
_1493 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -771,6 +771,7 @@ _1491 TILs and counting..._
|
|||||||
- [Force SSL When Making A psql Connection](postgres/force-ssl-when-making-a-psql-connection.md)
|
- [Force SSL When Making A psql Connection](postgres/force-ssl-when-making-a-psql-connection.md)
|
||||||
- [Generate A UUID](postgres/generate-a-uuid.md)
|
- [Generate A UUID](postgres/generate-a-uuid.md)
|
||||||
- [Generate Modern Primary Key Columns](postgres/generate-modern-primary-key-columns.md)
|
- [Generate Modern Primary Key Columns](postgres/generate-modern-primary-key-columns.md)
|
||||||
|
- [Generate Random Alphanumeric Identifier](postgres/generate-random-alphanumeric-identifier.md)
|
||||||
- [Generate Random UUIDs Without An Extension](postgres/generate-random-uuids-without-an-extension.md)
|
- [Generate Random UUIDs Without An Extension](postgres/generate-random-uuids-without-an-extension.md)
|
||||||
- [Generate Series Of Numbers](postgres/generate-series-of-numbers.md)
|
- [Generate Series Of Numbers](postgres/generate-series-of-numbers.md)
|
||||||
- [Generating UUIDs With pgcrypto](postgres/generating-uuids-with-pgcrypto.md)
|
- [Generating UUIDs With pgcrypto](postgres/generating-uuids-with-pgcrypto.md)
|
||||||
@@ -1516,6 +1517,7 @@ _1491 TILs and counting..._
|
|||||||
- [Switch Versions of a Brew Formula](unix/switch-versions-of-a-brew-formula.md)
|
- [Switch Versions of a Brew Formula](unix/switch-versions-of-a-brew-formula.md)
|
||||||
- [Tell direnv To Load The Env File](unix/tell-direnv-to-load-the-env-file.md)
|
- [Tell direnv To Load The Env File](unix/tell-direnv-to-load-the-env-file.md)
|
||||||
- [Touch Access And Modify Times Individually](unix/touch-access-and-modify-times-individually.md)
|
- [Touch Access And Modify Times Individually](unix/touch-access-and-modify-times-individually.md)
|
||||||
|
- [Undo Changes Made To Current Terminal Prompt](unix/undo-changes-made-to-current-terminal-prompt.md)
|
||||||
- [Undo Some Command Line Editing](unix/undo-some-command-line-editing.md)
|
- [Undo Some Command Line Editing](unix/undo-some-command-line-editing.md)
|
||||||
- [Unrestrict Where ripgrep Searches](unix/unrestrict-where-ripgrep-searches.md)
|
- [Unrestrict Where ripgrep Searches](unix/unrestrict-where-ripgrep-searches.md)
|
||||||
- [Update Package Versions Known By asdf Plugin](unix/update-package-versions-known-by-asdf-plugin.md)
|
- [Update Package Versions Known By asdf Plugin](unix/update-package-versions-known-by-asdf-plugin.md)
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
|
|||||||
all of the arguments are referenced in the function signature, they can
|
all of the arguments are referenced in the function signature, they can
|
||||||
still be accessed via the `arguments` object.
|
still be accessed via the `arguments` object.
|
||||||
|
|
||||||
|
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
function argTest(one) {
|
function argTest(one) {
|
||||||
console.log(one);
|
console.log(one);
|
||||||
|
|||||||
46
postgres/generate-random-alphanumeric-identifier.md
Normal file
46
postgres/generate-random-alphanumeric-identifier.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Generate Random Alphanumeric Identifier
|
||||||
|
|
||||||
|
Here is a PostgreSQL query that uses
|
||||||
|
[`pgcrypto`](https://www.postgresql.org/docs/current/pgcrypto.html) (for
|
||||||
|
[`get_random_bytes`](https://www.postgresql.org/docs/current/pgcrypto.html#PGCRYPTO-RANDOM-DATA-FUNCS))
|
||||||
|
and a CTE to generate a cryptographically-random 8-character alphanumeric
|
||||||
|
identifier.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- First ensure pgcrypto is installed
|
||||||
|
create extension if not exists pgcrypto;
|
||||||
|
|
||||||
|
-- Generates a single 8-character identifier
|
||||||
|
with chars as (
|
||||||
|
-- excludes some look-alike characters
|
||||||
|
select '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz' as charset
|
||||||
|
),
|
||||||
|
random_bytes as (
|
||||||
|
select gen_random_bytes(8) as bytes
|
||||||
|
),
|
||||||
|
positions as (
|
||||||
|
select generate_series(0, 7) as pos
|
||||||
|
)
|
||||||
|
select string_agg(
|
||||||
|
substr(
|
||||||
|
charset,
|
||||||
|
(get_byte(bytes, pos) % length(charset)) + 1,
|
||||||
|
1
|
||||||
|
),
|
||||||
|
'' order by pos
|
||||||
|
) as short_id
|
||||||
|
from positions, random_bytes, chars;
|
||||||
|
```
|
||||||
|
|
||||||
|
The
|
||||||
|
[`generate_series`](https://www.postgresql.org/docs/current/functions-srf.html)
|
||||||
|
gives us an 8-row table from 0 to 7 that we can use as indexes into the byte
|
||||||
|
positions of the value we get from `gen_random_bytes`. Those random bytes get
|
||||||
|
mapped to individual alphanumeric characters from `chars`. That then gets
|
||||||
|
squeezed together with `string_agg`.
|
||||||
|
|
||||||
|
Note: the character set excludes some characters that can be mistaken for one
|
||||||
|
another like `0` and `O` or `1` and `l`.
|
||||||
|
|
||||||
|
Note: you could change the right-bound of the `generate_series` to generate a
|
||||||
|
different length identifier.
|
||||||
20
unix/undo-changes-made-to-current-terminal-prompt.md
Normal file
20
unix/undo-changes-made-to-current-terminal-prompt.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Undo Change Made to Current Terminal Prompt
|
||||||
|
|
||||||
|
I frequently use a variety of ASCII command characters like `ctrl-u` to delete
|
||||||
|
the entire line or `ctrl-a` to jump to the front of a long line so I can make
|
||||||
|
some edits toward that side of the command or `ctrl-e` to jump to the end of
|
||||||
|
the command for the same reason. I sometimes even use `ctrl-k` to delete
|
||||||
|
everything after the cursor to the end of the line.
|
||||||
|
|
||||||
|
What I didn't realize until now is that any of those commands the modify the
|
||||||
|
current line of the termianl prompt plus regular typing and hitting the
|
||||||
|
backspace are all _undoable_.
|
||||||
|
|
||||||
|
So, if I just wiped out half the line (with `ctrl-k`) and I immediately regret
|
||||||
|
it, I can restore it with `ctrl-_`. The system keeps of history of the actions
|
||||||
|
you've taken, so you can keep hitting `ctrl-_` to undo even further.
|
||||||
|
|
||||||
|
The `ctrl-/` command does the same, per GNU's [Undo Changes in the Emacs
|
||||||
|
docs](https://www.gnu.org/software/emacs/manual/html_node/emacs/Basic-Undo.html).
|
||||||
|
|
||||||
|
[source](https://jvns.ca/ascii)
|
||||||
Reference in New Issue
Block a user