Skip to content

Instantly share code, notes, and snippets.

View cards-9-gap.nde
UNIT=MM
BORDER=NONE,#000000,0,MARKDOT,#000000
GAP=5,5,ON
PAGE=210,297,PORTRAIT,HV
DPI=300
CARDSIZE=63,88
LINK=cards.xls,image
IMAGE=,[IMAGE],0,0,100%,100%,0,PTA
View cards-pocket-gutterfold.nde
UNIT=MM
BORDER=NONE,#000000,0,MARKDOT,#000000
GAP=10,10,ON
PAGE=210,297,PORTRAIT,HV
DPI=300
CARDSIZE=40,55
LINK=cards.xls,image
IMAGE=,[IMAGE],0,0,100%,100%,0,PTA
@naholyr
naholyr / prerequisites-react.md
Created Feb 28, 2020
Prerequisites for React.js express training
View prerequisites-react.md

React.js training prerequisites

View ProductList.js
const category = useSelector(state => state.app.currentCategory);
const asyncFunction = React.useCallback(
category ? () => getProducts(category) : null,
[category]
);
const [error, loading, products] = useAsync(asyncFunction, category);
View 00-context.jsx
import * as React from 'react';
// TODO inject counters
const Counter = () => {
const [value, setValue] = React.useState(1);
const incr = React.useCallback(() => setValue(value + 1), [value]);
return (
<button type="button" onClick={incr}>
Click to incr. ({value})
View run.js
const { promisify } = require('util')
const delay = promisify(setTimeout)
const pad = (s, len = 4) => s.length >= len ? s : pad(`0${s}`, len)
// 300 tasks (id for log, run for action)
const tasks = []
for (let i = 0; i < 300; i++) {
const id = String(i)
const run = () => delay(2000 + Math.random() * 8000)
tasks.push({ id, run })
View test.jsx
import React, { Fragment, Component } from 'react';
import ReactDOM from 'react-dom';
class ContextData {
watchers = []
constructor(initialState = {}) {
this.state = initialState
View README.md

scan-dependencies

Usage : node scan-dependencies.js <path>

  • will find every root project inside <path> (a project is a folder with package.json file, himself not inside a node_modules directory)
  • will npm install then npm outdated from project
  • will list all *.js files and check for missing require(…) for every dependency
View README.md

Shitty code, version 1:

const concat = s => s.reduce((r,s) => r + s)
const mult = (a, b) => a * b
const foo = a => b => c => concat([c, ' = ', mult(a, b)])
const bar = a => Number(a) + 1
const baz = b => b ? 42 : 33
const res = foo(1)('bar')('baz')
console.log(res)
@naholyr
naholyr / promise-all.js
Last active Sep 8, 2016
Run promise-based async API in series or concurrency
View promise-all.js
// ( T1 => Promise<T2> ) => Array<T1> => Promise<Array<T2>>
export const concurrent = foo => vals =>
Promise.all(vals.map(foo))
export const series = foo => vals =>
vals.reduce((p, val) => p.then(rs => foo(val).then(r => rs.concat([val]))), Promise.resolve([]))
// Usage: promiseOfValues.then(promiseAll.concurrent(functionReturningAPromiseFromAValue))
You can’t perform that action at this time.