Skip to content

Instantly share code, notes, and snippets.

Avatar

Danny Andrews danny-andrews

View GitHub Profile
@danny-andrews
danny-andrews / shell-command-structure.md
Last active March 31, 2023 18:22
Shell Command Structure Summary
View shell-command-structure.md

Shell Command Structure Summary

Positional Arguments

Positional arguments are passed as-is after the command name.

cat file1.txt file2.txt


@danny-andrews
danny-andrews / loader.mjs
Created August 24, 2022 18:49
Node ESM Loader for JSX
View loader.mjs
import esbuild from "esbuild";
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
export async function load(url, context, nextLoad) {
const source = await readFile(fileURLToPath(url), "utf-8");
if (/\.jsx$/.test(url)) {
const transformedSource = await esbuild.transform(source, {
loader: "jsx",
@danny-andrews
danny-andrews / postgres-windows-installation.md
Last active July 21, 2022 16:16
Installing Postgres on Windows
View postgres-windows-installation.md

Postgres Setup on Windows

  1. Download Postgres installer.
  2. Run installer.
    1. Keep all default options selected (PGAdmin, command line tools, etc.)
    2. Keep port at default: 5432
  3. Navigate to the directory where you installed postgres, and enter the bin directory (should be something like C://Program Files/PostgreSQL/[VERSION_NUM]/bin). Copy this file path and add it to your PATH environment variable.
  4. NOTE: Restart your terminal if you already have it open. And if you're using the terminal in VSCode, you'll have to restart VSCode to have it pick up the changes to the PATH variable.
  5. Run $ psql -U postgres in command prompt. This runs the psql command as the default "postgres" superuser.
  6. Type password you used during install.
@danny-andrews
danny-andrews / mac-install.md
Created March 3, 2022 15:45
Installing Postgres on Mac
View mac-install.md

Install SQL using Homebrew

Begin by updating brew:

brew update

To install the latest version of PostgreSQL using Homebrew, run the following commands.

View array-cheat-sheet.md

Cheat sheet: JavaScript Array methods

Finding Array elements:

['■', '●', '■'].includes('■')            true
['■', '●', '■'].indexOf('■')             0
['■', '●', '■'].lastIndexOf('■')         2
['■', '●', '■'].find(x => x==='■')       ''
['■', '●', '■'].findIndex(x => x==='■')  0
@danny-andrews
danny-andrews / longest-palindrome.js
Created July 20, 2021 14:35
Longest Palindrome
View longest-palindrome.js
/**
* Implement a function that finds the longest palindrome in a given string.
* For example, in the string "My dad is a racecar athlete", the longest
* palindrome is "a racecar a". Count whitespaces as valid characters. Other
* palindromes in the above string include "dad", "ete", " dad " (including
* whitespace on each side of dad).
*/
function longestPalindrome(string) {}
View binary-tree.js
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
// Every value in the Left subtree less than root
// Every value in the right subtree is greater than or equal to the root
@danny-andrews
danny-andrews / recursive-reverse.js
Last active July 6, 2021 16:50
Recursive Reverse
View recursive-reverse.js
const reverseIterative = (arr) => {
const result = [];
for (let i = arr.length - 1; i >= 0; i--) {
result.push(arr[i]);
}
return result;
};
const reverseRec = (arr) =>
@danny-andrews
danny-andrews / factorial.js
Created July 6, 2021 15:03
Recursion example
View factorial.js
// 4! = 4 * 3 * 2 * 1
// 5! = 5 * 4 * 3 * 2 * 1
// 1! = 1
// 0! = 1
const factorial = (num) => {
let total = 1;
for(let i = 1; i <= num; i++) {
total *= i;
}