Skip to content

Instantly share code, notes, and snippets.

Avatar
🦄
Hacking fast and slow.

Anton Vynogradenko Restuta

🦄
Hacking fast and slow.
View GitHub Profile
@Restuta
Restuta / readme.md
Last active Sep 25, 2020
GitHub Badges test via Shields
View readme.md

Base PRs

#20

Stacked on top of this PR

#23

#24

@Restuta
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
}),
R.map(x => {
@Restuta
Restuta / neat-stack.js
Last active Mar 12, 2020
neat-stack.js
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 = [
'(node_modules)',
'(WEBPACK_IMPORTED)',
'(next_tick.js)',
'(domain.js)',
@Restuta
Restuta / README.md
Created Jan 21, 2020
How to get IP Ranges for Heroku
View README.md

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 https://api.heroku.com/regions/us "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
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
Restuta / audit-log-design-problem.js
Last active Jan 25, 2019
Audit Log Collection Design Problem
View audit-log-design-problem.js
/*
Problem
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
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.
View app-flow-proto-2.js
// step module
const applyUpdates = () => {};
const updateStepBody = useDb => (stepBody, updates) => {
const updatedBody = applyUpdates(stepBody, updates);
useDb(transaction => {
createHistoryRecord(updatedBody, updates);
});
@Restuta
Restuta / with-audit-log.js
Last active Jan 15, 2019
With Audit Log prototype
View with-audit-log.js
// original version with binding to module instance
const { createAuditLogRecords } = require('../commands');
const getStepFactory = require('./get-factory-by-type');
const { createStep, updateStep } = require('./commands');
const applyStepUpdates = require('./apply-step-updates');
const createContainer = (items = []) => ({
getAll: () => items,
You can’t perform that action at this time.