[SEO] Cache mechanism notes

  • Check if the cache is fresh and do NOT send request

Expires

Cache-Control: max-age=...

  • Send request and check if 304 or a fresh payload should be returned:

Last-Modified <===> If-Modified-Since

Etag <===> If-None-Match

  • Do not cache anything

Cache-Control: no-store

  • Stale-while-revalidate

Cache-Control: no-cache

[Git] Change case of a folder name

Make sure you have the ignorecase set to false:

git config core.ignorecase false

Then, do two git mv:

git mv foldername tempname
git mv tempname folderName

[Regex] Lookarounds

  • Positive lookahead
Regex: \d+(?=apples)
String: "666apples"
Match: "666"
  • Negative lookahead
Regex: \d+(?!apples)
String: "666bananas"
Match: "666"
  • Positive lookbehind
Regex: (?<=apples)\d+
String: "apples666"
Match: "666"
  • Negative lookbehind
Regex: (?<!apples)\d+
String: "bananas666"
Match: "666"

[Git] Change commit author

Use git rebase to select commits you want to modify

git rebase -i --root

And then for each rebase step, execute the following:

git commit --amend --reset-author --no-edit
git rebase --continue

[CSS] Text related CSS properties

  • white-space: Control how space characters behave
  • word-break: Control how the words are being broken
word-break: normal;
word-break: break-all;
word-break: keep-all;
word-break: break-word; /* deprecated */
  • word-wrap / overflow-wrap: Same as word-break but only apply when the remaining space is not enough
overflow-wrap: normal;
overflow-wrap: break-word;
overflow-wrap: anywhere;
  • text-overflow: Specify the appearance when the text is being wrapped
text-overflow: clip;
text-overflow: ellipsis ellipsis;
text-overflow: ellipsis " [..]";

[Express] Basic concept notes

Middleware (handlers)

  • Order-sensitive
  • Triggered by previous MW next()
  • Every middleware should call next() or end the request-response cycle
  • Changes to req and res will be passed down
  • App level MW: Bind to app
  • Router level MW: Bind to express.Router()
    • next('route'): Bypass remaining route callbacks
    • next('router'): Bypass remaining routes
  • Error-handling MW: (err, req, res, next) => { … }

Error handling

  • When an error occurs with next(myErr), remaining non-error MW will be skipped
  • Synchronous code: throw error;
  • Asynchronous code
    • Express 4: next(error);
    • Express 5: automatically call next(error);

[Mac] Useful commands

  • Open finder in current working directory
open .