Skip to content

Instantly share code, notes, and snippets.

View wentout's full-sized avatar
😎
building teleport

wentout wentout

😎
building teleport
View GitHub Profile
@wentout
wentout / createReflectedDiscriminator.js
Last active February 6, 2018 21:52
Attempt to change Mongoose.js Discriminator Value tied mapping leaving Discriminator Name untouched
// https://github.com/Automattic/mongoose/issues/2596
// 1. It was necessary for me to to fit our naming style to this behaviour.
// 2. And moreover, move to Mongoose 5
// 3. And leave all data untouched, I mean, no changes, at all, a lot of production running data.
/**
* Discriminator Reflected mapping
* to discriminator value,
* used inside of existent db
* @param {object} baseModel : parent model used for discriminator creation
@wentout
wentout / isSoftwareDeveloperDay.js
Last active September 13, 2018 09:27
Software Developer Day Holiday Check
global.isSoftwareDeveloperDay = function () {
const DEVELOPER_DAY =
Math.pow(2, 8);
const UNIX_EPOCH_BEGIN = 864e5;
const timestmp = new Date()
.setFullYear(
(new Date())
@wentout
wentout / CLS_Function_Wrapper.js
Last active November 8, 2018 19:58
CLS implementation using wrapped function. Polling problem shown from line 111.
'use strict';
// HOOKS EXAMPLE START
var counter = 0;
var currentId = 0;
var hooks = {
init: [],
before: [],
@wentout
wentout / AsyncStorageMixContextTest.js
Last active December 15, 2019 06:55
Some thoughts about async storage context for PR 26540
"use strict";
const common = require("../common");
const assert = require("assert");
const { AsyncContext } = require("async_hooks");
const asyncContext = new AsyncContext();
const tasks = [];
asyncContext.enter(store => {
@wentout
wentout / InheritanceMap.js
Last active August 29, 2019 07:05
Inheritance Map Example
'use strict';
// Inheritance Map Example
const assert = require('assert');
const { strictEqual, deepStrictEqual } = assert;
const util = require('util');
const inspect = (value) => {
return util.inspect(value, {
colors : true,
var Pollen = { season : 'Spring' };
// factory of constructors
var FlowersFactory = function (proto) {
var FlowerEggCell = function (sort) {
this.sort = sort;
};
FlowerEggCell.prototype = proto;
return FlowerEggCell;
};
var FlowerZygote = FlowersFactory(Pollen);
@wentout
wentout / cls-hooked-test.js
Created October 19, 2019 19:53
cls-hooked test
var createNamespace = require('cls-hooked').createNamespace;
const fn = () => {
var getNamespace = require('cls-hooked').getNamespace;
var session = getNamespace('my session');
var user = session.get('user');
process._rawDebug(user);
@wentout
wentout / Zone.js
Created October 19, 2019 20:30 — forked from devsnek/Zone.js
'use strict';
const {
AsyncResource,
executionAsyncId,
createHook,
} = require('async_hooks');
const EventEmitter = require('events');
const util = require('util');
@wentout
wentout / Y-Combinator-this-Question-Async-Await.js
Last active January 13, 2020 11:57
Example of Real Question you should ask your engineer if there is something about Y-Combinator work to be done...
const log = function (message, s) {
process.stdout.write(`${String(message).padEnd(17)} : ${s || ''}\n`);
};
const YCombinator = async function (realWork) {
log('start', this);
return await (async function (cb_x) {
log('inside', this);
return await cb_x.call(this, cb_x);
}).call(this, async function (cb_y) {
// just 4 fun & lools
class StringBoolean extends String {
static get [Symbol.species] () {
return Boolean;
}
get [Symbol.toStringTag] () {
return 'StringBoolean';
}
get [Symbol.toString] () {