mirror of
https://github.com/jbranchaud/til
synced 2026-01-17 05:58:01 +00:00
Compare commits
4 Commits
90690fffde
...
06d3ffc179
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06d3ffc179 | ||
|
|
1f039a8958 | ||
|
|
c6eefeac98 | ||
|
|
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).
|
||||
|
||||
_1574 TILs and counting..._
|
||||
_1576 TILs and counting..._
|
||||
|
||||
See some of the other learning resources I work on:
|
||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||
@@ -199,6 +199,7 @@ See some of the other learning resources I work on:
|
||||
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
||||
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
||||
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
||||
- [Default Rails Deploy Script On Hatchbox](devops/default-rails-deploy-script-on-hatchbox.md)
|
||||
- [Determine The IP Address Of A Domain](devops/determine-the-ip-address-of-a-domain.md)
|
||||
- [Hatchbox Exports Env Vars With asdf](devops/hatchbox-exports-env-vars-with-asdf.md)
|
||||
- [Path Of The Packets](devops/path-of-the-packets.md)
|
||||
@@ -780,6 +781,7 @@ See some of the other learning resources I work on:
|
||||
- [Convert A String To A Timestamp](postgres/convert-a-string-to-a-timestamp.md)
|
||||
- [Count How Many Records There Are Of Each Type](postgres/count-how-many-records-there-are-of-each-type.md)
|
||||
- [Count Records By Type](postgres/count-records-by-type.md)
|
||||
- [Count The Number Of Items In An Array](postgres/count-the-number-of-items-in-an-array.md)
|
||||
- [Count The Number Of Trues In An Aggregate Query](postgres/count-the-number-of-trues-in-an-aggregate-query.md)
|
||||
- [Create A Cluster In A Specific Data Directory](postgres/create-a-cluster-in-a-specific-data-directory.md)
|
||||
- [Create A Composite Primary Key](postgres/create-a-composite-primary-key.md)
|
||||
|
||||
28
devops/default-rails-deploy-script-on-hatchbox.md
Normal file
28
devops/default-rails-deploy-script-on-hatchbox.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Default Rails Deploy Script On Hatchbox
|
||||
|
||||
I deployed a Rails app to [Hatchbox](https://hatchbox.io) recently. When
|
||||
following along in the log during a deploy, I can see most of what is happening
|
||||
as part of the deploy. Though it is too verbose to look through every line. I'd
|
||||
rather see the contents of the deploy script.
|
||||
|
||||
I did quite a bit of digging around while SSH'd into my hatchbox server, but I
|
||||
couldn't find if or where that file might be stored.
|
||||
|
||||
Instead, there is a [_Help Center_
|
||||
article](https://hatchbox.relationkit.io/articles/55-what-is-the-default-rails-deploy-script)
|
||||
where Chris Oliver shares what is in the script.
|
||||
|
||||
```bash
|
||||
bundle install -j $(nproc)
|
||||
yarn install
|
||||
bundle exec rails assets:precompile
|
||||
[[ -n "${CRON}" ]] && bundle exec rails db:migrate
|
||||
```
|
||||
|
||||
It does a parallelized `bundle install`, then a `yarn install` (make sure your
|
||||
project is using `yarn.lock`), Rails asset precompilation, and then if `CRON`
|
||||
is set (Cron role is available by checking _Cron_ under _Server
|
||||
Responsibilities_ for your Hatchbox server), it will run Rails migrations.
|
||||
|
||||
From app settings, the deploy script can be overridden, or pre- and post-deploy
|
||||
steps can be added.
|
||||
@@ -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);
|
||||
|
||||
56
postgres/count-the-number-of-items-in-an-array.md
Normal file
56
postgres/count-the-number-of-items-in-an-array.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Count The Number Of Items In An Array
|
||||
|
||||
There are two ways to count the number of items in an array with PostgreSQL.
|
||||
The one that might jump out at you or show up at the top of search results is
|
||||
[`array_length`](https://www.postgresql.org/docs/current/functions-array.html).
|
||||
|
||||
```sql
|
||||
> select array_length(array[1,2,3], 1);
|
||||
+--------------+
|
||||
| array_length |
|
||||
|--------------|
|
||||
| 3 |
|
||||
+--------------+
|
||||
|
||||
> select array_length(array[[1,2], [3,4]], 2);
|
||||
+--------------+
|
||||
| array_length |
|
||||
|--------------|
|
||||
| 2 |
|
||||
+--------------+
|
||||
```
|
||||
|
||||
This requires specifying the dimension at which you want to check the length.
|
||||
The first example, checking the 1st dimension of a one-dimensional array, seems
|
||||
like the more common and useful scenario. In the second example, we are
|
||||
checking the 2nd dimension.
|
||||
|
||||
The other way we can determine the number of items in an array is with the
|
||||
[`cardinality`](https://www.postgresql.org/docs/current/functions-array.html)
|
||||
function.
|
||||
|
||||
> Returns the total number of elements in the array, or 0 if the array is
|
||||
> empty.
|
||||
|
||||
```sql
|
||||
> select cardinality(array[1,2,3]);
|
||||
+-------------+
|
||||
| cardinality |
|
||||
|-------------|
|
||||
| 3 |
|
||||
+-------------+
|
||||
|
||||
> select cardinality(array[[1,2], [3,4]]);
|
||||
+-------------+
|
||||
| cardinality |
|
||||
|-------------|
|
||||
| 4 |
|
||||
+-------------+
|
||||
```
|
||||
|
||||
This behaves the same as `array_length` for a one-dimensional array and doesn't
|
||||
require a second argument. Where it gets more interesting is with
|
||||
multi-dimensional arrays. It returns the total number of elements in the
|
||||
arrayregardless of the nesting.
|
||||
|
||||
[source](https://mattrighetti.com/2025/01/20/you-dont-need-sql-builders)
|
||||
Reference in New Issue
Block a user