Skip to content

Instantly share code, notes, and snippets.

Avatar

Danny Andrews danny-andrews

View GitHub Profile
@danny-andrews
danny-andrews / mac-install.md
Created Mar 3, 2022
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.

@danny-andrews
danny-andrews / postgres-windows-installation.md
Last active Jul 21, 2022
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.
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
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
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) =>
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;
}
@danny-andrews
danny-andrews / reverse-linked-list.js
Last active Jun 28, 2021
Linked List Reversal Prompt
View reverse-linked-list.js
// Given the linked list implementation below
// write a method which reverses the list.
function ListNode(data) {
this.data = data;
this.next = null;
}
class LinkedList {
constructor() {
this.head = null;
View vanilla-ticker.js
const template = document
.createElement("template");
template.innerHTML = `<span></span>`;
class MyTicker extends HTMLElement {
constructor() {
super();
this.ticks = 0;
this.attachShadow({ mode: "open" });
this.shadowRoot.appendChild(