Skip to content

Instantly share code, notes, and snippets.

View danny-andrews's full-sized avatar

Danny Andrews danny-andrews

View GitHub Profile
@danny-andrews
danny-andrews / sudoku-checker.js
Created November 13, 2023 22:39
Sudoku Checker Solution
export const checkSudoku = (board) => {
for (let i = 0; i < 4; i++) {
const row = new Set();
const col = new Set();
const square = new Set();
for (let j = 0; j < 4; j++) {
const rowEl = board[i][j];
const colEl = board[j][i];
const squareEl =
board[2 * Math.floor(i / 2) + Math.floor(j / 2)][2 * (i % 2) + (j % 2)];
@danny-andrews
danny-andrews / shell-command-structure.md
Last active September 5, 2023 20:48
Shell Command Structure Summary

Shell Command Structure Summary

Arguments (i.e. Positional Arguments)

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

cat file1.txt file2.txt


@danny-andrews
danny-andrews / loader.mjs
Created August 24, 2022 18:49
Node ESM Loader for JSX
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 / mac-install.md
Created March 3, 2022 15:45
Installing Postgres on Mac

Install SQL using Homebrew

Begin by updating brew:

brew update

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

@danny-andrews
danny-andrews / postgres-windows-installation.md
Last active October 10, 2023 17:26
Installing Postgres on Windows

Postgres Setup on WSL

  1. Download Postgres: sudo apt install postgresql.
  2. 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.
  3. Run $ psql -U postgres in command prompt. This runs the psql command as the default "postgres" superuser.
  4. Run: postgres=# CREATE USER "[WINDOWS_USERNAME]" WITH PASSWORD '[PASSWORD]' SUPERUSER;
  5. Quit postgres: postgres=# \q
  6. Run psql postgres and type the password you used in the CREATE USER command

Starting/Stopping/Restarting postgres: https://stackoverflow.com/a/53062239

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
/**
* 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) {}
@danny-andrews
danny-andrews / mongodb-quickstart.md
Last active July 14, 2021 21:16
MongoDB Quickstart
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
const reverseIterative = (arr) => {
const result = [];
for (let i = arr.length - 1; i >= 0; i--) {
result.push(arr[i]);
}
return result;
};
const reverseRec = (arr) =>