Skip to content

Instantly share code, notes, and snippets.

@ishiduca
ishiduca / coro1.pl
Created September 4, 2014 09:41
study coro
use strict;
use warnings;
use Coro;
my $n = 0;
async {
print "async 1 - $n\n";
$n++;
cede;
@ishiduca
ishiduca / Timer.js
Created August 27, 2014 05:44
Stream.Readable で インターバルタイマー
'use strict'
var stream = require('stream')
var util = require('util')
var types = {
'"timeout" must be "Number"': function (n) { return isNaN(n) }
, '"timeout" must be "Int".': function (n) { return (n + '').indexOf('.') !== -1 }
, '"timeout" must be over "0".': function (n) { return n < 0 }
}
function Timer (timeout, _opt) {
@ishiduca
ishiduca / index.js
Created June 19, 2014 04:41
循環参照を含むオブジェクトのJSON.stringify
;(function (global) {
'use strict'
var isBrowser = !! global.self
var isWorker = !! global.workerLocation
var isNodeJS = !! global.global
function stringify (o, rep, sp) {
return JSON.stringify(o, (function (m) {
return function (key, val) {
if (val instanceof Error) return val.toString()
@ishiduca
ishiduca / custom_error_test.js
Created May 8, 2014 06:38
CustomError(Error)の継承
var test = require('tape')
test('01', function (t) {
function MyError (message) {
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor)
} else {
this.stack = (new Error).stack || ''
}
this.name = this.constructor.name
this.message = message || this.name
@ishiduca
ishiduca / domain.js
Created April 19, 2014 01:24
第一引数にエラーが渡されるコールバック関数からエラー処理を退避させる ref: http://qiita.com/ishiduca/items/58459548a9c9bf5b6f0a
;(function (global) {
'use strict'
var isBrowser = !! global.self
var isWorker = !! global.WorkerLocation
var isNodeJS = !! global.global
function Domain () {}
Domain.prototype.intercept = function (cb, she) {
@ishiduca
ishiduca / HTTPClient.pm
Last active August 29, 2015 13:57
HTTPClient based Tatusmaki::HTTPClient
package Moco::Moco::HTTPClient;
use Moo;
use MooX::late;
use Moco::Moco;
use AnyEvent::HTTP;
extends qw(Tatsumaki::HTTPClient);
has agent => ( is => 'rw', isa => 'Str', default => sub { join '/', __PACKAGE__ , $Moco::Moco::VERSION });
has jar => ( is => 'rw', isa => 'HashRef', default => sub { +{version => 1} });
@ishiduca
ishiduca / bad_practice.html
Last active August 29, 2015 13:56
Ractive.js で ハッシュをリスト展開して表示するベストプラクティスを教えて下さい ref: http://qiita.com/ishiduca/items/b893063a9bc259a47808
<!doctype html>
<head>
<title>Ractive.js - hash to list</title>
<script src="../bower_components/ractive/Ractive.js"></script>
</head>
<body>
<main id="main">
<script id="template" type="text/ractive">
<h2>ハッシュのリスト表示</h2>
@ishiduca
ishiduca / m.pl
Last active January 4, 2016 08:08
カレントディレクトリ内の .checks ファイルに書かれた項目の出現回数を表示する
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use File::Slurp qw(read_file);
my %index = ();
while (<*>) {
if (/\.checks$/) {
package Greeter;
use 5.008005;
use strict;
use Carp;
our $VERSION = "0.01";
sub new {
my $class = shift;
bless +{} => $class;
@ishiduca
ishiduca / file0.js
Last active December 31, 2015 02:58
elementTarget.addEventListener の復習 ref: http://qiita.com/ishiduca/items/12f10b95da9faf157aea
elementTarget.addEventListener( type, listener [, useCapture ])