Skip to content

Instantly share code, notes, and snippets.

import { ethers } from 'hardhat';
import fs from 'fs';
import path from 'path';
async function main() {
const envArgs = process.env.SCRIPT_ARGS
? process.env.SCRIPT_ARGS.split(' ')
: [];
const [contractName, ...args] = envArgs;
const contractsDir = path.join(__dirname, '..', 'contracts');
@gdekefir
gdekefir / session-history.js
Last active January 26, 2018 04:25
Using jest-json-schema
const moment = require('moment');
const { URL_SESSION_HISTORY } = require('../../src/constants/urls');
const { STATUS_OK } = require('../../src/constants/used-http-status-codes');
const mocker = require('../../dev-helpers/testing/mocker');
const handler = mocker((req, res) =>
res.status(STATUS_OK).send({
sessions: [
{
@gdekefir
gdekefir / compose-maybe-with-default.js
Last active September 29, 2017 12:19
Returns a value of Maybe object after applying set of transformers
const R = require('ramda');
const composeMaybe = require('./compose-maybe').composeMaybe;
/**
* Returns a value of Maybe object after applying set of transformers
* default → [(y → z), (x → y), …, (o → p), ((a, b, …, n) → o)] → ((a, b, …, n) → z | default)
*/
const composeMaybeWithDefault = R.curry((defaultVal, transformers) =>
R.memoize(R.o(R.invoker(1, 'withDefault')(defaultVal), composeMaybe(...transformers)))
@gdekefir
gdekefir / webpack.config.js
Created August 17, 2017 22:48
webpack.config.js with multiple chunks
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const RollbarSourceMapPlugin = require('rollbar-sourcemap-webpack-plugin');
const envVarStubs = require('./package.json').appSettings.envVarStubs;
const envVars = process.env;
const isProd = process.argv.includes('-p');
@gdekefir
gdekefir / new_gist_file.js
Last active August 5, 2017 20:31
small ramda helpers
const argsToArray = unapply(identity);
argsToArray(1, 3, 5); //-> [1, 3, 5]
////////////////////////////////////////////////////////////////
const dropArgs = curryN(2, compose(
apply(drop),
splitAt(1),
const getProm = val => new Promise(resolve => resolve(val));
composeP(inc, getProm)(5).then(res => console.log(res)) //-> Promise 6
@gdekefir
gdekefir / fantasy-birds_and_ramda.js
Created August 2, 2017 20:41
Getting prop value via ramda and fantasy-birds
//const fn = obj => key => key => propOr(key, key, obj);
const fn = warblerstar(robinstar(propOr));
const src = {
some: 22,
other: 33
};
fn(src, 'some'); //-> 22
fn(src, 'qqq'); //-> 'qqq'
@gdekefir
gdekefir / ramda.js
Created August 1, 2017 23:00
Problem: Do any of these strings appear in another list? (point-free style)
// var overlaps = (spec, list) => !!find(contains(__, list), spec);
var overlaps = useWith(compose(Boolean, call), [flip(find), flip(contains)]);
var list = ['node', 'script.js', '-v']
overlaps(['-v', '--verbose'], list) //-> true
@gdekefir
gdekefir / new_gist_file.js
Created August 1, 2017 22:59
Problem: Do any of these strings appear in another list? (point-free style)
// var overlaps = (spec, list) => !!find(contains(__, list), spec);
var overlaps = useWith(compose(Boolean, call), [flip(find), flip(contains)]);
var list = ['node', 'script.js', '-v']
overlaps(['-v', '--verbose'], list) //-> true
@gdekefir
gdekefir / ramda.js
Last active July 31, 2017 21:25
Transform all keys
var mapKeys = useWith(compose(fromPairs, call), [o(map, adjust(__, 0)), toPairs])
mapKeys(R.toUpper, { a: 1, b: 2, c: 3 }); //=> {"A": 1, "B": 2, "C": 3}