Skip to content

Instantly share code, notes, and snippets.

Hacking fast and slow.

Anton Vynogradenko Restuta

Hacking fast and slow.
View GitHub Profile
View tourist-code.cpp
* author: tourist
* created: 08.08.2020 17:11:40
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class graph {
Restuta / modified-z-score.js
Last active Nov 22, 2020
Outliers: z-score and modified z-score method in JavaScript
View modified-z-score.js
// z-score
const { mean, deviation } = require('d3-array')
const zscore = input => {
const arrMean = mean(input)
// here the n-1 :
const arrDeviation = deviation(input)
return => ({
zscore: (i - arrMean) / arrDeviation,
item: i,
Restuta /
Last active Sep 25, 2020
GitHub Badges test via Shields

Base PRs


Stacked on top of this PR



Restuta / tranducers-experiments.js
Created Aug 13, 2020
Tranducers and mergeWith experiments
View tranducers-experiments.js
const R = require('ramda')
const numbers = [1, 2, 8, 9]
const transducer = R.compose(
R.filter(x => {
console.log('filter', x)
return x > 3
}), => {
Restuta / neat-stack.js
Last active Mar 12, 2020
View neat-stack.js
import cleanStack from 'clean-stack';
// dims non-useful log lines in stack traces
const neatStack = (colorize, stack) => {
// add parts of stack trace lines here that should be ignored
const regexParts = [
Restuta /
Created Jan 21, 2020
How to get IP Ranges for Heroku

Ip Ranges

Sometimes it's useful to know what IP ranges our servers are operating in. Since we run on Heroku, it's a little complicated. However, Heroku runs on AWS, which has this page dedicated to IP Ranges by Region.

Heroku recommends using this to identify which region are bing in use. If dynos are run in common spaces in US region, we can look up information about this region using Heroku's API:

using httpie:

 http "Accept:application/vnd.heroku+json; version=3"
View logger.js
const util = require('util');
const R = require('ramda');
const chalk = require('chalk');
const jsondiffpatch = require('jsondiffpatch');
const toJson = require('./to-json');
let prefix;
let coloredOutput = false;
Restuta / ora-progress-bar.js
Last active Nov 8, 2019
Ora based progress bar
View ora-progress-bar.js
/* eslint-disable no-return-assign */
const chalk = require('chalk');
const ora = require('ora');
const prettyMs = require('pretty-ms');
const throttle = require('lodash/throttle');
const getHeapUsed = throttle(
() => {
const heapUsed = process.memoryUsage().heapUsed / 1024 / 1024;
return Math.round(heapUsed, 2);
Restuta / audit-log-design-problem.js
Last active Jan 25, 2019
Audit Log Collection Design Problem
View audit-log-design-problem.js
We have a function that updates objects and generates audit records of the changes.
Think about financial systems or just any app where it's useful to know who made changes to what.
Audit records needs to be saved to the DB as well as updates to objects, but ideally
we would want to execute business logic, accumulate all updates and audit records in memory
and then save it to DB all at once. Let's look at the specifics.
Restuta / with-audit-log.js
Created Jan 15, 2019
With Audit Log (proto)
View with-audit-log.js
/* tl;dr of the problem
- We have a funtion that updates objects and produces two values [updates, auditLogRecord].
Let's call it "applyChangesWithAuditLog"
- We need to use this function in the context of another function (let's call it "update") and that another function should not be
aware of the fact that that auditLogRecord's are being produced and collected.
- When function "update" is executed, we want to collect all auditLogRecords that originated from calls
to "applyChangesWithAuditLog" inside "update" function.
- Then we want to save all collected auditLog items to DB.
Code below achieves this by building a functional wrapper.