This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getBase64FromImageUrl(URL: string, width: number, height: number, setImageSize?: boolean):Promise<string> { | |
return new Promise((res, rej) => { | |
const img = new Image(); | |
img.src = URL; | |
img.onload = function() { | |
const canvas = document.createElement("canvas"); | |
canvas.width = width; | |
canvas.height = height; | |
const ctx = canvas.getContext("2d"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=5 | |
indicator("Telecoin", overlay=true) | |
// Define colors | |
// Get risk background color for dashboard | |
// Somewhat of gradient | |
get_risk_bgcol(r) => | |
risk = r * 100 | |
col = color.green | |
if risk <= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @module | |
* @description It schedules running HTTP requests | |
*/ | |
export const requestsManager = (function() { | |
const waitingQueue = []; | |
const runningQueue = []; | |
const MAX_PARALLEL_REQUESTS = 5; | |
function makeRequest(reqToMake) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* creating a cancelable promises allows you to ensure that callbacks will only be executed | |
* if the context is still appropriate for it. | |
* https://medium.com/trabe/avoid-updates-on-unmounted-react-components-2fbadab17ad2 | |
* | |
* useEffect(() => { | |
* const api = useCancellablePromises(); | |
* const fetchDataCancellablePromise = fetchData(); | |
* api.appendPendingPromise(fetchDataCancellablePromise); | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Async callback calls for array items | |
* https://codeburst.io/javascript-async-await-with-foreach-b6ba62bbf404 | |
* | |
* | |
* await asyncForEach(items, async (item) => { | |
* await someAsyncCallback(items) | |
* .catch((e) => { | |
* console.error(e); | |
* }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
.view { | |
fill: blue; | |
stroke: #000; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getNestedChildren = (flatArray, parent) => { | |
const nestedResult = []; | |
Object.values(flatArray).forEach((item) => { | |
if (item.parentId === parent) { | |
const children = getNestedChildren(flatArray, item.id); | |
if (children.length) { | |
/* eslint-disable-next-line no-param-reassign */ | |
item.children = children; | |
} | |
nestedResult.push(item); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flattenDeep = (items) => ( | |
items.reduce((acc, val) => { | |
if (val.children && val.children.length) { | |
acc.push(val); | |
return acc.concat(flattenDeep(val.children)); | |
} | |
return acc.concat(val); | |
}, []) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Fiddler4 settings for redirection with autoresponder | |
from regex:http://localhost:3000/api/(.*) | |
to https://targethost.com:4000/api/$1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getObjectDiff(obj1, obj2) { | |
const diff = Object.keys(obj1).reduce((result, key) => { | |
if (!obj2.hasOwnProperty(key)) { | |
result.push(key); | |
} else if (isEqual(obj1[key], obj2[key])) { | |
const resultKeyIndex = result.indexOf(key); | |
result.splice(resultKeyIndex, 1); | |
} | |
return result; | |
}, Object.keys(obj2)); |
NewerOlder