This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const binarySearch = ( | |
array: number[], | |
element: number, | |
range: [left: number, right: number] = [0, array.length - 1], | |
): number => { | |
let left = range[0]; | |
let right = range[1]; | |
let halfIndex = -1; | |
while (left < right) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Selector = { | |
}; | |
interface CaseLine<T, G> { | |
condition(value: T): boolean; | |
body(value: T): void | G; | |
} | |
interface Switcher<T, G> { | |
case(caseLine: CaseLine<T, G>): this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final selector = Selector(); | |
selector | |
.when((value) => value == 3).then((value) => value * 2) | |
.whenIsEqual((value) => value == 'QQQ').then((value) { print(value); return null; }) | |
.fallback((value) => { 'x': 42 }); | |
final selector2 = Selector<int, int>(); | |
selector2 | |
.when((value) => value == 3).then((value) => value * 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Listener<TContext> = (context: TContext) => Promise<void> | void; | |
export type MatcherFn<TEvent extends string> = (event: TEvent) => TEvent | null; | |
export class Matcher< | |
TEvent extends string, TAdditionalEvent extends string = 'DEFAULT', TContext = any, | |
> { | |
private _listeners: Map<TEvent | TAdditionalEvent, Listener<TContext>[]> = new Map(); | |
private _customMatchers: MatcherFn<TEvent | TAdditionalEvent>[] = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Transform } = require('stream'); | |
const sliceBySize = (buffer, size, callback) => { | |
let chunk = buffer.slice(0, size); | |
let index = size; | |
while (chunk.length >= size) { | |
callback(chunk); | |
chunk = buffer.slice(index, index + size); | |
index += size; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IterableHash<G extends string | number, T> { | |
[key: string]: T; | |
[key: number]: T; | |
// @ts-ignore | |
private primaryKeyIndex: G[] = []; | |
// @ts-ignore | |
private data: Record<G, T | void> = {}; | |
// @ts-ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isSupportSymbol = (symbolCode) => symbolCode === 55356 || (symbolCode >= 768 && symbolCode <= 879); | |
const reverse = (str) => { | |
let res = ''; | |
let prevSymbol = null; | |
for (const symbol of str) { | |
if (isSupportSymbol(symbol.charCodeAt())) { | |
res = `${prevSymbol}${symbol}${res}`; | |
prevSymbol = null; | |
} else if (prevSymbol == null) { | |
prevSymbol = symbol; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const relation = (ModelClass, deserialize, serialize) => { | |
return (target, key, descriptor) => { | |
const proto = Reflect.getPrototypeOf(target); | |
if (!target.hasOwnProperty(Symbol.for('#meta'))) { | |
if (proto.hasOwnProperty(Symbol.for('#meta'))) { | |
Reflect.defineProperty(target, Symbol.for('#meta'), {value: {...proto[Symbol.for('#meta')]}}); | |
} else { | |
Reflect.defineProperty(target, Symbol.for('#meta'), {value: {}}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
componentName: 'rd-block', | |
mods: null, | |
classNameBindings: ['componentName', 'modClassNames'], | |
modClassNames: Ember.computed('componentName', 'mods', 'mods.[]', { | |
get() { | |
let componentName = this.get('componentName'); | |
let mods = this.get('mods') || []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
attributeBindings: 'style'.w(), | |
init() { | |
this._super(...arguments); | |
Ember.run.later(this, () => { | |
this.set('isVisible', true); | |
}, 5000); |
NewerOlder