Skip to content

Instantly share code, notes, and snippets.

View memememomo's full-sized avatar
🏠
Working from home

Uchiko memememomo

🏠
Working from home
  • Aichi, Japan
View GitHub Profile
@memememomo
memememomo / base.t
Created February 25, 2014 12:06
Test::Mojoでアップロード処理をテストする ref: http://qiita.com/memememomo/items/023c00ba9fe1e3f8f658
use strict;
use warnings;
use utf8;
use Encode;
use Test::Mojo;
use Test::More;
use File::Basename;
use Mojo::Asset::File;
@memememomo
memememomo / sample.pl
Created February 25, 2014 12:45
Mojo::Server::Daemonで簡易なWebサーバを作る ref: http://qiita.com/memememomo/items/bafa7929af0ae8ab091c
use strict;
use warnings;
use utf8;
use Encode;
use Mojo::Server::Daemon;
use Test::More;
use Test::TCP;
use Mojo::UserAgent;
$ morbo script/myapp # Mojoliciousアプリの場合
$ morbo myapp.pl # Mojolicious::Liteアプリの場合
@memememomo
memememomo / base.t
Created March 13, 2014 10:59
Test::Mojoで、JSONを返すAPIをテストする。 ref: http://qiita.com/uchiko/items/70c132bab5e66783e474
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Mojo;
use File::Basename;
$ENV{MOJO_HOME} = dirname(__FILE__) . '/../';
require "$ENV{MOJO_HOME}/myapp.pl";
JSON文字列に変換する + utf8フラグを外す
#include <stdio.h>
int main()
{
char buf[80];
int a, b;
fgets(buf, 80, stdin);
sscanf(buf, "%d %d", &a, &b);
@memememomo
memememomo / Poll.pm
Created April 5, 2014 19:18
Mojo::Reactor::Pollのソースを読んだときに調べたこと ref: http://qiita.com/memememomo/items/bee6630be8453a891fe1
# タイムアウト設定
$poll->poll($timeout);
# Read OKとなったハンドルに対してコールバックを実行
++$i and $self->_sandbox('Read', $self->{io}{fileno $_}{cb}, 0)
for $poll->handles(POLLIN | POLLPRI | POLLHUP | POLLERR);
# Write OKとなったハンドルに対してコールバックを実行
++$i and $self->_sandbox('Write', $self->{io}{fileno $_}{cb}, 1)
for $poll->handles(POLLOUT);
@memememomo
memememomo / basic.t
Created April 9, 2014 10:30
Test::MojoでビルドされたアプリにPhantomJSでアクセスする ref: http://qiita.com/memememomo/items/cc0ae8bb1d82be75315e
use strict;
use warnings;
use File::Basename;
use Mojo::Server::Daemon;
use Test::TCP;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('SampleApp');
@memememomo
memememomo / sample.pl
Created April 9, 2014 10:54
Perlでタイムアウトを設定して外部コマンドを実行する ref: http://qiita.com/memememomo/items/72a10e1bbe04b57f5666
use strict;
use warnings;
use POSIX qw( SIGKILL );
my $TIMEOUT = 10;
my $cmd = "sleep 15";
my $pid = fork();
if (!defined($pid)) { die "failed to fork"; }
if ($pid == 0) {
@memememomo
memememomo / parse_param.js
Last active August 29, 2015 13:58
inputのnameで配列表記されているものをjavascriptのデータ構造に変換する
var is_array = function(value) {
return value &&
typeof value === 'object' &&
typeof value.length === 'number' &&
typeof value.splice === 'function' &&
!(value.propertyIsEnumerable('length'));
}
function parse_param(params) {
var build_hash;