Skip to content

Instantly share code, notes, and snippets.

View kyanny's full-sized avatar

Kensuke Nagae kyanny

View GitHub Profile
@kyanny
kyanny / gist:220365
Created October 28, 2009 09:04
\Q\E
#!/usr/bin/env perl
use strict;
use Encode;
my $text = q{王将};
my $html = q{餃子の王将(ぎょうざのおうしょう)は、京都府京都市山科区に本社を置く王将フードサービスが京阪地区を中心に全国展開する、大阪風の餃子を売りにした中華料理チェーンの名称。通称は「王将」、「京都王将」である。};
my $decoded_text = decode('euc-jp', $text);
my $decoded_html = decode('euc-jp', $html);
@kyanny
kyanny / gist:222271
Created October 30, 2009 11:20
HTML の中から特定のタグだけ削除する (ただしツリー構造ごと削除はしない)
#!/usr/bin/env perl
#
# HTML の中から特定のタグだけ削除する (ただしツリー構造ごと削除はしない)
#
use HTML::TreeBuilder;
use Test::Base;
plan tests => 1 * blocks;
sub remove_tag {
my $html = shift;
@kyanny
kyanny / gist:222282
Created October 30, 2009 11:43
HTML::Element#content_list() の返り値 #
#!/usr/bin/env perl
#
# HTML::Element#content_list() の返り値
#
use HTML::TreeBuilder;
use Test::Base;
plan tests => 1 * blocks;
sub empty_content_scalar {
my $html = shift;
@kyanny
kyanny / gist:222283
Created October 30, 2009 11:46
HTML::Element の属性値を操作する
#!/usr/bin/env perl
#
# HTML::Element の属性値を操作する
#
use HTML::TreeBuilder;
use Test::Base;
plan tests => 1 * blocks;
sub remove_attr {
my $html = shift;
@kyanny
kyanny / gist:226821
Created November 5, 2009 06:34
Getting Started Plack on Amazon EC2
# yum install perl-*
# cpan -i Plack
# cpan -i Devel::StackTrace::AsHTML
# cpan -i Plack
# cpan -i HTTP::Request::AsCGI
# cpan -i Plack
# wget http://cpansearch.perl.org/src/MIYAGAWA/Plack-0.9008/eg/dot-psgi/Dumper.psgi
# plackup -a Dumper.psgi -p 3000
# wget http://cpansearch.perl.org/src/MIYAGAWA/Plack-0.9008/eg/dot-psgi/plack-req.psgi
# plackup -a plack-req.psgi -p 3000
@kyanny
kyanny / gist:241774
Created November 24, 2009 10:22
Trap SIGINT but wait until process finished.
#!/usr/bin/env perl
use strict;
use DateTime;
our $cnt = 0;
our $int = 0;
$SIG{INT} = sub {
warn sprintf('sigint received at %s.', DateTime->now(time_zone => 'local'));
$int++;
package MyApp::SimpleConfig;
use Moose;
with qw(MooseX::Getopt MooseX::SimpleConfig);
has 'config' => (
is => 'ro',
isa => 'HashRef',
);
@kyanny
kyanny / gist:253175
Created December 10, 2009 07:16
DBIC arbitrary (気まぐれな) table names
package MyApp::Schema;
use strict;
use base qw(DBIx::Class::Schema);
__PACKAGE__->load_namespaces();
use Data::Dumper;
my $source = __PACKAGE__->source('Foo');
for my $table (qw(foo foo_200912)) {
my $new_source = $source->new($source);
@kyanny
kyanny / gist:253188
Created December 10, 2009 07:55
Get the first day of this month
use DateTime;
my $the_first_day_of_this_month = DateTime->last_day_of_month(
year => $today->year,
month => $today->month,
)->subtract(months => 1)->add(days => 1);
@kyanny
kyanny / exifr_date.rb
Created February 8, 2010 16:24
Ruby RMagick exifr TMail
#!/usr/bin/env ruby
require 'rubygems'
gem 'exifr'
require 'exifr'
exif = EXIFR::JPEG.new('xxx_orig.jpg')
p exif.date_time
p exif.date_time_original
p exif.date_time_digitized