Skip to content

Instantly share code, notes, and snippets.

View koorchik's full-sized avatar
🇺🇦

Viktor Turskyi koorchik

🇺🇦
View GitHub Profile
@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++?
{
"modules" : {
"CPAN::Meta" : {
"dist" : "CPAN-Meta-2.130880",
"mymeta" : {
"abstract" : "the distribution metadata for a CPAN dist",
"author" : [
"David Golden <dagolden@cpan.org>",
"Ricardo Signes <rjbs@cpan.org>"
],
use Try::Tiny;
sub load {
my $self = shift;
try {
return $self->SUPER::load(@_);
}
catch {
...
@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];
@koorchik
koorchik / list_util_bug.pl
Created June 2, 2012 11:26
List::Util::first bug
use List::Util qw/first/;
use List::MoreUtils qw/first_value/;
use v5.10;
use Test::More;
is( test('grep'), 4, 'Grep for finding first value' );
is( test('list_util'), 4, 'List::Util::first for finding first value' );
is( test('list_more_utils'), 4, 'List::MoreUtils::first_value for finding first value' );
@koorchik
koorchik / try_tiny_with_helper.pl
Created May 19, 2012 08:02
Try::Tiny with helper
# ...
test_exception( Exception1->new() );
test_exception( Exception2->new() );
test_exception( Exception3->new() );
test_exception("Special text\n");
test_exception("Text exception\n");
use Scalar::Util qw/blessed/;
sub e($) {
@koorchik
koorchik / try_tiny_dispatch_exceptions.pl
Created May 19, 2012 07:58
Try::Tiny dispatch exceptions
package Exception::Base;
use overload
'~~' => sub { $_[0]->isa( $_[1] ) },
fallback => 1;
package Exception1;
use base 'Exception::Base';
sub new { bless {}, shift }
package Exception2;
@koorchik
koorchik / render_file.pl
Created May 15, 2012 05:38
render_file
$app->helper('render_file' => sub {
my $c = shift;
my %args = @_;
my $filepath = $args{filepath};
unless ( -f $filepath && -r $filepath ) {
$c->app->log->error("Cannot read file [$filepath]. error [$!]");
return;
}
@koorchik
koorchik / Makefile.PL
Created January 5, 2012 16:51
Makefile example
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'MyApp',
VERSION => 0.01,
MIN_PERL_VERSION => 5.010,
PREREQ_PM => {
'Mojolicious' => 2.41,
<meta name="csrftoken" content="af58af65a8f65a8dfafa76df8a7afdf"/>
<script type="text/javascript">
$(document).ajaxSend(function(e, xhr, options) {
var token = $("meta[name='csrftoken']").attr("content");
xhr.setRequestHeader("X-CSRF-Token", token);
})
</script>