Skip to content

Instantly share code, notes, and snippets.

View b2whats's full-sized avatar
🎯
Focusing

Akimov Vladimir b2whats

🎯
Focusing
View GitHub Profile
@b2whats
b2whats / fluent_mapper_builder_gist.ts
Created May 4, 2022 02:54 — forked from JSuder-xx/fluent_mapper_builder_gist.ts
Explicitly declare modifications to an existing object type via a fluent interface which yields a mapping function to the derived type. Demonstration of TypeScript meta-programming through mapped and conditional types.
/**
* _Explicitly declare modifications_ to an existing object type via a fluent interface which yields a mapping function
* from the original data type to the type derived from the modification commands.
*
* The value over authoring a simple mapping function directly
* * harder to make a mistake due to the explicit nature
* * easier to read.
*
* This is _not_ production quality code but rather a _proof of concept_ gist for applying conditional/mapped
* types to mapper generation. A real-world usage might involve also generating the type-guard function
@b2whats
b2whats / constrained_fluent_builder.ts
Created May 4, 2022 02:54 — forked from JSuder-xx/constrained_fluent_builder.ts
Fluent Builder Type API which transforms any arbitrary fluent builder type into a fluent builder type enforcing call count dependencies between methods (where dependencies are represented as a type). Employs Mapped, Conditional, and Literal Types to demonstrate both TypeScript's proximity to dependent typing and the practical value.
/**
* Imagine a Fluent Builder where some subset of the fluent methods are valid to call
* * after one or more fluent methods have been called
* * before one or more fluent methods have been called
* * limited number of times.
*
* There is no way to enforce such constraints in statically typed languages such as C++, C# or Java when using a single builder
* class/interface. Developers would need to author many interfaces to represent the different shapes and would likely need to
* author many versions of the builder itself (proxies with a specific signature delegating to an underlying source builder).
*
@b2whats
b2whats / MutateRuntimePlugin.js
Created February 9, 2021 21:45 — forked from yordis/MutateRuntimePlugin.js
Remote PublicPath Modification
const PLUGIN_NAME = "MutateRuntimePlugin";
class MutateRuntimePlugin {
/**
*
* @param {FederationDashboardPluginOptions} options
*/
constructor(options) {}
/**
@b2whats
b2whats / index.html
Last active April 15, 2020 17:16 — forked from JobLeonard/index.html
join vs concat when dealing with very long lists of single-character strings (http://jsbench.github.io/#c9813d523fd015e61472b9258703e6ef) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>join vs concat when dealing with very long lists of single-character strings</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@b2whats
b2whats / Infrastructure.js
Created March 12, 2019 12:54 — forked from sebmarkbage/Infrastructure.js
SynchronousAsync.js
let cache = new Map();
let pending = new Map();
function fetchTextSync(url) {
if (cache.has(url)) {
return cache.get(url);
}
if (pending.has(url)) {
throw pending.get(url);
}
@b2whats
b2whats / index.html
Created July 9, 2018 13:16 — forked from RubaXa/index.html
(key in object) vs. (object[key] !== void 0) vs. object.hasOwnProperty(key) (http://jsbench.github.io/#1aebf699d73fb743127903c0b0a8bece) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>(key in object) vs. (object[key] !== void 0) vs. object.hasOwnProperty(key)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
{ __esModule: true,
is: [function is(type /*: string*/, node /*: Object*/, opts /*:: ?: Object*/, skipAliasCheck /*:: ?: boolean*/) /*: boolean*/ ],
isType: [function isType(nodeType /*: string*/, targetType /*: string*/) /*: boolean*/ ],
validate: [function validate(node, key, val) ],
shallowEqual: [function shallowEqual(actual /*: Object*/, expected /*: Object*/) /*: boolean*/ ],
appendToMemberExpression: [function appendToMemberExpression(member /*: Object*/, append /*: Object*/, computed /*:: ?: boolean*/) /*: Object*/ ],
prependToMemberExpression: [function prependToMemberExpression(member /*: Object*/, prepend /*: Object*/) /*: Object*/ ],
ensureBlock: [function ensureBlock(node /*: Object*/) ],
clone: [function clone(node /*: Object*/) /*: Object*/ ],
cloneDeep: [function cloneDeep(node /*: Object*/) /*: Object*/ ],
@b2whats
b2whats / index.html
Last active August 15, 2017 14:38 — forked from RubaXa/index.html
String#includes vs. String#indexOf vs. RegExp (http://jsbench.github.io/#e9d85ace4fc1febe3744e39d2a2269db) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>String#includes vs. String#indexOf vs. RegExp</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@b2whats
b2whats / duck-on-wheels.js
Created December 28, 2016 22:05 — forked from nickbalestra/duck-on-wheels.js
An example of Duck Redux Reducer Bundle with Cycle.js apps to handle async
import xs from 'xstream'
import { combineCycles } from 'redux-cycle-middleware'
import { push } from 'react-router-redux'
import { API_URL } from '../constants/api'
// ACTION TYPES (Format: app-name/reducer/ACTION_TYPE)
// =======================================================
const LOGIN = 'app-name/auth/LOGIN'
const LOGIN_SUCCESS = 'app-name/auth/LOGIN_SUCCESS'
const LOGIN_FAIL = 'app-name/auth/LOGIN_FAIL'
@b2whats
b2whats / rxjs_operators_by_example.md
Created October 25, 2016 21:59 — forked from btroncone/rxjs_operators_by_example.md
RxJS 5 Operators By Example