Skip to content

Instantly share code, notes, and snippets.

@sekia
sekia / scrape_colordic.pl
Created November 19, 2011 22:47
Scrapes table of japanese traditional colors on colordic.org and dumps color name / RGB value mappings as YAML
#!/usr/bin/env perl
use 5.014;
use strict;
use warnings;
use Carp;
use Encode;
use Furl;
use Web::Scraper;
use YAML::Any;
@sekia
sekia / shift_heading_level.pl
Created November 23, 2011 09:20
Reads HTML and shifts its heading level
#!/usr/bin/env perl
use 5.014;
use warnings;
use opts;
use HTML::TreeBuilder;
use HTML::TreeBuilder::XPath;
use Pod::Usage;
opts my $help => +{ isa => 'Bool', default => 0 },
use v6;
sub mapBetween(@list, &fn) {
sub infix:<op>($a, $b) { &fn($a, $b) };
@list <<op<< @list[1..*];
}
say mapBetween([1..5], &[+]); # 3 5 7 9
@sekia
sekia / dump_mixi_diary.pl
Created February 19, 2012 10:29
Dumps mixi diaries out to a YAML file.
#!/usr/bin/env perl
use 5.014;
use strict;
use warnings;
use opts;
use Encode;
use File::HomeDir;
use Path::Class;
use Storable qw/dclone/;
@sekia
sekia / pika.pl
Created March 6, 2012 09:46
ピカチュウっぽいセリフの正規表現を作るスクリプト ref: http://qiita.com/items/3030
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Regexp::Optimizer;
=for comment
Output:
@sekia
sekia / file1.txt
Created June 14, 2012 12:44
リストの要素数を数えるコードの速度比較 ref: http://qiita.com/items/5a00636dbf812722c959
Rate empty_assign array anon_array grep alias
empty_assign 7.68/s -- -2% -10% -17% -39%
array 7.84/s 2% -- -9% -15% -37%
anon_array 8.57/s 12% 9% -- -7% -31%
grep 9.21/s 20% 18% 8% -- -26%
alias 12.5/s 63% 60% 46% 36% --
@sekia
sekia / markov.go
Created June 16, 2012 14:21
マルコフ連鎖を使った文章生成サンプル ref: http://qiita.com/items/0fb1730607db04dcff49
package main
import (
"bufio"
"errors"
"fmt"
"io"
"log"
"math/rand"
"os"
@sekia
sekia / bl.pl
Created July 2, 2012 08:33
bl コマンド
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Curses;
use Getopt::Long;
use POSIX;
use Time::HiRes qw/usleep/;
@sekia
sekia / AnyEvent-Groonga-0.07.diff
Created July 4, 2012 11:31
A patch for AnyEvent::Groonga 0.07
diff --git a/lib/AnyEvent/Groonga.pm b/lib/AnyEvent/Groonga.pm
index 6d57c95..d068b64 100644
--- a/lib/AnyEvent/Groonga.pm
+++ b/lib/AnyEvent/Groonga.pm
@@ -127,7 +127,7 @@ sub _post_to_http_server {
my $json = shift;
my $result;
try {
- my $data = JSON->new->utf8(0)->decode($json);
+ my $data = JSON->new->utf8->decode($json);
@sekia
sekia / index.html
Created July 28, 2012 15:27
WebSocket echo server
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script>
var status = "LOADING";
var connectedSock;
document.onreadystatechange = function() {
if (document.readyState != 'complete') { return; }