Skip to content

Instantly share code, notes, and snippets.

View jeromecovington's full-sized avatar

Jerome Covington jeromecovington

View GitHub Profile
@jeromecovington
jeromecovington / revalidate.ts
Created February 8, 2023 13:48
NextJS on-demand revalidation endpoint
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
if (
!req.query.revalidate_token ||
!process.env.REVALIDATE_TOKEN ||
req.query.revalidate_token !== process.env.REVALIDATE_TOKEN
@jeromecovington
jeromecovington / curl-in-brief.md
Last active November 10, 2021 21:05
Curl in brief

Basic

curl https://www.keycdn.com

Returning only the HTTP headers of a URL

curl -I https://www.keycdn.com

ALTER

ALTER TABLE table_name
ADD column_name datatype;

AND

SELECT column_name(s) 
FROM table_name
@jeromecovington
jeromecovington / dynamic-fibonacci.js
Created June 8, 2021 20:35
Dynamic programming fibonacci example
// Naive recursion.
function fib1(n) {
if (n <= 1) {
return n
}
return fib1(n - 1) + fib1(n - 2)
}
{
console.log('fib1')
@jeromecovington
jeromecovington / diff-redis-dumps.md
Created April 23, 2021 19:42
Save and diff Redis dumps
$ redis-cli --rdb dump-before.rdb save
$ redis-cli --rdb dump-after.rdb save
$ pip install rdbtools python-lzf
$ rdb --command diff dump-before.rdb | sort > sorted-dump-before.out
$ rdb --command diff dump-after.rdb | sort > sorted-dump-after.out
$ diff sorted-dump-before.out sorted-dump-after.out
type PartiallyRequired<T, K extends keyof T> = Pick<T, K> & Partial<T>;
type Test = {
foo: string;
bar: string;
baz: string;
};
type Test1 = PartiallyRequired<Test, "foo">;
Matchers
^
Match starting position
.
Match any single character, enclose in bracket for literal dot
a.c -> "abc", etc.
[a.c] -> "a", ".", "c"
[ ]
Match single character, or character within range
[abc], [a-c] -> "a", "b", "c"
AWSTemplateFormatVersion: "version date"
" String
Description:
" template metadata
" arbitrary yaml
" CloudFormation helper scripts
" cfn-init, cfn-signal, cfn-get-metadata, cfn-hup
" Resources can have Metadata (install scripts, etc.)
@jeromecovington
jeromecovington / vim-vscode-in-brief.txt
Last active September 14, 2020 16:45
vim + vscode in brief
"word" motions (no special chars)
w
forward by word
b
backward by word
e
end of word
ge
end of word (backward)
@jeromecovington
jeromecovington / nsolid-in-brief.md
Created February 14, 2020 21:40
Nsolid usage in brief

MacOS

  1. $ brew tap nodesource/nsolid
  2. $ brew install nsolid-console
  3. $ nsolid-console
  4. Run any script necessary to build app.
  5. $ NSOLID_APPNAME="my-app" NSOLID_COMMAND="localhost:9001" nsolid my-app/index.js
  6. Visit console at http://localhost:6753
  7. Start profiling in console.
  8. Exert load on local app at its usual port.
  9. Analyze and export results in console.