Skip to content

Instantly share code, notes, and snippets.

View Jabher's full-sized avatar

Vsevolod Rodionov Jabher

  • St. Petersburg, Russia
View GitHub Profile
import fs from 'fs';
import express from 'express';
import https from 'https';
import { createServer as createViteServer } from 'vite';
import createProxyMiddleware from 'http-proxy-middleware';
import ws from 'ws';
import { parse } from 'url';
const dataproxy = createProxyMiddleware('XXX', { changeOrigin: true });
import { Chunk, ParamType } from './pathParser'
import { last } from 'ramda'
const evalCache = Object.create(null)
const cachedEval = (fn: string): (path: string[]) => {} => {
if (!evalCache[fn]) {
/* see MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
* from the line "If you use the eval function indirectly..."
**/
const globalEval = eval
function router (method: string, path: string) {
const chunks = path.split('/')
let endpoints = compiledTrieMap
let children = endpoints.children
const chunksLength = chunks.length
let i = 0
while (true) {
const chunk = chunks[i]
if (children.has(chunk)) {
import { compileTrie } from './compileTrie'
import { Trie } from './Trie'
const makeTrie = (name: string, ...paths: string[]) => {
const trie = new Trie()
for (const key of paths) {
trie.mapValue(key.split('/'), () => `${name} ${key}`)
}
return trie
}
export class Node<Value> {
children: {
[key: string]: Node<Value>
} = {}
value?: Value
hasValue: boolean = false
setValue (value: Value) {
this.hasValue = true
@Jabher
Jabher / machine.js
Created October 8, 2019 11:24
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
const async_hooks = require('async_hooks');
const triggerMap = {};
const asyncId = async_hooks.executionAsyncId();
const triggerId = async_hooks.triggerAsyncId();
const envs = {};
global.env = undefined;
let lastResolvedPromiseAsyncId;
require('./magic');
function a() {
console.log(global.env.test)
}
Promise.resolve()
.then(async function () {
global.env.test = 'baz';
console.log('in async 1', global.env.test);
@Jabher
Jabher / affirmation
Created March 27, 2017 09:19
MuleSoft Contributor Agreement Acceptance by Vsevolod Rodionov
I, Vsevolod Rodionov, have read and do accept the MuleSoft Contributor Agreement
at http://www.mulesoft.org/legal/contributor-agreement.html
Accepted on Mon Mar 27 2017 12:19:20 GMT+0300 (+03)
var R = require('ramda');
void 0; //to not bloat the output
var random = require('seed-random')(1337);
var data = [
{input: [0, 0], output: 0},
{input: [1, 0], output: 1},
{input: [0, 1], output: 1},
{input: [1, 1], output: 0},
];
var activation_sigmoid = x => 1 / (1 + Math.exp(-x));