Skip to content

Instantly share code, notes, and snippets.

@ktat
ktat / gist:816833
Created February 8, 2011 17:44
import JPA translations to perldocjp directory
#!/usr/bin/perl
use strict;
use File::Slurp qw/slurp/;
use LWP::Simple qw/get/;
my $jpa_dir = '/home/ktat/git/github/jpa-translation/';
my $assets_dir = '/home/ktat/git/github/PJP/assets/perldoc.jp/docs/modules/';
copy_to_pjp_assets($jpa_dir, $assets_dir);
@ktat
ktat / gist:949875
Created April 30, 2011 18:53
insert =begin original ... =end original around selected region
(defun oi ()
(interactive)
(insert "=begin original\n\n")
(search-forward-regexp "^\n")
(goto-char (match-beginning 0))
(insert "\n=end original\n")
)
@ktat
ktat / gist:961378
Created May 8, 2011 13:43
plackup / chrome 11.0.696.57
% sudo tcpdump 'tcp port 5000' -i lo -A -ttt
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
00:00:00.000000 IP gatto.36312 > gatto.5000: Flags [F.], seq 468590568, ack 468536422, win 257, options [nop,nop,TS val 20656595 ecr 20655989], length 0
E..43p@.@. R..................Lf.....p.....
.;1..;/u
00:00:00.000041 IP gatto.5000 > gatto.36312: Flags [.], ack 1, win 256, options [nop,nop,TS val 20656595 ecr 20656595], length 0
E..4..@.@.<...............Lf...............
.;1..;1.
00:00:00.001033 IP gatto.36316 > gatto.5000: Flags [S], seq 665707558, win 32792, options [mss 16396,sackOK,TS val 20656595 ecr 0,nop,wscale 7], length 0
@ktat
ktat / gist:961381
Created May 8, 2011 13:44
plackup / chrome 11.0.696.57 (anonymous mode)
% sudo tcpdump 'tcp port 5000' -i lo -A -ttt
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
00:00:00.000000 IP gatto.36255 > gatto.5000: Flags [S], seq 2660630935, win 32792, options [mss 16396,sackOK,TS val 20641806 ecr 0,nop,wscale 7], length 0
E..<..@.@.C ........................T.....@....
.:..........
00:00:00.000040 IP gatto.5000 > gatto.36255: Flags [S.], seq 2660819315, ack 2660630936, win 32768, options [mss 16396,sackOK,TS val 20641806 ecr 20641806,nop,wscale 7], length 0
E..<..@.@.<................s..............@....
.:...:......
00:00:00.000035 IP gatto.36255 > gatto.5000: Flags [.], ack 1, win 257, options [nop,nop,TS val 20641806 ecr 20641806], length 0
@ktat
ktat / gist:985234
Created May 22, 2011 06:48
WebSocket perl client
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
use Protocol::WebSocket::Handshake::Client;
use Protocol::WebSocket::Frame;
use IO::Socket;
use open ':utf8';
@ktat
ktat / gist:999684
Created May 31, 2011 00:35
WebSocket perl client(select)
#!/usr/bin/perl
use utf8;
use strict;
use warnings;
use Protocol::WebSocket::Handshake::Client;
use Protocol::WebSocket::Frame;
use IO::Socket;
use IO::Select;
@ktat
ktat / gist:1000223
Created May 31, 2011 09:15
WebSocket perl client(AE)
#!/usr/bin/perl
use utf8;
use strict;
use warnings;
use AnyEvent;
use Protocol::WebSocket::Frame;
use Protocol::WebSocket::Handshake::Client;
use IO::Socket;
use constant {READ => 0, WRITE => 1};
@ktat
ktat / gist:1018320
Created June 10, 2011 06:19
Text::Xslate bug
use Text::Xslate;
my $t = Text::Xslate->new(syntax => 'TTerse');
print $t->render_string(<<__END__);
[%
#
#
#
#
#
#
@ktat
ktat / gist:1070298
Created July 7, 2011 19:13
SQL::Maker の $where/$opt の処理が別メソッドだったら
sub search {
my ($self, $table_name, $where, $opt) = @_;
my $table = $self->schema->get_table( $table_name );
if (! $table) {
Carp::croak("No such table $table_name");
}
my $sql_maker = $self->sql_builder;
my $stmt = $sql_maker->new_select(select => $opt->{columns} || $table->columns);
@ktat
ktat / gist:1287614
Created October 14, 2011 16:34
add_to_items
# 問題では、add_to_items($value, \@array); でしたので、書き換わりません。
# と、指摘いただきました。
{
my ($value, $array_ref) = (1, [1,2,3,4]);
add_to_items($value, $array_ref);
print join ",", @$array_ref;
# 2,3,4,5
}