mirror of
https://github.com/jbranchaud/til
synced 2026-01-07 09:08:01 +00:00
Compare commits
6 Commits
17cdf4a212
...
483b4e0097
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
483b4e0097 | ||
|
|
93398ab950 | ||
|
|
b1b2aa8982 | ||
|
|
6cbf1cb974 | ||
|
|
79faae1047 | ||
|
|
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).
|
||||
|
||||
_1613 TILs and counting..._
|
||||
_1617 TILs and counting..._
|
||||
|
||||
See some of the other learning resources I work on:
|
||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||
@@ -495,6 +495,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
- [Analyze Your Website Performance](internet/analyze-your-website-performance.md)
|
||||
- [Check Your Public IP Address](internet/check-your-public-ip-address.md)
|
||||
- [Digraph Unicode Characters Have A Titlecase](internet/digraph-unicode-characters-have-a-titlecase.md)
|
||||
- [Download A Google Doc As Specific Format](internet/download-a-google-doc-as-specific-format.md)
|
||||
- [Enable Keyboard Shortcuts In Gmail](internet/enable-keyboard-shortcuts-in-gmail.md)
|
||||
- [Exclude AI Overview From Google Search](internet/exclude-ai-overview-from-google-search.md)
|
||||
- [Exclude Whitespace Changes From GitHub Diffs](internet/exclude-whitespace-changes-from-github-diffs.md)
|
||||
@@ -692,6 +693,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
|
||||
### Mise
|
||||
|
||||
- [Create Umbrella Task For All Test Tasks](mise/create-umbrella-task-for-all-test-tasks.md)
|
||||
- [List The Files Being Loaded By Mise](mise/list-the-files-being-loaded-by-mise.md)
|
||||
- [Preserve Color Output For Task Command](mise/preserve-color-output-for-task-command.md)
|
||||
- [Read Existing Dot Env File Into Env Vars](mise/read-existing-dot-env-file-into-env-vars.md)
|
||||
@@ -957,6 +959,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
### Python
|
||||
|
||||
- [Access Instance Variables](python/access-instance-variables.md)
|
||||
- [Break Debugger On First Line Of Program](python/break-debugger-on-first-line-of-program.md)
|
||||
- [Create A Dummy DataFrame In Pandas](python/create-a-dummy-dataframe-in-pandas.md)
|
||||
- [Dunder Methods](python/dunder-methods.md)
|
||||
- [Override The Boolean Context Of A Class](python/override-the-boolean-context-of-a-class.md)
|
||||
@@ -974,6 +977,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
- [Add A Generated Column To A PostgreSQL Table](rails/add-a-generated-column-to-a-postgresql-table.md)
|
||||
- [Add A Reference Column With An Index](rails/add-a-reference-column-with-an-index.md)
|
||||
- [Add ActiveRecord Error Not Tied To Any Attribute](rails/add-activerecord-error-not-tied-to-any-attribute.md)
|
||||
- [Add Color To The IRB Console Prompt](rails/add-color-to-the-irb-console-prompt.md)
|
||||
- [Add React With Webpacker To A New Rails App](rails/add-react-with-webpacker-to-a-new-rails-app.md)
|
||||
- [Add timestamptz Columns With The Migration DSL](rails/add-timestamptz-columns-with-the-migration-dsl.md)
|
||||
- [Adjust The Production Log Level](rails/adjust-the-production-log-level.md)
|
||||
|
||||
34
internet/download-a-google-doc-as-specific-format.md
Normal file
34
internet/download-a-google-doc-as-specific-format.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Download A Google Doc As Specific Format
|
||||
|
||||
I was recently given a public Google Doc URL and I was curious if I could
|
||||
download it from the command line. I didn't want to have to install special CLI
|
||||
though. I was hoping to use something like `curl`.
|
||||
|
||||
A brief chat with Claude and I learned that not only can I use `curl`, but I
|
||||
can specify the format in the _export_ URL.
|
||||
|
||||
```bash
|
||||
$ export GOOGLE_DOC_URL="https://docs.google.com/document/d/157rMgHeBf76T9TZnUjtrUyyS2XPwG0tObr-OjYNfMaI"
|
||||
|
||||
$ echo $GOOGLE_DOC_URL
|
||||
https://docs.google.com/document/d/157rMgHeBf76T9TZnUjtrUyyS2XPwG0tObr-OjYNfMaI
|
||||
|
||||
$ curl -L "$GOOGLE_DOC_URL/export?format=pdf" -o doc.pdf
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
100 414 0 414 0 0 2763 0 --:--:-- --:--:-- --:--:-- 2895
|
||||
100 16588 0 16588 0 0 56214 0 --:--:-- --:--:-- --:--:-- 167k
|
||||
|
||||
$ ls doc.pdf
|
||||
doc.pdf
|
||||
```
|
||||
|
||||
I append `/export` and then include the `?format=pdf` query param to specify
|
||||
that I want the document to be exported in PDF format. With the `-o` flag I can
|
||||
specify the name and extension of the output file.
|
||||
|
||||
This is a handy on its own, but noticing that Google Docs supports other export
|
||||
formats, I thought it would be useful to go back-and-forth with Claude to
|
||||
sketch out a script that can do this and prompt me (with `fzf`) for the file
|
||||
type -- [here is the gist for
|
||||
`gdoc-download`](https://gist.github.com/jbranchaud/cf3d2028107a1bd8484eed7cca0fcdab).
|
||||
@@ -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
|
||||
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
|
||||
function argTest(one) {
|
||||
console.log(one);
|
||||
|
||||
53
mise/create-umbrella-task-for-all-test-tasks.md
Normal file
53
mise/create-umbrella-task-for-all-test-tasks.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Create Umbrella Task For All Test Tasks
|
||||
|
||||
When I was first sketching out the [`mise`
|
||||
tasks](https://mise.jdx.dev/tasks/running-tasks.html) for a Rails app, I added
|
||||
the following two tasks. One is for running all the `rspec` tests. The Other is
|
||||
for running all the `vitest` (JavaScript) tests.
|
||||
|
||||
```toml
|
||||
[tasks."test:rspec"]
|
||||
run = "unbuffer bundle exec rspec"
|
||||
description = "Run RSpec tests"
|
||||
depends = ["bundle-install"]
|
||||
|
||||
[tasks."test:vitest"]
|
||||
run = "unbuffer yarn test run"
|
||||
description = "Run Vitest tests"
|
||||
depends = ["node-install"]
|
||||
```
|
||||
|
||||
I didn't want to have to invoked both of this individually every time I wanted
|
||||
to run the full suite. So I added a `test:all` task to do it all.
|
||||
|
||||
```toml
|
||||
[tasks."test:all"]
|
||||
description = "Run all tests (RSpec and Vitest)"
|
||||
run = [
|
||||
"unbuffer bundle exec rspec",
|
||||
"unbuffer yarn test run",
|
||||
]
|
||||
description = "Run RSpec tests"
|
||||
depends = ["bundle-install", "node-install"]
|
||||
```
|
||||
|
||||
This worked (for now). But it ate at me, for a couple reasons. I had to
|
||||
duplicate everything about the existing `test:rspec` and `test:vitest` tasks.
|
||||
And this didn't account for a new kind of test task being added (e.g.
|
||||
`test:e2e`).
|
||||
|
||||
Instead, I can rely on `depends` and wildcards to achieve this without the
|
||||
duplication which makes it more future-proof.
|
||||
|
||||
```toml
|
||||
[tasks."test:all"]
|
||||
description = "Run all tests (RSpec and Vitest)"
|
||||
depends = ["test:*"]
|
||||
```
|
||||
|
||||
Running `mise run test:all` won't execute its own command, but because it
|
||||
depends on all other `test:*` tasks, the tests will get run through those
|
||||
dependencies.
|
||||
|
||||
This task naming pattern also allows for calling all tests with `mise run
|
||||
"test:**"`.
|
||||
35
python/break-debugger-on-first-line-of-program.md
Normal file
35
python/break-debugger-on-first-line-of-program.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Break Debugger On First Line Of Program
|
||||
|
||||
One of the things I appreciate about how
|
||||
[Delve](https://github.com/go-delve/delve) (the debugger for Go) works by
|
||||
default is that when you start it up, it immediately breaks on the first line
|
||||
of the program. This is as good a starting point as any regardless of whether
|
||||
you have other breakpoints set.
|
||||
|
||||
As I was reading through the VS Code Python Debugger configuration docs, I
|
||||
noticed [an option called
|
||||
`stopOnEntry`](https://code.visualstudio.com/docs/python/debugging#_stoponentry).
|
||||
It is turned off by default, but if you turn it on, then you get the same
|
||||
behavior as I described for Delve. Nice!
|
||||
|
||||
This can be configured in a `.vscode/launch.json` file:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python Debugger: Current File",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"stopOnEntry": true
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Now, when running this debugger configuration profile, you'll break the
|
||||
debugger on the first line of the program. From there add more breakpoints,
|
||||
start stepping through, etc.
|
||||
62
rails/add-color-to-the-irb-console-prompt.md
Normal file
62
rails/add-color-to-the-irb-console-prompt.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Add Color To The IRB Console Prompt
|
||||
|
||||
IRB has a little-known [`Color`
|
||||
module](https://docs.ruby-lang.org/en/3.2/IRB/Color.html) with some helpers for
|
||||
adding a splash of color to the IRB prompt. I like to clearly differentiate the
|
||||
environment I'm in when connecting to the `rails console`, so I have a
|
||||
customize the prompt to display and colorize the current environment.
|
||||
|
||||
I can wrap any string in ANSI escape codes that instruct the terminal to style
|
||||
the text with color. For instance, here is how I can style the word `DEV` to be
|
||||
inverted against a blue background.
|
||||
|
||||
```ruby
|
||||
IRB::Color.colorize("DEV", [:BLUE, :BOLD, :REVERSE])
|
||||
```
|
||||
|
||||
which will clearly stand out from `PROD` against a red background:
|
||||
|
||||
```ruby
|
||||
IRB::Color.colorize("PROD", [:RED, :BOLD, :REVERSE])
|
||||
```
|
||||
|
||||
Here is a full example of customizing the prompt from the
|
||||
`config/application.rb` file.
|
||||
|
||||
```ruby
|
||||
module MyApp
|
||||
class Application < Rails::Application
|
||||
# ...
|
||||
|
||||
console do
|
||||
# Get the application module name and convert to kebab-case
|
||||
app_name = Rails.application.class.module_parent.name
|
||||
kebab_name = app_name.underscore.dasherize
|
||||
|
||||
# Environment color coding
|
||||
env_colors = {
|
||||
"development" => IRB::Color.colorize("DEV", [:BLUE, :BOLD, :REVERSE]),
|
||||
"production" => IRB::Color.colorize("PROD", [:RED, :BOLD, :REVERSE]),
|
||||
"test" => IRB::Color.colorize("TEST", [:YELLOW, :BOLD, :REVERSE]),
|
||||
}
|
||||
|
||||
colored_env = "(#{env_colors[Rails.env]})"
|
||||
|
||||
# Docs: https://docs.ruby-lang.org/en/3.2/IRB.html#module-IRB-label-Customizing+the+IRB+Prompt
|
||||
IRB.conf[:PROMPT][:RAILS_APP] = {
|
||||
PROMPT_I: "#{kebab_name}#{colored_env}> ",
|
||||
PROMPT_N: "#{kebab_name}#{colored_env}* ",
|
||||
PROMPT_S: "#{kebab_name}#{colored_env}% ",
|
||||
PROMPT_C: "#{kebab_name}#{colored_env}? ",
|
||||
RETURN: "=> %s\n"
|
||||
}
|
||||
|
||||
# Set it as the current prompt
|
||||
IRB.conf[:PROMPT_MODE] = :RAILS_APP
|
||||
end
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
The Ruby docs have more about [IRB Prompt
|
||||
Customization](https://docs.ruby-lang.org/en/3.2/IRB.html#module-IRB-label-Customizing+the+IRB+Prompt).
|
||||
Reference in New Issue
Block a user