Skip to content

Instantly share code, notes, and snippets.

View termi's full-sized avatar

Егор Халимоненко termi

View GitHub Profile
@termi
termi / server.test.js
Created June 19, 2025 21:29
MRE for "Aborting `signal` of server.lister method before actual listeting begin put a `listen` promise into a floating state"
// add into test/server.test.js
await t.test('listen should not start server if already aborted 2', async (t) => {
t.plan(2)
const controller = new AbortController()
controller.abort(new Error('aborting before actual start'))
const fastify = Fastify()
try {
// promise returning by fastify.listen is in "floating" state
await fastify.listen({ port: 1234, signal: controller.signal })
@termi
termi / Readme.md
Created May 7, 2025 09:30
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
@termi
termi / Readme.md
Last active March 7, 2025 08:17
Patch jest/runner/testWorker.js to fix compatibility issues and more

Fix env in jest tests

How to use

@termi
termi / getOnlyUniqueValuesInArray.js
Created February 22, 2025 18:37
Get only unique values in array
function getOnlyUniqueValuesInArray(array) {
const arrayLen = array.length;
/** @type {Map<any, number>} */
const map = new Map();
for (let i = 0 ; i < arrayLen ; i++) {
const value = array[i];
map.set(value, map.getOrInsert(value, 0) + 1);
}
@termi
termi / Symbol_test.js
Created March 3, 2014 13:04
Symbol's polyfill test
applyPolyfills();var $S_polyfill$0 = Symbol["__polyfill__"];var $S_SET$0, $S_GET$0, $isSymbol$0;if($S_polyfill$0){$S_SET$0 = $S_polyfill$0["__setObjectSetter__"];$S_GET$0 = $S_polyfill$0["__setObjectGetter__"];$isSymbol$0 = $S_polyfill$0["__isSymbol__"];$S_polyfill$0 = true;}else {$S_polyfill$0 = false}
var private1 = Symbol();var $S$0 = $S_polyfill$0 && typeof private1 === 'object' && $isSymbol$0(private1);
var private2 = Symbol();var $S$1 = $S_polyfill$0 && typeof private2 === 'object' && $isSymbol$0(private2);
var publicProp1 = 'public_prop1';
var publicProp2 = (function(){return 'public_prop1'})();var $S$2 = $S_polyfill$0 && typeof publicProp2 === 'object' && $isSymbol$0(publicProp2);
function createSymbolOrObject(createSymbol){ return createSymbol ? Symbol() : {} };
{// simple
var obj = {}, obj1 = {};
@termi
termi / crossBrowser_initKeyboardEvent.js
Last active June 13, 2023 02:01
Cross-browser initKeyboardEvent
void function() {//closure
var global = this
, _initKeyboardEvent_type = (function( e ) {
try {
e.initKeyboardEvent(
"keyup" // in DOMString typeArg
, false // in boolean canBubbleArg
, false // in boolean cancelableArg
, global // in views::AbstractView viewArg
@termi
termi / matchesSelector_shim.js
Last active February 9, 2021 09:52
Element.prototype.matchesSelector shim
var _hasOwnProperty = Object.prototype.hasOwnProperty;
if(!Element.prototype.matchesSelector) {
Element.prototype.matchesSelector =
Element.prototype.matches ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector || function(selector) {
if(!selector)return false;
@termi
termi / declension.js
Created October 21, 2013 09:55
Склонение существительных
/**
* Склонение существительных
* Правильная форма cуществительного рядом с числом (счетная форма).
*
* @example declension("файл", "файлов", "файла", 0);//returns "файлов"
* @example declension("файл", "файлов", "файла", 1);//returns "файл"
* @example declension("файл", "файлов", "файла", 2);//returns "файла"
*
* @param {string} oneNominative единственное число (именительный падеж)
* @param {string} severalGenitive множественное число (родительный падеж)
@termi
termi / scrollIntoView_polyfill.js
Last active March 6, 2019 15:22
Support centering an element when scrolling into view w3c issue: https://www.w3.org/Bugs/Public/show_bug.cgi?id=17152 Original code from http://jsbin.com/ilecok/16/
////////////////////////////////////////////////////////////////////////////////
// Author: Thaddee Tyl 2012.
// The following work is under CC0.
void function() {
// Hook the polyfill.
Element.prototype._scrollIntoView = function scrollIntoView(options) {
if( !this.ownerDocument )return;
@termi
termi / css3SelectorsPolyfill.js
Created May 5, 2012 19:05
getElementsByClassName/querySelector/querySelectorAll/matchesSelector Polyfill
/** @license MIT License (c) copyright Egor Halimonenko (termi1uc1@gmail.com) */
// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @warning_level VERBOSE
// @jscomp_warning missingProperties
// @output_file_name a.js.querySelector.min.js
// @check_types
// ==/ClosureCompiler==