Skip to content

Instantly share code, notes, and snippets.

View MaxXxiMast's full-sized avatar

Purujit Negi MaxXxiMast

View GitHub Profile
@MaxXxiMast
MaxXxiMast / cloudSettings
Created February 5, 2021 16:42 — forked from samselikoff/cloudSettings
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-05-01T19:06:41.818Z","extensionVersion":"v3.4.3"}
@MaxXxiMast
MaxXxiMast / waitAndProcess.js
Created April 18, 2020 21:50
Process multiple values through a promise one by one
function processAll(){
return asyncAction.then(x => waitForEach(y => processFunc(y), x))
}
const waitForEach = (processFunc, [head, ...tail]) => {
!head
? Promise.resolve()
: processFunc(head).then(waitForEach(processFunc, tail))
}
const superSet = arr => {
var result = [];
result.push([])
arr.forEach(val => {
let length = result.length;
let i = 0;
while(i < length){
let newAr = result[i].slice(0);
newAr.push(val);
result.push(newAr);
@MaxXxiMast
MaxXxiMast / objectIsPolyfill.js
Last active June 25, 2019 08:12
Object.is Polyfill
if (!Object.is) {
Object.is = function ObjectIs(x, y) {
if (x === y) {
return x !== 0 || 1/x === 1/y
} else {
return x !== x && y !== y;
}
}
}
@MaxXxiMast
MaxXxiMast / checkSign.js
Last active June 25, 2019 06:45
Check the Sign on a Number taking -ve 0 into consideration
function checkSign(x){
return x !== 0 ? Math.sign(x) : Object.is(x, -0) ? -1 : 1;
}
checkSign(-0) // -1 i.e. -ve sign
checkSign(0) // 1 i.e. +ve sign
checkSign(-6) // -1
checkSign(6) // 1
credits: Kyle Simpson (getify)
@MaxXxiMast
MaxXxiMast / plusplus.js
Created June 24, 2019 13:15
How a ++ operator works
function plusplus(orig_x){
let orig_x_changed = Number(orig_x);
x = orig_x_changed + 1;
return orig_x_changed;
}
let x = '2';
plusplus(x); // 2
x; // 3
@MaxXxiMast
MaxXxiMast / spiral_matrix.js
Created January 21, 2019 16:33
Flatten a 2D Array into a spiral format
//ES6
function spiral(matrix) {
const arr = [];
while (matrix.length) {
arr.push(
...matrix.shift(),
...matrix.map(a => a.pop()),
...(matrix.pop() || []).reverse(),
...matrix.map(a => a.shift()).reverse()
@MaxXxiMast
MaxXxiMast / array_intersect.min.js
Last active January 16, 2019 08:54
Calculate the Intersection of Arrays
function array_intersect(){var a,b,c,d,e,f,g=[],h={},i;i=arguments.length-1;d=arguments[0].length;c=0;for(a=0;a<=i;a++){e=arguments[a].length;if(e<d){c=a;d=e}}for(a=0;a<=i;a++){e=a===c?0:a||c;f=arguments[e].length;for(var j=0;j<f;j++){var k=arguments[e][j];if(h[k]===a-1){if(a===i){g.push(k);h[k]=0}else{h[k]=a}}else if(a===0){h[k]=0}}}return g}
function textSize(text) {
if (!d3) return;
var container = d3.select('body').append('svg');
container.append('text').attr('x', -99999).attr('y',-99999).text(text);
var size = container.node().getBBox();
container.remove();
return { width: size.width, height: size.height };
}
// Usage: textSize("This is a very long text");
https://reqres.in/
http://www.omdbapi.com/