Skip to content

Instantly share code, notes, and snippets.

View doasync's full-sized avatar
🙂

Ruslan @doasync doasync

🙂
View GitHub Profile
@doasync
doasync / gulpfile.symlink.js
Last active June 20, 2017 09:41
Relative symbolic links to folders in gulp with vinyl-fs
@doasync
doasync / mongoose.min.js
Created June 20, 2017 14:24
Browserify mongoose js version for browser from 'node_modules' npm package
var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
gulp.task('mongoose', function() {
return browserify('./node_modules/mongoose/lib/browser.js')
.bundle()
@doasync
doasync / util.js
Created August 5, 2017 13:25
ES6 utils for arrays and objects
function collapse (arr) {
return [...new Set(arr)];
}
function isIterable(obj) {
return obj != null && typeof obj[Symbol.iterator] === 'function';
}
function collapseAll (...args) {
const all = args.reduce((arr, arg) => {
@doasync
doasync / pino.js
Last active June 2, 2023 21:57
Pino logger: log prettyfied messages to console + log to separate files WARN, ERROR, FATAL (pino-tee module in child process)
const pino = require('pino');
const childProcess = require('child_process');
const stream = require('stream');
// Environment variables
const cwd = process.cwd();
const {env} = process;
const logPath = `${cwd}/log`;
@doasync
doasync / README.md
Created September 22, 2017 12:01
ES6 classes without a class keyword but with class variable

noclass

Here is an example of ES6 classes without a class keyword but with class variables. Looks the same as classes and has the same structure internally.

Example

// class
var Foo = {
  classVariable: true,
@doasync
doasync / README.md
Last active January 31, 2019 01:12
Why effector?

☄️ Why do you need Effector?

Effector is reactive state manager. It is decentralized, declarative and efficienct.

Effector was created to manage data in complex applications without danger of inflating a monolithic central store. It provides events/effects and reactive storages. It has explicit control flow, Flow and TypeScript type definitions and sufficient API

Here are some principles:

  • application store should be as light as possible - you should not be frightened by the idea that you need to add another store for specific needs
@doasync
doasync / README.md
Last active March 6, 2019 17:08
createStoreMap & createMapper for working with lists and collections in effector

Usage of createStoreMap

Create $todos store (with an array) using createStore. Then create a $todoList store using createStoreMap.

There will be a map inside of $todoList store. Define map keys with getKey function and values with createValue function. A value object should contain a store inside which will represent an item of your $todos array. Provide this store with a getStore function.

As a result, $todoList will contain a map of value-objects (by keys). Each object will contain an item-store (with an item of a mapped array)

You can filter, map, concat or do anything you want with items of an array inside $todos.

@doasync
doasync / group-events.js
Last active March 1, 2019 17:27
Effector: group events
const groupEvents = events => {
for (const fromEvent of events) {
const eventCreate = fromEvent.create;
fromEvent.create = (data, fullName, args) => {
const [meta = {}] = args;
if (meta !== null && !meta.single) {
for (const toEvent of events) {
if (toEvent !== fromEvent) {
toEvent(data, { single: true });
@doasync
doasync / __example.js
Last active March 15, 2019 02:08
Flow 0.92.1: CustomEvent type with addEventListener (put dom.js to flow-typed folder)
// @flow
const myEvent = new CustomEvent<{ body: string }>('eventType', {
detail: { body: 'Specific Text' },
});
const myEventHandler = (event: typeof myEvent) => {
if (event.detail.body === 'Specific Text') {
// perform a certain action
}
@doasync
doasync / perf.js
Last active April 8, 2019 17:51
Browser or Node.js JavaScript performance test (jsperf): for..in vs for + Object.keys vs for..of + Object.keys vs for..of + Object.entries
// Run each test in the new tab
const { performance, PerformanceObserver } = typeof window !== 'undefined' ? window : require('perf_hooks');
function test() {
let objectSize = 30;
let iterations = 7000;
const values = {
'ENTRIES': 0,
'FOR-OF-KEYS': 0,