Skip to content

Instantly share code, notes, and snippets.

View peter-leonov's full-sized avatar

Peter Leonov peter-leonov

View GitHub Profile
@peter-leonov
peter-leonov / gist:5659189
Created May 27, 2013 21:31
Parsable, but meant broken by Jison grammar.
%pure_parser
%token keyword_class keyword_module keyword_def keyword_undef keyword_begin keyword_rescue keyword_ensure keyword_end keyword_if keyword_unless keyword_then keyword_elsif keyword_else keyword_case keyword_when keyword_while keyword_until keyword_for keyword_break keyword_next keyword_redo keyword_retry keyword_in keyword_do keyword_do_cond keyword_do_block keyword_do_LAMBDA keyword_return keyword_yield keyword_super keyword_self keyword_nil keyword_true keyword_false keyword_and keyword_or keyword_not modifier_if modifier_unless modifier_while modifier_until modifier_rescue keyword_alias keyword_defined keyword_BEGIN keyword_END keyword__LINE__ keyword__FILE__ keyword__ENCODING__
%token <id> tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tLABEL
%token <node> tINTEGER tFLOAT tSTRING_CONTENT tCHAR
%token <node> tNTH_REF tBACK_REF
%token <num> tREGEXP_END
%type <node> singleton strings string string1 xstring regexp
> You're welcome!
>
> In answer to your questions and remarks:
>
> 1) I'm sorry, but jison is /not/ a /port/ of bison…
Understand. Who may want to just copy such a monster.
>
> 1.a) jison combines a lexer and LALR(1) parser in one package.
It is cool and I like it. But, as you write below, in my case the builtin lexer is not the case :(
> 1.b) jison may share 4 alphanumerics with bison and may support a large
@peter-leonov
peter-leonov / send.rb
Last active December 23, 2015 00:19
CGI (sic!) script sending emails
<empty>
# get hex color of pixel
# implementation of answer here http://stackoverflow.com/questions/8894194/retrieving-the-hex-code-of-the-color-of-a-given-pixel
# solution to 'undefined method for MiniMagick::CommandBuilder in mini_magick'
require 'mini_magick'
module MiniMagick
class Image
def pixel_at(x, y)
run_command("convert", "#{path}[1x1+#{x.to_i}+#{y.to_i}]", 'txt:').split("\n").each do |line|
return $1 if /^0,0:.*(#[0-9a-fA-F]+)/.match(line)
end
@peter-leonov
peter-leonov / template.pl
Last active August 29, 2015 14:22
tiny aka small aka simple aka plain perl template "engine"
#!/usr/bin/perl
# use: echo "hello <%= $USER %> <% if (true) { %>abc<%>%>" | perl template.pl > out.txt
for $key (keys %ENV) { ${$key} = $ENV{$key} }
$template = join("", <>);
$template =~ s/<%=/<% print /g;
@code = @text = split(/<%(.+?)%>/s, $template);
for (my $i = 0; $i <= $#code; $i+=2) { @code[$i] = "; print \@text[$i];" }
eval join(";", @code);
@peter-leonov
peter-leonov / gist:49cb28698a93064d79cb
Created July 1, 2015 12:34
/var/log/upstart/docker.log
This file has been truncated, but you can view the full file.
INFO[297400] GET /v1.18/containers/network/json
INFO[297401] GET /v1.18/containers/network/json
INFO[297401] GET /v1.18/containers/network/json
INFO[297401] GET /v1.18/containers/network/json
INFO[297401] GET /v1.18/containers/network/json
INFO[297401] GET /v1.18/containers/json?all=0&limit=-1&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dinshaker%22%2C+%22com.docker.compose.service%3Dcombinator%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D&size=0
INFO[297402] POST /v1.18/containers/dc0136dc7fe3cd7549c0367f999c96e95e297953eb7f66df4f443ac6e6eae0f8/stop?t=10
INFO[297404] GET /v1.18/containers/json?all=0&limit=-1&trunc_cmd=0&filters=%7B%22label%22%3A+%5B%22com.docker.compose.project%3Dinshaker%22%2C+%22com.docker.compose.service%3Drails%22%2C+%22com.docker.compose.oneoff%3DFalse%22%5D%7D&size=0
INFO[297404] POST /v1.18/containers/d332476a2d1b2c0fb14f255f21766e772735c58dfa07e5d3ca672196943467f2/stop?t=10
INFO[297405] GET /
@peter-leonov
peter-leonov / gist:073b161622e539c62956
Created July 3, 2015 10:42
docker-machine ssh food 'cat /var/log/upstart/docker.log'
Waiting for /var/run/docker.sock
INFO[0000] Listening for HTTP on unix (/var/run/docker.sock)
WARN[0000] Running modprobe bridge nf_nat failed with message: insmod /lib/modules/3.13.0-52-generic/kernel/net/llc/llc.ko
insmod /lib/modules/3.13.0-52-generic/kernel/net/802/stp.ko
insmod /lib/modules/3.13.0-52-generic/kernel/net/bridge/bridge.ko
insmod /lib/modules/3.13.0-52-generic/kernel/net/netfilter/nf_conntrack.ko
insmod /lib/modules/3.13.0-52-generic/kernel/net/netfilter/nf_nat.ko
, error: exit status 1
/var/run/docker.sock is up
WARN[0000] Your kernel does not support swap memory limit.
@peter-leonov
peter-leonov / bomb.sh
Last active November 22, 2019 03:46
docker fork bomb
docker run ruby ruby -e 'loop { fork { fork { sleep 0.1 } } }'
@peter-leonov
peter-leonov / template.pl
Created March 8, 2016 19:55
dump perl based template
#!/usr/bin/perl
# usage: echo "hello <%= $USER %> <% if (true) { %>abc<%>%>" | perl template.pl > out.txt
for $key (keys %ENV) { ${$key} = $ENV{$key} }
$template = join("", <>);
$template =~ s/<%=/<% print /g;
@code = @text = split(/<%(.+?)%>/s, $template);
for (my $i = 0; $i <= $#code; $i+=2) { @code[$i] = "; print \@text[$i];" }
eval join(";", @code);