Skip to content

Instantly share code, notes, and snippets.

View whal-e3's full-sized avatar

Eric Whale whal-e3

View GitHub Profile
@whal-e3
whal-e3 / tsBasics.ts
Created September 9, 2021 03:08
TypeScript Basics
let id: number = 5;
let company: string = "Eric";
let isBool: boolean = true;
let x: any = 2;
x = false;
let ids: number[] = [1, 2, 3, 4, 5];
let arr: any[] = [1, true, "asf"];
// Tuple (fixed number of elements and types)
@whal-e3
whal-e3 / mongodb_cheat_sheet.md
Created February 5, 2021 10:28 — forked from bradtraversy/mongodb_cheat_sheet.md
MongoDB Cheat Sheet

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@whal-e3
whal-e3 / pattern.js
Last active November 26, 2020 09:50
JS Patterns
// PATTERN
// MODULE PATTERN
// BASIC Structure
// IIFE (immediate invoked function expression)
(function () {
// Declare private vars and functions
return {
@whal-e3
whal-e3 / set.js
Created November 25, 2020 02:35
JS sets (unique values)
// SET - unique values
const set1 = new Set();
set1.add(100);
set1.add('A string');
set1.add({ name: 'John' });
set1.add(true);
set1.add(100);
@whal-e3
whal-e3 / map.js
Last active November 25, 2020 02:22
JS maps (key - value pair)
// MAP (key-value pair)
const map = new Map();
const key1 = 'string key',
key2 = {},
key3 = function () {};
map.set(key1, 'value of key1');
map.set(key2, 'value of key2');
map.set(key3, 'value of key3');
@whal-e3
whal-e3 / destruct.js
Created November 25, 2020 01:58
JS Destructuring - Object destructuring*
// Destructuring Assignment
let a, b;
[a, b] = [100, 200];
// Basic + (rest)
[a, b, c, ...rest] = [100, 200, 300, 400, 500];
// # OBJECT # + (rest)
({ a, b, ...rest } = { a: 100, b: 200, c: 300, d: 400, e: 500 });
@whal-e3
whal-e3 / iter_datingWebsite.js
Created November 24, 2020 06:55
JS Iterator/Generator - real use (dating website)
const data = [
{
name: 'John Doe',
age: 32,
gender: 'male',
lookingfor: 'female',
location: 'Boston MA',
image: 'https://randomuser.me/api/portraits/men/82.jpg'
},
{
@whal-e3
whal-e3 / iter_gene.js
Created November 24, 2020 06:15
JS iterator/generator baiscs
// Iterator
function nameIterator(names) {
let nextIndex = 0;
return {
next: function () {
return nextIndex < names.length
? { value: names[nextIndex++], done: false }
: { done: true };
}
};
@whal-e3
whal-e3 / regex.js
Created November 23, 2020 05:51
JS regular expression (regex)
let reg, result, str;
reg = /hello/g; // global search
reg = /hello/;
reg = /hello/i; // i == flag : case insensitive
console.log(reg);
console.log(reg.source);
// exec() - result in array or null
result = reg.exec('hello world');
@whal-e3
whal-e3 / errorHandle.js
Created November 23, 2020 02:52
JS error handling (try/catch/finally/throw)
const user = { email: 'jdoe@gmail.com' };
try {
if (!user.name) {
// throw 'User has no name';
throw new SyntaxError('User has no name');
}
} catch (e) {
console.log(`User Error: ${e.message}`);
// console.log(e.message);