Skip to content

Instantly share code, notes, and snippets.

@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')
});

Set up git editor

The main command is:

git config --global core.editor "path to your editor with params"

Set up an editor and check it by making a commit:

@andrIvash
andrIvash / dark-theme.css
Created September 3, 2019 08:29
base styles for dark theme
:root {
background-color: #fefefe;
filter: invert(100%);
}
* {
background-color: inherit;
}
img:not([src*=".svg"]), video {
filter: invert(100%);
}
@andrIvash
andrIvash / parallel_promises.js
Last active August 5, 2019 11:40
Limit number of promises running in parallel
// example lib https://github.com/charto/cwait
// https://krasimirtsonev.com/blog/article/implementing-an-async-queue-in-23-lines-of-code
function createQueue(tasks, maxNumOfWorkers = 4) {
let numOfWorkers = 0;
let taskIndex = 0;
const resultData = [];
return new Promise(done => {
const handleResult = index => result => {
@andrIvash
andrIvash / savef_pdf.js
Created July 10, 2019 19:09
save pdf with axios
axios(`${apiURL}/pdf`, {
method: 'GET',
responseType: 'blob' //Force to receive data in a Blob Format
})
.then(response => {
//Create a Blob from the PDF Stream
const file = new Blob(
[response.data],
{type: 'application/pdf'});
//Build a URL from the file
@andrIvash
andrIvash / escapeHtml.js
Created June 25, 2019 14:45
escape Html chars
function escapeHtml(text) {
var map = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
@andrIvash
andrIvash / Auth.js
Created June 21, 2019 11:23
Auth class for api call with jwt-token logic
import decode from 'jwt-decode';
import {
API_BASE_URL,
ACCESS_TOKEN,
REFRESH_TOKEN,
ACTIVE_USER } from '../../helpers/constants.js';
/**
* Authentification service.
* Performs api calls sending the required authentication headers.
@andrIvash
andrIvash / getFiniteValue.js
Last active February 27, 2019 19:49
getFiniteValue of nested objects with recursion and circular reference logging
// node.js version
var util = require('util');
var fractal = {
a1: {
b1: {
c: 1
},
b2: {
c: 222
@andrIvash
andrIvash / linkedList.js
Created February 26, 2019 19:31
linkedList
const linkedList = {
toc: {
children: [
{id: '1-1', val: '1-1', children: []},
{
id: '1-2',
val: '1-2',
children: [
{id: '2-1', val: '2-1', children: []},
{id: '2-2', val: '2-2', children: []},
@andrIvash
andrIvash / multi.js
Created February 8, 2019 12:47
Like multithreading Node
const crypto = require('crypto')
const arr = new Array(200).fill('something')
function processChunk() {
if (arr.length === 0) {
// code that runs after the whole array is executed
} else {
console.log('processing chunk');
// pick 10 items and remove them from the array
const subarr = arr.splice(0, 10)