Skip to content

Instantly share code, notes, and snippets.

View UniBreakfast's full-sized avatar
💡
reinventing basic stuff in order to understand it better

Mykhailo "Ninin" Velykoselskyi UniBreakfast

💡
reinventing basic stuff in order to understand it better
View GitHub Profile
@UniBreakfast
UniBreakfast / sleep.js
Created December 14, 2019 12:11
To insert arbitrary delay in an async function
const sleep = time => new Promise(wakeUp => setTimeout(wakeUp, time))
// ...
await sleep(2000)
// or simply
await new Promise(go => setTimeout(go, 2000))
@UniBreakfast
UniBreakfast / rndStr.js
Created November 29, 2019 16:14
random strings for session tokens etc
// this one is shorter
rndStr1 = (i=4, f=()=>Math.random().toString(36).slice(2), s='') =>
{ for (;i;--i) s+=f(); return s }
// this one is faster
rndStr2 = (n=42,
l='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz--', s='') =>
{ for (;n;--n) s+=l[Math.random()*62|0]; return s }
// this one is with dashes
@slavafomin
slavafomin / javascript-pluralization.md
Last active February 12, 2023 19:22
How to pluralize words in JavaScript in different languages?

How to pluralize any word in different languages using JavaScript?

Hello!

Today, I'm going to show you how to pluralize any word in JavaScript (Node.js or Browser) in almost any language!

I've developed a very simple, but powerful package in JavaScript that will help you to achieve this goal. It's called Numerous.

@bobspace
bobspace / css_colors.js
Last active April 24, 2024 13:34
All of the CSS Color names in a big javascript object.
// CSS Color Names
// Compiled by @bobspace.
//
// A javascript object containing all of the color names listed in the CSS Spec.
// This used to be a big array, but the hex values are useful too, so now it's an object.
// If you need the names as an array use Object.keys, but you already knew that!
//
// The full list can be found here: https://www.w3schools.com/cssref/css_colors.asp
// Use it as you please, 'cuz you can't, like, own a color, man.