Skip to content

Instantly share code, notes, and snippets.

View dkrnl's full-sized avatar

Dmitri Pyatkov dkrnl

View GitHub Profile
@xiaochengh
xiaochengh / explainer.md
Last active December 14, 2022 09:21
Explainer: Font Metrics Override Descriptors

Explainer: Font Metrics Override Descriptors

(A newer version is at here, where a new descriptor advance-override is added)

Spec

This doc explains descriptors ascent-override, descent-override and line-gap-override for CSS @font-face rule.

Basic usage:

@tomhicks
tomhicks / plink-plonk.js
Last active March 18, 2024 02:23
Listen to your web pages
@mattdesl
mattdesl / about.md
Last active September 29, 2023 20:08
interactive audio sketch
@mikowl
mikowl / oneliners.js
Last active March 28, 2024 20:52
👑 Awesome one-liners you might find useful while coding.
// Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// or
const sleep = util.promisify(setTimeout);
@vielhuber
vielhuber / README.MD
Last active February 17, 2022 00:32
input date datetime-local polyfill for firefox and older browsers with flatpickr datepicker #js

installation

npm install flatpickr --save-dev

usage

import flatpickr from 'flatpickr';
import { fr } from 'flatpickr/dist/l10n/fr.js';
import { de } from 'flatpickr/dist/l10n/de.js';
@andreiglingeanu
andreiglingeanu / nullify-transforms.js
Last active January 30, 2024 22:17
A nice way to nullify CSS transforms and get original positions of the un-modified rect
// Nullify the transforms of the element
//
// This is all behaving just like getBoundingClientRect() but it nullifies all the transforms
// and kinds _reverts_ the element onto its original position.
// This will work even with complex translations, rotations.
// The beauty is in the way it applies matrix inverse onto the transformation
// matrix and mutates the getboundingclientrect along the way.
//
// Usage:
// let { top, left } = nullifyTransforms(el);
@refactorized
refactorized / package.json
Created August 1, 2017 17:58
npm script arguments
{
"name": "npm-args",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"hbd": "bash -c 'echo \"happy birthday $0! and many returns\"'",
"paradiddle": "bash -c 'echo \"$0$1$0$0 $1$0$1$1\"'",
"test": "echo \"Error: no test specified\" && exit 1"
},
@ayamflow
ayamflow / gist:96a1f554c3f88eef2f9d0024fc42940f
Last active March 20, 2024 02:48
Threejs Fit plane to screen
var cameraZ = camera.position.z;
var planeZ = 5;
var distance = cameraZ - planeZ;
var aspect = viewWidth / viewHeight;
var vFov = camera.fov * Math.PI / 180;
var planeHeightAtDistance = 2 * Math.tan(vFov / 2) * distance;
var planeWidthAtDistance = planeHeightAtDistance * aspect;
// or
U+0000
U+0002
U+000D
U+0020
U+0021
U+0022
U+0023
U+0024
U+0025
U+0026
@znechai
znechai / pluralize-ru.js
Last active April 2, 2024 03:03
JavaScript - Plural forms for russian words
/**
* Plural forms for russian words
* @param {Integer} count quantity for word
* @param {Array} words Array of words. Example: ['депутат', 'депутата', 'депутатов'], ['коментарий', 'коментария', 'комментариев']
* @return {String} Count + plural form for word
*/
function pluralize(count, words) {
var cases = [2, 0, 1, 1, 1, 2];
return count + ' ' + words[ (count % 100 > 4 && count % 100 < 20) ? 2 : cases[ Math.min(count % 10, 5)] ];
}