Skip to content

Instantly share code, notes, and snippets.

@ishiduca
ishiduca / gist:1321875
Created October 28, 2011 08:33
λ式をPerlで表現するメモ
#!/usr/bin/env perl -l
use strict;
use warnings;
# fx:=x+1;
sub f {
local $_ = shift;
$_+1;
}
print f(3);
@ishiduca
ishiduca / gist:1321878
Created October 28, 2011 08:34
メモ化のデモ
#!/usr/bin/env perl -l
use strict;
use warnings;
sub memorize {
my $fib = shift;
my @list = ();
sub {
local $_ = shift;
$list[$_] or $list[$_] = $fib->($_);
@ishiduca
ishiduca / gist:1326939
Created October 31, 2011 04:58
MacOSX 10.6.8 に Mecab && Text::MeCab インストールのメモ
MeCabインストールメモ
$HOME に MeCab をインストールする
※ [参照] [http://kawa.at.webry.info/201110/article_2.html:title=形態素解析 MeCab を Perl モジュール Text::MeCab から使う Kawanet Tech Blog/ウェブリブログ]
----
1. MeCab本体: http://downloads.sourceforge.net/project/mecab/mecab/0.98/mecab-0.98.tar.gz
2. MeCab辞書: http://downloads.sourceforge.net/project/mecab/mecab-ipadic/2.7.0-20070801/mecab-ipadic-2.7.0-20070801.tar.gz
3. PerlのMeCabドライバ(Text::MeCab):
----
@ishiduca
ishiduca / gist:1336597
Created November 3, 2011 14:21
AnyEvent上でdlのテスト
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use AnyEvent;
use AnyEvent::HTTP;
use Config::Pit;
use Web::Scraper;
use File::Basename;
@ishiduca
ishiduca / gist:1366140
Created November 15, 2011 04:28
FriendFeed に AnyEvent 文脈で いろいろポストする
package MyApp::AnyEvent::FriendFeed;
use strict;
use warnings;
use Carp;
use AnyEvent;
use AnyEvent::HTTP;
use MIME::Base64;
use HTTP::Request::Common;
use HTTP::Request;
@ishiduca
ishiduca / gist:1369669
Created November 16, 2011 09:23
ラムダ(あとで消す)
if (! Array.prototype.filter) {
Array.prototype.filter = function (patternFunc) {
var helper = function (thisArray, newArray) {
if (! newArray) newArray = [];
if (thisArray && thisArray.length > 0) {
var el = thisArray.shift();
if (patternFunc(el)) newArray.push(el);
return helper(thisArray, newArray);
}
@ishiduca
ishiduca / gist:1403579
Created November 29, 2011 05:36
EventEmitterでイベントハンドラー ;; 3の付く数字と3の倍数の時だけアホになるタイマー
var EvEm = require('events').EventEmitter;
function Timer (interval, defaultFunc) {
this.count = 0;
this.interval = interval || 1000; // 1秒デフォルト
this.eventsList = {};
this.default = defaultFunc || function (c) { console.log(c); };
};
(function (_tp) {
@ishiduca
ishiduca / gist:1415207
Created December 1, 2011 09:08
食べログ API を AnyEvent文脈で 使う
package AnyEvent::Tabelog::Search;
use strict;
use utf8;
use Carp;
use URI;
use AnyEvent;
use AnyEvent::HTTP qw(http_request);
use XML::Simple;
our $VERSION = '0.01';
@ishiduca
ishiduca / gist:1438022
Created December 6, 2011 12:23
自前 fold & foldr で合成関数
#!/usr/bin/env perl -l
use strict;
use warnings;
use Data::Dumper;
sub fold {
my $f = shift;
my $res = shift;
my @rest = @_;
@ishiduca
ishiduca / gist:1492449
Created December 18, 2011 05:19
任意の順番で「+5」か「*3」して、任意の値にする過程を示す 初期値は「1」
function findSequence (goal) {
var find = function (start, history) {
return (start === goal) ? history :
(start > goal) ? null :
find(start + 5, "(" + history + " + 5)") ||
find(start * 3, "(" + history + " * 3)");
};
return find(1, '1');
}