Skip to content

Instantly share code, notes, and snippets.

View leolanese's full-sized avatar
💻
[] === []; // false ¯\_(ツ)_/¯

Leo Lanese leolanese

💻
[] === []; // false ¯\_(ツ)_/¯
View GitHub Profile
@leolanese
leolanese / fp-curry
Created October 28, 2019 15:17
fp-curry
/**
* @param curry
*
* @usage
* const _sum3 = (x, y, z) => x + y + z;
* const _sum4 = (p, q, r, s) => p + q + r + s;
*
* const sum3 = curry(_sum3);
* sum3(1)(3)(2); // 6
* const sum4 = curry(_sum4);
@leolanese
leolanese / fp-varadocCurry
Created October 28, 2019 15:18
fp-varadocCurry
/**
*
* @param varadocCurry
*
* @usage
* const toSum = varadocCurry((x, y) => x + y, 0);
* const toMul = varadocCurry((x, y) => x * y, 1);
*
* toSum(1)(1, 2)(3, 4)(5, 6, 7)(); // 29
* toMul(1)(1, 2)(3, 4); // 24
@leolanese
leolanese / Show both Critical and High Issues
Created October 28, 2019 16:26
Show both Critical and High Issues
npm audit | grep -E "(High | Critical)" -B3 -A10
// 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} ...`);
});
// - 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')
-- 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
@leolanese
leolanese / removeUrlParameter.js
Created April 10, 2020 04:36
Remove url parameter from url path using fallback for IE and legacy browsers
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 April 10, 2020 04:38
Functional Programming: Object Composition
// 1
```javascript
function sum(a) {
return function(b) {
return function(c) {
return a + b + c;
};
};
}
```
@leolanese
leolanese / selectionSort.js
Last active April 10, 2020 08:42
Sorting algorithms JS: Selection Sort Implementation
//
// 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 April 10, 2020 08:43
Sorting algorithms JS: Bubble Sort Implementation
//
// Bubble Sort Implementation
//
function bubbleSort (unsortedArray) {
if (unsortedArray.length <= 1) {
return unsortedArray;
}
for (let i = 0; i < unsortedArray.length; i++) {