Skip to content

Instantly share code, notes, and snippets.

View kyanny's full-sized avatar

Kensuke Nagae kyanny

View GitHub Profile
#cat dt2.pl
#!/usr/local/bin/perl
use strict;use DateTime;
use DateTime::Format::MySQL;
my $sql_datetime = '2009-09-07 13:15:00';
my $dt1 = DateTime->new(year => 2009, month => 9, day => 7, hour => 13, minute => 15, second => 0);
my $dt2 = DateTime->new(year => 2009, month => 9, day => 7, hour => 13, minute => 15, second => 0, time_zone => 'Asia/Tokyo');
my $dt3 = DateTime::Format::MySQL->parse_datetime($sql_datetime);
// ==UserScript==
// @name rssmix LDRize
// @namespace http://d.hatena.ne.jp/a666666/
// @include http://pikapika.to/rssmix/*
// ==/UserScript==
(function(){
var $ = unsafeWindow.jQuery;
$('dt.rheader div a.article').each(function(i,elem){
$(elem).addClass("taggedlink");
$(elem).wrap(
#!/usr/bin/env perl
use strict;
use LWP::UserAgent;
use Test::Simple tests => 1;
my $ua = LWP::UserAgent->new();
my $response = $ua->get('http://1password.com/');
ok $response->base, 'http://agilewebsolutions.com/products/1Password';
#!/usr/bin/env perl
use strict;
use LWP::UserAgent;
use Data::Dumper;
my $ua = LWP::UserAgent->new();
my $url = 'http://livedoor.blogcms.jp/';
print '='x35, ' last response ', '='x35, "\n";
my $response = $ua->get($url);
#!/usr/bin/env perl
BEGIN {
require Lingua::JA::Summarize::Extract::ResultSet;
*Lingua::JA::Summarize::Extract::ResultSet::as_string = sub {
my $self = shift;
my $text;
my @result;
for my $line (@{ $self->sentences }) {
push @result, $line;
--- ResultSet.pm.orig 2007-06-10 17:50:39.000000000 +0900
+++ ResultSet.pm 2009-10-02 10:19:23.000000000 +0900
@@ -61,7 +61,7 @@
}
my $len = $self->length;
- $text =~ s/^(.{$len}).*$/$1¥n/s;
+ $text =~ s/^(.{$len}.*?¥x{3002}).*$/$1¥n/s;
$text;
}
@kyanny
kyanny / gist:215028
Created October 21, 2009 11:01
qr/^(-[5}|-{7})\n$/;
#!/usr/bin/env perl
use strict;
use Test::More;
plan tests => 6;
my $re = qr/^(-{5}|-{7})\n$/;
my $ret;
my $str1 = "-----\n"; # 5
ok( ($str1 =~ /$re/) );
@kyanny
kyanny / gist:215905
Created October 22, 2009 11:56
MT形式のデリミタ
#!/usr/bin/env perl
use strict;
use Test::Base;
plan tests => 1 * blocks;
run_is input => 'expected';
sub delimiter_escape_filter {
my $html = shift;
my $SEP = qr/^(-{8})(¥n)$/;
@kyanny
kyanny / gist:218540
Created October 26, 2009 10:04
implicit() implicit_tags()
#!/usr/bin/env perl
use strict;
use HTML::TreeBuilder;
use Test::Base;
plan tests => 1 * blocks;
run_is input => 'expected';
sub html_tree_parse {
my $tree = HTML::TreeBuilder->new();
@kyanny
kyanny / gist:219503
Created October 27, 2009 11:22
エンコーディングを意識して文字列を指定のバイト数でカットする
#!/usr/bin/env perl
use strict;
use Benchmark;
use Encode;
use Encode::Guess;
my $var = q{いいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいいab}; # euc-jp octets, 256 bytes
my $charset = eval { Encode::Guess::guess_encoding($var, qw(utf-8 euc-jp shiftjis))->name } || 'euc-jp'; # euc-jp
my $maxlength = 255;