This file contains 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
// The most perfomance way to populate a new array | |
[...Array(1000)].map((_, i) => i); // [0,...,999] | |
// Grouping array elements by condition | |
function groupBy(list, groupingCondition) { | |
const groups = []; | |
let currentGroup = []; | |
for (const item of list) { | |
if (currentGroup.length) { |
This file contains 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 animate(animation: AnimationFunction, ...args: unknown[]): Promise<void> { | |
let start | |
return new Promise<void>((resolve) => { | |
function step(timestamp) { | |
start ??= timestamp | |
const isRunning = animation(timestamp - start, ...args) | |
if (isRunning) { | |
window.requestAnimationFrame(step) | |
} else { |
This file contains 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
error_page 400 /400.json; | |
location /400.json { | |
internal; | |
default_type application/json; | |
return 400 '{ "code": 400, "message":"Bad Request" }'; | |
} | |
error_page 401 /401.json; | |
location /401.json { | |
internal; |
This file contains 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 AppError extends Error { | |
constructor(message, data, options) { | |
super(message, options); | |
this.name = this.constructor.name; | |
this.data = data; | |
if (options && options.cause) { | |
const stackOffset = (this.message.match(/\n/g) || []).length + 2; | |
const afterCauseStack = this.stack | |
.split("\n") |