Skip to content

Instantly share code, notes, and snippets.

View batrudinych's full-sized avatar

batrudinych batrudinych

View GitHub Profile
@batrudinych
batrudinych / [parallel-promises]-take3-subtake1-part1.js
Created January 14, 2019 10:58
Running async operations in parallel and harvesting the results. Concurrency limit applied correctly
async function take3subtake1part1() {
const concurrencyLimit = 5;
// Enhance arguments array to have an index of the argument at hand
const argsCopy = [].concat(listOfArguments.map((val, ind) => ({ val, ind })));
const result = new Array(listOfArguments.length);
const promises = new Array(concurrencyLimit).fill(Promise.resolve());
// Recursively chain the next Promise to the currently executed Promise
function chainNext(p) {
if (argsCopy.length) {
const arg = argsCopy.shift();
@batrudinych
batrudinych / send-blob.js
Created March 10, 2019 14:28
Send a blob (which may be a file) from client app
// Blob may contain something else, check https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#Syntax
// Keep in mind this requires preflight
const blob = new Blob(['this is a test'], { type: 'application/x-www-form-urlencoded'})
const xhr = new XMLHttpRequest();
xhr.open("POST", 'http://localhost:8080/files', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
@batrudinych
batrudinych / eosjs-tx-signing-example.js
Last active December 10, 2020 09:27
sign transaction with eosjs (signle and double authorization)
// npm i eosjs node-fetch
// node eosjs-tx-singing-example.js
'use strict'
const { Api, JsonRpc } = require('eosjs')
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig')
const fetch = require('node-fetch')
const { TextDecoder, TextEncoder } = require('util')
const privateKeys = ['_INSERT_PRIVATE_KEY_']