Today I Learned

4 posts by joneriksuero

Exclusion using File Masks

When using Find in Path.. functionality to find a word across multiple files, file masks can be used to match certain types of files. For example, using *.rb will only look through Ruby files. On the other hand, if you want to exclude Ruby files instead, you can add an ! at the front (i.e. !*.rb).

Here are other useful examples/combinations:

all files excluding spec tests: !*spec.rb

all Ruby files excluding spec tests: *.rb,!*spec.rb

Bulk Upsert through PostgreSQL 9.5+

Warning: This only works for PostgreSQL 9.5+


Given the following:

  1. a users table:

    • id
    • name
    • created_at
    • updated_at
  2. users table only has 1 user with values:

    • id: 1
    • name: Alejandro
    • created_at: '2010-10-10 10:00:00.000000'
    • updated_at: '2010-10-10 10:00:00.000000'

You can upsert using the following SQL query:

INSERT INTO
  users(id, name, created_at, updated_at)
VALUES
  (1, 'Alexander', NOW(), NOW()),
  (2, 'Belle', NOW(), NOW())
ON CONFLICT (id)
  DO UPDATE SET
    name=EXCLUDED.name,
    updated_at=NOW()
;

Results:

  1. User(id=1) will be renamed from Alejandro to Alexander. The updated_at value will be set to current time.
  2. User(id=2) will be inserted to users table with name = Belle, and both created_at and updated_at will be set to current time.

Bundle Console

bundle console [GROUP]

runs Ruby console with bundled gems

Get Overwritten/Discarded Commits using reflog

git reflog

shows commits including the overwritten/discarded ones. This is useful in case of accidents such as unwanted git commit --amend and git reset.

Source

https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog

Extra

Use git reflog --date=iso to include dates.