Skip to content

Instantly share code, notes, and snippets.

View riywo's full-sized avatar
🏈
Go 49ers!

Ryosuke Iwanaga riywo

🏈
Go 49ers!
View GitHub Profile
@riywo
riywo / Fuga.pm
Created October 5, 2011 12:11
perlで別のモジュールのメソッドを生やす
package Fuga;
use strict;
use warnings;
use Hoge;
sub new {
my ($class) = @_;
my $self = bless {}, $class;
$self->{'foo'} = 'bar';
return $self;
@riywo
riywo / Fuga.pm
Created October 6, 2011 06:26
perlで別のモジュールのメソッドを生やす その2
package Fuga;
use strict;
use warnings;
use Hoge;
use Sub::Install;
Sub::Install::install_sub({ code => \&Hoge::hoge });
sub new {
my ($class) = @_;
@riywo
riywo / rrd-server.pl
Created November 29, 2011 19:31
rrdtoolプロセスをTCPサーバにしてみる
use strict;
use warnings;
use IO::Socket::INET;
use Parallel::Prefork;
use IPC::Open3;
sub MaxRequestsPerChild () { 100 }
my $listen_sock = IO::Socket::INET->new(
Listen => 5,
@riywo
riywo / gist:1484992
Created December 16, 2011 07:43
wantarrayはこんな感じで連鎖できる
use strict;
use warnings;
sub hoge { return fuga() };
sub fuga {
if (wantarray) {
print "array\n";
} else {
print "scalar\n";
}
@riywo
riywo / Util.pm
Created December 27, 2011 18:42
Amon2でTest::mysqld
package t::Util;
BEGIN {
unless ($ENV{PLACK_ENV}) {
$ENV{PLACK_ENV} = 'test';
}
if ($ENV{PLACK_ENV} eq 'deployment') {
die "Do not run a test script on deployment environment";
}
}
use File::Spec;
@riywo
riywo / run
Created December 29, 2011 07:01
daemontoolsのrunでperlbrewのbashrc使う
#!/bin/sh
exec 2>&1
export HOME=/home/riywo
cd /home/riywo/MyApp
exec setuidgid riywo ./script/start.sh
@riywo
riywo / os_type
Created January 7, 2012 04:52
OSのタイプをなんとなく出力
#!/bin/sh
if [ $OSTYPE = "linux-gnu" ]; then
LSB_ID=`lsb_release -i | cut -f2 -d:`
LSB_VERSION=`lsb_release -r | cut -f2 -d:`
OS_VERSION=`echo $LSB_ID-$LSB_VERSION | sed -e "s/ //g"`
MACHINE_TYPE=`uname -m`
echo $OS_VERSION-$MACHINE_TYPE
else
echo `uname -rsm | sed -e "s/ /-/g"`
fi
@riywo
riywo / gist:1575091
Created January 7, 2012 15:49
XS失敗
/usr/bin/perl /Users/riywo/llenv/apps/perl-5.8.8/local/lib/perl5/ExtUtils/xsubpp -typemap /System/Library/Perl/5.10.0/ExtUtils/typemap -typemap typemap XS.xs > XS.xsc && mv XS.xsc XS.c
gcc-4.2 -c -arch x86_64 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include -Os -DVERSION=\"2.32\" -DXS_VERSION=\"2.32\" "-I/System/Library/Perl/5.10.0/darwin-thread-multi-2level/CORE" XS.c
XS.xs: In function ‘json_init’:
XS.xs:109: warning: format not a string literal and no format arguments
XS.xs: In function ‘shrink’:
XS.xs:135: warning: format not a string literal and no format arguments
XS.xs: In function ‘decode_hv’:
XS.xs:1317: warning: comparison is always false due to limited range of data type
XS.xs: In function ‘decode_json’:
XS.xs:1611: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘STRLEN’
@riywo
riywo / pm_test.pl
Created January 11, 2012 19:37
Parallel::ForkManagerでpipe使って簡単に結果渡し
use strict;
use warnings;
use Parallel::ForkManager;
use IO::Pipe;
use JSON;
my @hosts = map { sprintf("host%02d", $_) } (1..10);
my $workers = 5;
my $pm = Parallel::ForkManager->new($workers);
@riywo
riywo / nginx.conf
Created January 18, 2012 18:29
nginxでURIの先頭使ってbackend serverのportを決める
http {
map $uri $backend_port {
include port_map;
}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
server {