mirror of
https://github.com/jbranchaud/til
synced 2026-01-16 21:48:02 +00:00
Compare commits
2 Commits
b6e5ea4c03
...
11859a096f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11859a096f | ||
|
|
6096f5af10 |
@@ -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).
|
||||
|
||||
_1399 TILs and counting..._
|
||||
_1401 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -624,6 +624,7 @@ _1399 TILs and counting..._
|
||||
- [Fetch Does Not Work In API Serverless Function](nextjs/fetch-does-not-work-in-api-serverless-function.md)
|
||||
- [Make Environment Variable Publicly Available](nextjs/make-environment-variable-publicly-available.md)
|
||||
- [Match Middleware On Groups Of Paths](nextjs/match-middleware-on-groups-of-paths.md)
|
||||
- [Precedence Of Dot Env Files](nextjs/precedence-of-dot-env-files.md)
|
||||
- [Push A Route With A URL Object](nextjs/push-a-route-with-a-url-object.md)
|
||||
- [Redirect An Unauthorized User](nextjs/redirect-an-unauthorized-user.md)
|
||||
- [Remove A Query Param From The URL](nextjs/remove-a-query-param-from-the-url.md)
|
||||
@@ -1129,6 +1130,7 @@ _1399 TILs and counting..._
|
||||
- [Fetch Warns About Superseding Block Argument](ruby/fetch-warns-about-superseding-block-argument.md)
|
||||
- [Find The Min And Max With A Single Call](ruby/find-the-min-and-max-with-a-single-call.md)
|
||||
- [Finding The Source of Ruby Methods](ruby/finding-the-source-of-ruby-methods.md)
|
||||
- [Format A Hash Into A String Template](ruby/format-a-hash-into-a-string-template.md)
|
||||
- [Generate A Signed JWT Token](ruby/generate-a-signed-jwt-token.md)
|
||||
- [Generate Ruby Version And Gemset Files With RVM](ruby/generate-ruby-version-and-gemset-files-with-rvm.md)
|
||||
- [Get Info About Your RubyGems Environment](ruby/get-info-about-your-ruby-gems-environment.md)
|
||||
|
||||
41
nextjs/precedence-of-dot-env-files.md
Normal file
41
nextjs/precedence-of-dot-env-files.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Precedence Of Dot Env Files
|
||||
|
||||
_Dot Env_ files like `.env`, `.env.development`, `.env.local`, etc. are one of
|
||||
the main ways to configure your Next.js app across various environments.
|
||||
|
||||
It's not uncommon to see several different `.env*` files in production app that
|
||||
is under active development.
|
||||
|
||||
Here is an example of almost every variant in play:
|
||||
|
||||
```bash
|
||||
$ ls -a -1 .env*
|
||||
.env
|
||||
.env.development
|
||||
.env.development.local
|
||||
.env.development.local.example
|
||||
.env.local
|
||||
.env.production
|
||||
.env.test
|
||||
```
|
||||
|
||||
So, how does Next.js decide which files to load and in what order?
|
||||
|
||||
It will always attempt to load `.env` and `.env.local` (except in `test`) if
|
||||
those exist. It will also look for environment-specific files based on the
|
||||
`NODE_ENV` (which can be one of `development`, `test`, or `production`). So, in
|
||||
`development`, the `.env.development` and `.env.development.local` will be
|
||||
loaded. Something like `.env.development.local.example` isn't on the list, but
|
||||
rather is a convention for a dotenv file's template.
|
||||
|
||||
As for the order, the environment itself (your system's environment variables)
|
||||
which are present in `process.env` take the highest precedence. After that, it
|
||||
looks in any of the follow present files in this order, stopping once it finds
|
||||
what it is looking for:
|
||||
|
||||
- `.env.$(NODE_ENV).local`
|
||||
- `.env.local`
|
||||
- `.env.$(NODE_ENV)`
|
||||
- `.env`
|
||||
|
||||
[source](https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#environment-variable-load-order)
|
||||
35
ruby/format-a-hash-into-a-string-template.md
Normal file
35
ruby/format-a-hash-into-a-string-template.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Format A Hash Into A String Template
|
||||
|
||||
The `%` method as defined by `String`
|
||||
([`String#%`](https://ruby-doc.org/core-3.0.0/String.html#method-i-25)) allows
|
||||
you to format (interpolate) an object or array of values into a string. That
|
||||
string needs to contain template markers for where the values should go.
|
||||
|
||||
Here is an example of folding an array of values into a string with [`%s`
|
||||
format
|
||||
specifier](https://docs.ruby-lang.org/en/master/format_specifications_rdoc.html#label-Specifier+s):
|
||||
|
||||
```ruby
|
||||
> User = Struct.new(:id)
|
||||
=> User
|
||||
> user1 = User.new(123)
|
||||
=> #<struct User id=123>
|
||||
> "%s ID: %s" % [user1.class.to_s, user1.id]
|
||||
=> "User ID: 123"
|
||||
```
|
||||
|
||||
Or perhaps more usefully for a string that acts as a template, you can used
|
||||
named specifiers that correspond to hash keys:
|
||||
|
||||
```ruby
|
||||
> template = "You paid %{formatted_price} for %{product}. Enjoy your purchase!"
|
||||
=> "You paid %{formatted_price} for %{product}. Enjoy your purchase!"
|
||||
|
||||
> data = { product: "Ruby Explained™", formatted_price: "$38.99" }
|
||||
=> {:product=>"Ruby Explained™", :formatted_price=>"$38.99"}
|
||||
|
||||
> template % data
|
||||
=> "You paid $38.99 for Ruby Explained™. Enjoy your purchase!"
|
||||
```
|
||||
|
||||
[source](https://hashrocket.com/blog/posts/using-a-hash-of-data-for-string-replacement-in-ruby)
|
||||
Reference in New Issue
Block a user