mirror of
https://github.com/jbranchaud/til
synced 2026-01-18 14:38:01 +00:00
Compare commits
7 Commits
35d468b6c9
...
41e0f7f70a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41e0f7f70a | ||
|
|
baab5738e7 | ||
|
|
191c9d6d9d | ||
|
|
25b5677260 | ||
|
|
df3492d4ef | ||
|
|
bd49b31bb0 | ||
|
|
cff6592c4e |
@@ -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).
|
||||
|
||||
_1436 TILs and counting..._
|
||||
_1441 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -392,6 +392,7 @@ _1436 TILs and counting..._
|
||||
|
||||
- [Deploy A Review App To A Different Stack](heroku/deploy-a-review-app-to-a-different-stack.md)
|
||||
- [Diagnose Problems In A Heroku Postgres Database](heroku/diagnose-problems-in-a-heroku-postgres-database.md)
|
||||
- [Open Dashboard For Specific Add-On](heroku/open-dashboard-for-specific-add-on.md)
|
||||
- [Run SQL Against Remote Postgres Database](heroku/run-sql-against-remote-postgres-database.md)
|
||||
- [Set And Show Heroku Env Variables](heroku/set-and-show-heroku-env-variables.md)
|
||||
- [SSH Into Heroku Server Hosting App](heroku/ssh-into-heroku-server-hosting-app.md)
|
||||
@@ -896,6 +897,7 @@ _1436 TILs and counting..._
|
||||
- [Find Or Create A Record With FactoryBot](rails/find-or-create-a-record-with-factory-bot.md)
|
||||
- [Find Records With Multiple Associated Records](rails/find-records-with-multiple-associated-records.md)
|
||||
- [Force All Users To Sign Out](rails/force-all-users-to-sign-out.md)
|
||||
- [Generate A Rails App From The Main Branch](rails/generate-a-rails-app-from-the-main-branch.md)
|
||||
- [Generating And Executing SQL](rails/generating-and-executing-sql.md)
|
||||
- [Get A Quick Approximate Count Of A Large Table](rails/get-a-quick-approximate-count-of-a-large-table.md)
|
||||
- [Get ActiveRecord Attribute Directly From Database](rails/get-active-record-attribute-directly-from-database.md)
|
||||
@@ -1101,6 +1103,7 @@ _1436 TILs and counting..._
|
||||
|
||||
- [Avoid Accidentally Disabling Pry](rspec/avoid-accidentally-disabling-pry.md)
|
||||
- [Check Specific Arguments To Received Method](rspec/check-specific-arguments-to-received-method.md)
|
||||
- [Configure Tests To Run In Random Order](rspec/configure-tests-to-run-in-random-order.md)
|
||||
- [Find Minimal Set Of Tests Causing A Flicker](rspec/find-minimal-set-of-tests-causing-a-flicker.md)
|
||||
- [Format Test Results As A JSON File](rspec/format-test-results-as-a-json-file.md)
|
||||
- [Run Tests With Documentation Formatting](rspec/run-tests-with-documentation-formatting.md)
|
||||
@@ -1180,6 +1183,7 @@ _1436 TILs and counting..._
|
||||
- [Map With Index Over An Array](ruby/map-with-index-over-an-array.md)
|
||||
- [Mock Method Chain Calls With RSpec](ruby/mock-method-chain-calls-with-rspec.md)
|
||||
- [Mocking Requests With Partial URIs Using Regex](ruby/mocking-requests-with-partial-uris-using-regex.md)
|
||||
- [Multi-Line Comments](ruby/multi-line-comments.md)
|
||||
- [Named Regex Captures Are Assigned To Variables](ruby/named-regex-captures-are-assigned-to-variables.md)
|
||||
- [Navigate Back In The Browser With Capybara](ruby/navigate-back-in-the-browser-with-capybara.md)
|
||||
- [Next And Previous Floats](ruby/next-and-previous-floats.md)
|
||||
@@ -1352,6 +1356,7 @@ _1436 TILs and counting..._
|
||||
- [Command Line Length Limitations](unix/command-line-length-limitations.md)
|
||||
- [Compare Two Variables In A Bash Script](unix/compare-two-variables-in-a-bash-script.md)
|
||||
- [Configure cd To Behave Like pushd In Zsh](unix/configure-cd-to-behave-like-pushd-in-zsh.md)
|
||||
- [Convert SVG To Favicon](unix/convert-svg-to-favicon.md)
|
||||
- [Copying File Contents To System Paste Buffer](unix/copying-file-contents-to-system-paste-buffer.md)
|
||||
- [Copying Nested Directories With Ditto](unix/copying-nested-directories-with-ditto.md)
|
||||
- [Count The Lines In A CSV Where A Column Is Empty](unix/count-the-lines-in-a-csv-where-a-column-is-empty.md)
|
||||
|
||||
17
heroku/open-dashboard-for-specific-add-on.md
Normal file
17
heroku/open-dashboard-for-specific-add-on.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Open Dashboard For Specific Add-On
|
||||
|
||||
The number of times I've needed to check the papertrail logs for my
|
||||
Heroku-hosted Rails app is a lot. I open a browser tab, go through several
|
||||
layers of navigation to get to my app's dashboard, and then click the
|
||||
papertrail link under _Add-ons_.
|
||||
|
||||
There is a much quicker way using the Heroku CLI.
|
||||
|
||||
```bash
|
||||
$ heroku addons:open papertrail -a my-app-name
|
||||
Opening https://addons-sso.heroku.com/apps/abc123/addons/efg456...
|
||||
```
|
||||
|
||||
It sends you to an add-ons SSO link in the browser which authenticates you and
|
||||
drops you into the dashboard for that specific add-on. You just need to specify
|
||||
the add-on name and the app name.
|
||||
27
rails/generate-a-rails-app-from-the-main-branch.md
Normal file
27
rails/generate-a-rails-app-from-the-main-branch.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generate A Rails App From The Main Branch
|
||||
|
||||
Typically you are going to want to generate a Rails app using some officially
|
||||
released version of the framework. These releases have been thoroughly tested,
|
||||
have received patches, and can guarantee a certain level of stability.
|
||||
|
||||
However, if you are wanting to try out the latest, unreleased features, you may
|
||||
want to generate a fresh Rails app based off the current state of the `main`
|
||||
branch of the `rails` repository.
|
||||
|
||||
To do this, add the `--main` flag:
|
||||
|
||||
```bash
|
||||
$ rails new rails_app_on_main --main
|
||||
```
|
||||
|
||||
Toward the top of your app's `Gemfile`, you'll see that `rails` is pointed to
|
||||
the `main` branch of their repo:
|
||||
|
||||
```ruby
|
||||
# Use main development branch of Rails
|
||||
gem "rails", github: "rails/rails", branch: "main"
|
||||
```
|
||||
|
||||
See `rails new --help` for more details
|
||||
|
||||
[source](https://x.com/gregmolnar/status/1832720168264286571)
|
||||
33
rspec/configure-tests-to-run-in-random-order.md
Normal file
33
rspec/configure-tests-to-run-in-random-order.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Configure Tests To Run In Random Order
|
||||
|
||||
By default, an RSpec test suite is going to run in a predictable, sequential
|
||||
order, every time.
|
||||
|
||||
When testing the parts of a complex Rails app that have all kinds of test data
|
||||
that needs to be set up, I prefer to have my tests always run in a random
|
||||
(repeatable with a seed) order. This way I'm more likely to catch sooner,
|
||||
rather than later, bugs that are hidden by passing tests due to test data setup
|
||||
that happens to work in a specific order.
|
||||
|
||||
RSpec can be configured to run tests in a random, seedable order in the
|
||||
`spec_helper.rb` file.
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.order = :random
|
||||
end
|
||||
```
|
||||
|
||||
Whenever you run your test suite, the first thing you'll see is a message like
|
||||
this:
|
||||
|
||||
```
|
||||
Randomized with seed 7011
|
||||
```
|
||||
|
||||
That seed number can be used to re-run the suite in a repeatable order when you
|
||||
need to do so to track down an order-dependent failing test.
|
||||
|
||||
```bash
|
||||
$ be rspec --seed 7011
|
||||
```
|
||||
@@ -21,5 +21,7 @@ at the same time when you call
|
||||
|
||||
```ruby
|
||||
list = [3,7,4,15,9,1,2]
|
||||
|
||||
list.minmax
|
||||
#=> [1,15]
|
||||
```
|
||||
|
||||
46
ruby/multi-line-comments.md
Normal file
46
ruby/multi-line-comments.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Multi-Line Comments
|
||||
|
||||
Ruby has an obscure syntax for creating multi-line comments.
|
||||
|
||||
In many languages, there is a multi-line comment syntax that looks something
|
||||
like this:
|
||||
|
||||
```javascript
|
||||
/*
|
||||
* multi-line comment in javascript
|
||||
*/
|
||||
```
|
||||
|
||||
This gets used often in those languages.
|
||||
|
||||
In Ruby, the multi-line comment syntax is not something we see very often. It
|
||||
is a departure from the single-line comment syntax and it also requires no
|
||||
indentation.
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.order = :random
|
||||
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
=begin
|
||||
# These two settings work together to allow you to limit a spec run
|
||||
# to individual examples or groups you care about by tagging them with
|
||||
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
||||
# get run.
|
||||
config.filter_run :focus
|
||||
config.run_all_when_everything_filtered = true
|
||||
|
||||
# ...
|
||||
|
||||
=end
|
||||
end
|
||||
```
|
||||
|
||||
Using the `=begin` and `=end` syntax (no indentation), we make everything
|
||||
inbetween into a comment.
|
||||
|
||||
Though we don't see this too often, I did pull this example directly from the
|
||||
`spec_helper.rb` file that RSpec generates.
|
||||
|
||||
[source](https://docs.ruby-lang.org/en/master/syntax/comments_rdoc.html)
|
||||
28
unix/convert-svg-to-favicon.md
Normal file
28
unix/convert-svg-to-favicon.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Convert SVG To Favicon
|
||||
|
||||
The imagemagick `convert` CLI tool can convert an SVG file into a transparent
|
||||
favicon (ICO) file with the different standard sizes.
|
||||
|
||||
Assuming the background that we want to make transparent is white, then include
|
||||
`-transparent white` and then to resize the icon include `-define
|
||||
icon:auto-resize ...`. Point to the `image.svg` to be converted and specify the
|
||||
name of the output file (`favicon.ico`).
|
||||
|
||||
```bash
|
||||
$ convert image.svg -transparent white -define icon:auto-resize=16,32,48,64,128 favicon.ico
|
||||
```
|
||||
|
||||
We can then use the `identify` CLI to inspect the `favicon.ico` file to see
|
||||
that the above worked.
|
||||
|
||||
```bash
|
||||
$ identify favicon.ico
|
||||
|
||||
favicon.ico[0] ICO 16x16 16x16+0+0 8-bit sRGB 0.000u 0:00.002
|
||||
favicon.ico[1] ICO 32x32 32x32+0+0 8-bit sRGB 0.000u 0:00.004
|
||||
favicon.ico[2] ICO 48x48 48x48+0+0 8-bit sRGB 0.000u 0:00.004
|
||||
favicon.ico[3] ICO 64x64 64x64+0+0 8-bit sRGB 0.000u 0:00.004
|
||||
favicon.ico[4] ICO 128x128 128x128+0+0 8-bit sRGB 99678B 0.000u 0:00.003
|
||||
```
|
||||
|
||||
[source](https://www.joshmcarthur.com/2024/06/19/Auto-resizing-images-for-.ico-files.html)
|
||||
Reference in New Issue
Block a user