Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/perl
use strict;
use warnings;
use Text::Xslate;
use Test::More;
my $tx = Text::Xslate->new(cache => 0,
function => {
@hanabokuro
hanabokuro / gist:1041891
Created June 23, 2011 04:16
xslate vm code
[% f() %]
||
VV
pushmark // f
fetch_s "f" #1
or 2
fetch_symbol "f" #1
funcall
@hanabokuro
hanabokuro / gist:1042245
Created June 23, 2011 09:39
Text::Xslate::Compiler simulate global_vars
sub _generate_variable {
my($self, $node) = @_;
if(defined(my $lvar_id = $self->lvar->{$node->value})) {
return $self->opcode( load_lvar => $lvar_id, symbol => $node );
}
else {
my $name = $self->_variable_to_value($node);
my @code;
@hanabokuro
hanabokuro / gist:1042248
Created June 23, 2011 09:40
Text::Xslate enable to write 'func()' instead of '$func()'
sub _generate_call {
my($self, $node) = @_;
my $callable = $node->first; # function or macro
my $args = $node->second;
my @code = $self->SUPER::_generate_call($node);
if($callable->arity eq 'name'){
my @code_fetch_symbol = $self->compile_ast($callable);
@code = (
@hanabokuro
hanabokuro / gist:1108805
Created July 27, 2011 06:46
memcached-1.4.6
よく似た症状を再現させる方法
・memcachedを起動
・gdb -p <PID> で attach
(gdb) call pthread_mutex_lock(&conn_lock)
(gdb) call pthread_mutex_lock(&conn_lock)
2回目はlockするので Ctrl-C で中断
(gdb) detach
これで同じ症状になります。
@hanabokuro
hanabokuro / gist:2709534
Created May 16, 2012 11:00
pnotes leak (perl5.8 + mod_perl-2.0.4)
#!/usr/bin/perl
use strict;
use warnings;
use B;
use Apache2::RequestUtil;
print <<"END;";
Content-type: text/plain
@hanabokuro
hanabokuro / gist:3031761
Created July 2, 2012 07:54
Text::Xslate::_magic_token
sub _magic_token {
my($self, $fullpath) = @_;
$self->{serial_opt} ||= Data::MessagePack->pack([
ref($self->{compiler}) || $self->{compiler},
$self->_filter_options_for_magic_token($self->_extract_options($self->parser_option)),
$self->_filter_options_for_magic_token($self->_extract_options($self->compiler_option)),
$self->input_layer,
[sort keys %{ $self->{function} }],
]);
@hanabokuro
hanabokuro / mysql client wrapper
Created May 30, 2013 09:31
予期せず本番DBを更新してしまわないようにするためのwrapper 本物のmysqlよりもPATHの先頭にくるようにしておく。 DBを更新したいときは /usr/bin/msql とfull pathで起動する。
#!/usr/bin/perl
use strict;
use warnings;
use Expect;
my $MYSQL_COMMAND = '/usr/bin/mysql';
my $expect = new Expect;
package AvoidCoreTextBug;
use strict;
use warnings;
our %SEPARATORS = map { $_ => 1 } (0x20, 0xa0,
0x1680, 0x180e,
0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200a,
0x202f, 0x205f,
0x3000,
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Builder;
BEGIN {
use_ok('AvoidCoreTextBug');