Skip to content

Instantly share code, notes, and snippets.

@andrIvash
andrIvash / telecoin.pine
Last active January 25, 2024 14:34
telecoin
//@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
@andrIvash
andrIvash / requestsManager.js
Created April 20, 2022 08:43
schedules running HTTP requests
/**
* @module
* @description It schedules running HTTP requests
*/
export const requestsManager = (function() {
const waitingQueue = [];
const runningQueue = [];
const MAX_PARALLEL_REQUESTS = 5;
function makeRequest(reqToMake) {
@andrIvash
andrIvash / useCancellablePromises.js
Created February 19, 2021 14:08
creating a cancelable promises
/**
* 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);
*
@andrIvash
andrIvash / asyncForEach
Created February 19, 2021 11:19
Async callback calls for array items
/**
* 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);
* });
@andrIvash
andrIvash / index.html
Created October 6, 2020 19:04 — forked from tomeustace/index.html
d3 v4 translateBy, scaleBy and scaleTo example usage
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.view {
fill: blue;
stroke: #000;
}
</style>
@andrIvash
andrIvash / getNestedChildren.js
Created December 17, 2019 07:43
from flat nested array to tree
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);
@andrIvash
andrIvash / flattenDeep.js
Created December 17, 2019 07:42
tree to flat array
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);
}, [])
);
@andrIvash
andrIvash / settings.txt
Created December 6, 2019 06:23
Fiddler4 settings for redirection with autoresponder
//Fiddler4 settings for redirection with autoresponder
from regex:http://localhost:3000/api/(.*)
to https://targethost.com:4000/api/$1
@andrIvash
andrIvash / getObjectDiff.js
Created November 22, 2019 07:37
get and show diff between object
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));
@andrIvash
andrIvash / cypress_command_to_check_react_input.js
Created October 17, 2019 16:57
Small gist for cypress to check react input text
// https://github.com/cypress-io/cypress/issues/566
// https://github.com/cypress-io/cypress/issues/534
// in your commands file:
Cypress.Commands.add('fill', {
prevSubject: 'element'
}, (subject, value) => {
cy.wrap(subject).invoke('val', value).trigger('input').trigger('change')
});