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
| function updateSpecificity(selector, currentSpecificity) { | |
| const newSpecificity = [...currentSpecificity]; | |
| if (isSelectorId(selector)) { | |
| newSpecificity[0] += 1; | |
| return newSpecificity; | |
| } | |
| if ( | |
| isSelectorClass(selector) || |
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
| function findScoreIndexOrClosest<T>( | |
| arr: [score: number, value: T][], | |
| score: number, | |
| ): [matched: boolean, index: number] { | |
| if (arr.length === 1) { | |
| return arr[0][0] === score | |
| ? [true, 0] | |
| : arr[0][0] > score | |
| ? [false, 0] | |
| : [false, 1]; |
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 { createHash, randomBytes } from "crypto"; | |
| interface INode<T = any> { | |
| id: number; | |
| data: Map<string, T>; | |
| hash: string; | |
| } | |
| interface IHashRing { | |
| nodes: INode<any>[]; |
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
| cat /dev/urandom | head -1 | shasum | awk '{print $1}' | cut -c 1-8 |
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
| function PriorityQueue() { | |
| this.collection = []; | |
| } | |
| PriorityQueue.prototype = { | |
| enqueue([item, priority]) { | |
| let indexToBePlacedAt = -1; | |
| for (let i = 0; i < this.collection.length; i++) { | |
| const [, itemPriority] = this.collection[i]; | |
| const isNewItemHigherPriority = priority < itemPriority; |
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
| function createAppContainer() { | |
| const bindingsMap = new Map(); | |
| const appContainer = { | |
| bind(abstractClass, concreteClassOrFn) { | |
| bindingsMap.set(abstractClass, concreteClassOrFn); | |
| }, | |
| make(ClassToCreate, ...constructorArgs) { | |
| const argTypes = ClassToCreate.argTypes || []; |
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
| '''Cache class for LRU''' | |
| KEY_NOT_EXIST_VALUE = 'key-not-exist' | |
| class LRUCache: | |
| ''' | |
| Least recently used cache | |
| ''' |
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 EventEmitter from 'events'; | |
| import { Worker } from 'worker_threads'; | |
| class CustomWorker extends Worker { | |
| public isReady: boolean; | |
| constructor(...args: ConstructorParameters<typeof Worker>) { | |
| super(...args); | |
| this.isReady = true; | |
| } |
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
| // Old school classic inheritence | |
| function Shape(name) { | |
| this.name = name; | |
| } | |
| Shape.prototype.getName = function() { | |
| return this.name; | |
| } |
NewerOlder