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 / howToImport.py
Created November 4, 2020 06:47
Python import + if __name__ == "__main__":
# sand box 1 file -------------------------------------------------------------------
import SandBox2
if __name__ == "__main__":
print("Executed when invoked directly from SANDBOX 1")
else:
print("Executed when imported from SANDBOX 1")
@whal-e3
whal-e3 / iterNext.py
Last active November 4, 2020 06:48
Python OOP User defined iterator ( how to use __iter__ and __next__ )
class EvenNum:
def __init__(self, size) -> None:
self.size = size
print(self, end=" : ")
def __iter__(self):
self.count = 0
return self
def __next__(self):
@whal-e3
whal-e3 / loanCalc.js
Created November 4, 2020 05:43
JS Loan Calculator (isFinite(), setTimeout())
// Listen for submit
document.getElementById('loan-form').addEventListener('submit', function (e) {
// Hide results
document.getElementById('results').style.display = 'none';
// Show loader
document.getElementById('loading').style.display = 'block';
setTimeout(calculateResults, 2000);
e.preventDefault();
@whal-e3
whal-e3 / taskListForm.js
Created November 1, 2020 09:24
JS form of Task List application
// Define UI variables
const form = document.querySelector('#task-form');
const taskList = document.querySelector('.collection');
const clearBtn = document.querySelector('.clear-tasks');
const filter = document.querySelector('#filter');
const taskInput = document.querySelector('#task');
// Load all event listeners
loadEventListeners();
@whal-e3
whal-e3 / loc_storage.js
Created October 27, 2020 05:38
JavaScript Local/Session storage
// Local & Session storage
// Only difference = local - data remains // Session - erased when browser closed(session ends)
// --------------------------------------------------------------------
// set local storage item
localStorage.setItem('name', 'John');
localStorage.setItem('age', '30');
sessionStorage.setItem('name', 'Beth');
@whal-e3
whal-e3 / dom.js
Created October 27, 2020 05:03
JavaScript DOM manipulation & events
let val;
val = document;
// val = document.all;
// val = document.all[2];
val = document.head;
val = document.body;
val = document.doctype;
@whal-e3
whal-e3 / higherOrderFunction_Array.js
Last active November 10, 2020 13:25
forEach, filter, map, sort, reduce
// This file is used in youtube video "Traversy Media".
// visit "Traversy Media" down below
// https://www.youtube.com/watch?v=rRgD1yVwIvE&list=PLillGF-RfqbbnEGy3ROiLWk7JMCuSyQtX&index=9
const companies= [
{name: "Company One", category: "Finance", start: 1981, end: 2004},
{name: "Company Two", category: "Retail", start: 1992, end: 2008},
{name: "Company Three", category: "Auto", start: 1999, end: 2007},
{name: "Company Four", category: "Retail", start: 1989, end: 2010},
@whal-e3
whal-e3 / postgreSQL_cheatsheet.txt
Last active October 19, 2020 12:49
PostgreSQL 13 cheat sheet
SELECT COUNT(DISTINCT(*)) FROM _somewhere_
WHERE _something_ <= 12 AND _something2_ = '_word_'
WHERE _something_ BETWEEN 8 AND 9
WHERE _something_ IN (0.99, 1.98, 1.99)
WHERE _something_ LIKE/ILIKE '_J%'
ORDER BY _something_ ASC, _something2_ DESC
LIMIT 5;
// EXAMINE THE DOCUMENT OBJECT // -- by Traversy Media
console.dir(document);
console.log(document.domain);
console.log(document.URL);
console.log(document.title);
//document.title = 123;
console.log(document.doctype);
console.log(document.head);
console.log(document.body);
@whal-e3
whal-e3 / Big integer multiplication using vector.cpp
Created March 30, 2020 05:10
Big integer multiplication method using vector! (Elements represent each number in decimal.)
#include <iostream>
#include <string>
#include <vector>
long long int reg_factorial(int num) {
long long int res = 1;
for (int i = num; i > 0; i--) res *= i;
return res;
}
std::vector<long long int> spe_factorial(int num) {