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 HR = ` | |
# sintaksa: regularni_izraz [dio_za_dodat] | |
# prva grupa u regularnom izrazu je i dio koji se brise | |
PFX (je|ni|ne|ho|naj|pra|is) | |
PFX (ne) i | |
SFX (i|mo|te|u) am |
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
/** @param {number} n */ | |
function semaphore (n) { | |
const resolvers = [] | |
const pushToResolvers = resolve => { resolvers.push(resolve) } | |
/** @type {() => (Promise<void> | void)} */ | |
const acquire = () => { | |
if (--n < 0) { |
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 { useEffect, useLayoutEffect, useRef, useState } from 'react' | |
function shallowEqualArrays(a, b) { | |
if (a.length !== b.length) { | |
return false | |
} | |
for (let i = 0; i < a.length; ++i) { | |
if (a[i] !== b[i]) { | |
return false |
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 isNotExpired = x => x && x.exp >= Date.now() | |
export function resourceCache (get, isValid = isNotExpired, initialData = undefined) { | |
let data = initialData | |
let pending = null | |
return async () => { | |
if (pending) return pending | |
if (!isValid(data)) { |
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
'use strict' | |
/// Circular double-linked list | |
class Node { | |
constructor () { | |
this.key = null | |
this.val = null | |
this.prev = this | |
this.next = 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
const identity = x => x | |
/** | |
* Creates a predicate function to check if a value is not seen before | |
* | |
* @param {function} [by = x=>x] | |
* @returns {function} predicate function | |
* | |
* @example | |
* |
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
'use strict' | |
const objToStringMethod = Object.prototype.toString | |
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g | |
const reUnescapedSpaces = /(?<!\\)\s+/g | |
const reHasSpace = /\s/ | |
const compact = raw => reHasSpace.test(raw) ? raw.replace(reUnescapedSpaces, '') : raw | |
const escape = val => String(val).replace(reRegExpChar, '\\$&') |
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 timeout (ms, x) { | |
return new Promise((resolve, reject) => { | |
let timeoutId = setTimeout(() => { | |
timeoutId = null | |
reject('timeout') | |
}, ms) | |
const onSettle = () => { | |
if (timeoutId != null) { | |
clearTimeout(timeoutId) |
NewerOlder