Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / app.js
Created September 19, 2014 09:40
use Domain in 'carom.js app'
var app = Object.create(require('carom.js')).constructor()
function onError (err, req, res) {
console.error(err)
console.error(err.stack)
res.writeHead(500)
res.end(String(err))
}
@ishiduca
ishiduca / index.html
Created September 28, 2014 07:28
ractivate で ractive.js を brwoserify に対応させる
<!doctype html>
<head>
<meta charset="utf-8" />
<title>Ractiv.ate</title>
<head>
<body>
<div id="main"></div>
<script src="./bundle.js"></script>
</body>
@ishiduca
ishiduca / semaphore-stream.js
Created October 16, 2014 08:12
streamでセマフォ?
var util = require('util')
var stream = require('stream')
var semaphore = require('semaphore')
function SemaphoreStream (count, option) {
stream.Duplex.call(this, (option || {}))
this.semaphore = semaphore(count)
this.finished = false