Skip to content

Instantly share code, notes, and snippets.

View kaathewise's full-sized avatar

Svyatoslav Usachev kaathewise

View GitHub Profile
function draw(fractal, state, R, maxDepth, context) {
context.moveTo(state.x, state.y);
step(0, R);
function step(depth, R) {
if (depth == maxDepth) {
var x1 = state.x + R * Math.cos(state.alpha)
, y1 = state.y + R * Math.sin(state.alpha);
context.lineTo(x1, y1);
state.x = x1;
# waterfall is the most obvious one
sub waterfall {
my $promise = make_promise;
for (@_) {
$promise = $promise->then($_);
}
return $promise;
}
# series is a bit harder
<div class="item">
<div class="toSave"></div>
<div class="focusable"></div>
</div>
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Promises qw( make_promise );
sub waterfall {
my $promise = make_promise;
for (@_) {
$promise = $promise->then($_);
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Promises qw( make_promise );
my $exit = AnyEvent->condvar;
my $p = make_promise;
$p->then(sub { 1 })->then(sub { print "1\n" });
{
my $_postpone;
if ( exists &AE::postpone ) {
$_postpone = \&AE::postpone;
}
else {
my $POSTPONE_W;
my @POSTPONE;
sub lexer {
my $target = shift;
sub {
TOKEN: {
return ['VAR', $1] if $target =~ /\G \$ ([A-Za-z_]\w*) /gcx;
return ['BINOP', $1] if $target =~ /\G (and|or) /gcx;
return ['UNOP', $1] if $target =~ /\G (not) /gcx;
return ['CMP', $1] if $target =~ /\G (eq|ne|=~|!~) /gcx;
return ['LP', undef] if $target =~ /\G \( /gcx;
return ['RP', undef] if $target =~ /\G \) /gcx;
%{
use English qw( -no_match_vars );
use Data::Dumper;
sub a_rule {
shift;
return join "\n", "sub {", @_, "}";
}
sub a_default {
if: ($method eq PUT and not $from) or $method eq POST
metric: multi_counter uploads (os)
metric: multi_sum uploads_traffic (os rcv)
metric: multi_timing upload_time (os time)
if: $method eq PUT and $from
metric: multi_counter continued_uploads (os)
metric: multi_sum continued_uploads_traffic (os rcv)
metric: multi_timing continued_upload_time (os time)
function Eagle(...) {
Bird.call(this, ...);
}
Eagle.prototype = {
__proto__: Bird.prototype,
...
};