Skip to content

Instantly share code, notes, and snippets.

View koorchik's full-sized avatar
🇺🇦

Viktor Turskyi koorchik

🇺🇦
View GitHub Profile
@koorchik
koorchik / perl6-consistency.md
Last active December 7, 2017 19:20
Perl6 consistency example

In most programming languages you have a shorter form for incrementing a value

In JavaScript you can write:

a = a + 10; // original form
a += 10; // shorter form

a = a * 10; // original form
a *= 10; // shorter form
@koorchik
koorchik / fastest-validator-vs-livr-benchmark.mjs
Last active July 3, 2023 11:49
Fastest with strict: remove vs LIVR Benchmark
import Benchmark from "benchmark";
import LIVR from "livr";
import FastestValidator from "fastest-validator";
/* FASTEST VALIDATOR */
const fastestValidatorShema = {
$$strict: "remove",
username: { required: true, type: "string" },
gender: { type: "string", enum: ["male", "female"] },
phone: { type: "string", max: 10 },
package Validator;
use strict;
use warnings;
use Moo;
use BaseValidator;
use Util;
our $DEFAULT_RULES = {};
our $IS_DEFAULT_AUTO_TRIM = 0;
@koorchik
koorchik / uuid_distribution_test.mjs
Created September 7, 2023 06:39
Testing UUID distribution if used as sharding key
import crypto from "crypto";
const NUMBER_OF_SHARDS = 100;
const NUMBER_OF_ENTRIES = 100_000;
const shards = [];
for (let i = 0; i < NUMBER_OF_ENTRIES; i++) {
const numericUUID = BigInt("0x" + crypto.randomUUID().replace(/-/g, ""));
const shardId = Number(numericUUID % BigInt(NUMBER_OF_SHARDS));