Skip to content

Instantly share code, notes, and snippets.

function throttle(callback, fps = 60) {
const frameTime = 1000 / fps;
let lastTime = window.performance.now();
return function run() {
window.requestAnimationFrame(run);
const currentTime = window.performance.now();
const elapsedTime = currentTime - lastTime;
.neon-text {
color: #fff;
text-shadow:
0 0 7px #fff,
0 0 10px #fff,
0 0 21px #fff,
0 0 42px #0fa,
0 0 82px #0fa,
0 0 92px #0fa,
0 0 102px #0fa,
if (!Object.prototype[Symbol.iterator]) {
Object.prototype[Symbol.iterator] = function* () {
for (let key in this) {
yield this[key];
}
};
}
const fetchWithRetries = async (url, options, retryCount = 0) => {
const { maxRetries = 3, ...remainingOptions } = options;
try {
return await fetch(url, remainingOptions);
} catch (error) {
if (retryCount < maxRetries) {
return fetchWithRetries(url, options, retryCount + 1);
}
const cities = new Map([
['MG', 'Belzante'],
['SP', 'Sampa']
]);
const getCity = city => cities.get(city) ?? 'Not found';
export enum MouseButton {
None = 0,
Primary = 1,
Secondary = 2,
Auxiliary = 4,
BrowserBack = 8,
BrowserForward = 16
}
@jakubbarczyk
jakubbarczyk / buffer-max-count.js
Last active March 31, 2022 10:30
Buffer max count operator for RxJS.
import { defer } from 'rxjs';
import { map } from 'rxjs/operators';
export const bufferMaxCount = (count = 0) => source => defer(() => {
let buffer = [];
return source.pipe(
map(next => buffer = [next, ...buffer.slice(0, count - 1)])
);
});
export const delay = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));
function Seal(constructor: Function) {
Object.seal(constructor);
Object.seal(constructor.prototype);
}
function Freeze(constructor: Function) {
Object.freeze(constructor);
Object.freeze(constructor.prototype);
}