Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
null !== undefined but null == undefined ¯\_(ツ)_/¯

Leo Lanese leolanese

💻
null !== undefined but null == undefined ¯\_(ツ)_/¯
View GitHub Profile
View install-homebrew.sh
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
@leolanese
leolanese / selectionSort.js
Last active Apr 10, 2020
Sorting algorithms JS: Selection Sort Implementation
View selectionSort.js
//
// Selection Sort Implementation
//
function selectionSort (unsortedArray) {
if (unsortedArray.length <= 1) {
return unsortedArray;
}
for (let i = 0; i < unsortedArray.length; i++) {
@leolanese
leolanese / bubbleSort.js
Last active Apr 10, 2020
Sorting algorithms JS: Bubble Sort Implementation
View bubbleSort.js
//
// Bubble Sort Implementation
//
function bubbleSort (unsortedArray) {
if (unsortedArray.length <= 1) {
return unsortedArray;
}
for (let i = 0; i < unsortedArray.length; i++) {
@leolanese
leolanese / mergeSort.js
Last active Apr 10, 2020
Sorting algorithms JS: Merge Sort (Recursion)
View mergeSort.js
//
// Merge Sort Implentation (Recursion)
//
function mergeSort (unsortedArray) {
// No need to sort the array if the array only has one element or empty
if (unsortedArray.length <= 1) {
return unsortedArray;
}
// In order to divide the array in half, we need to figure out the middle
@leolanese
leolanese / removeUrlParameter.js
Created Apr 10, 2020
Remove url parameter from url path using fallback for IE and legacy browsers
View removeUrlParameter.js
function removeUrlParameter(url, param) {
if (typeof URLSearchParams !== 'undefined') {
// modern browsers
var r = new URL(url);
r.searchParams.delete(param);
return r.href;
} else {
// IE version
return url.replace(new RegExp('^([^#]*\?)(([^#]*)&)?' + parameter + '(\=[^&#]*)?(&|#|$)' ), '$1$3$5').replace(/^([^#]*)((\?)&|\?(#|$))/,'$1$3$4')
}
@leolanese
leolanese / FE-Object-Composition.txt
Last active Apr 10, 2020
Functional Programming: Object Composition
View FE-Object-Composition.txt
// 1
```javascript
function sum(a) {
return function(b) {
return function(c) {
return a + b + c;
};
};
}
```
View wait-async-nested-promises.js
// - WAIT FOR ME! - I PROMISE.
// resolve NESTED promises waiting for inner promises
function nestedPromisesThatresolveAfter4Seconds() {
return new Promise(resolve => {
setTimeout(() => {
setTimeout(() => {
console.log('setTimeout1')
resolve('Promise resolved');
}, 4000);
console.log('setTimeout2')
View create-new-git
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
View read-json-ES6
// We no longer need the "use strict" directive since
// all ECMAScript modules implicitly use strict mode.
import * as config from "./config.json";
app.listen(config.server.nodePort, () => {
console.log(`Listening on port ${config.server.nodePort} ...`);
});
@leolanese
leolanese / Show both Critical and High Issues
Created Oct 28, 2019
Show both Critical and High Issues
View Show both Critical and High Issues
npm audit | grep -E "(High | Critical)" -B3 -A10