Skip to content

Instantly share code, notes, and snippets.

@ishiduca
ishiduca / fmap.js
Created April 18, 2013 01:17
ハッシュのプロパティ名(key)に関数を利用する例。使い場所ないのでここに
(function (define) {
define([], function () {
var mod = {};
mod.Fmap = function () {};
var fp = mod.Fmap.prototype;
fp.map = function (type, opt) {
if ('function' !== typeof type) {
@ishiduca
ishiduca / incr.js
Last active February 11, 2024 22:41
サーバーサイド(Node.js)とクライアントサイド(AMD/非AMD)共通のJSモジュールの定義 ref: http://qiita.com/ishiduca/items/cd6b27e80ae7c3435eb0
(function (loader) {
loader(function _commonDefine (math) {
var incr = {}; incr.increment = function (val) {
return math.add(val, 1);
};
return incr;
});
})(
// AMD RequireJS
@ishiduca
ishiduca / films.md
Last active February 15, 2023 06:58
@ishiduca
ishiduca / app.js
Last active July 26, 2022 07:46
httpResponseの処理とビジネスロジック処理を分離させるインターフェイスについて
get('/article/:id', [ 200, 'html' ], function * (args) {
var { param } = args
var { id } = param
var article = yield api.getArticle(id)
var author = yield api.getAuthor(article.author.id)
return yo`<section>
<article>${JSON.stringify(article)}</article>
<footer>${JSON.stringify(author)}</footer>
</section>`
})
@ishiduca
ishiduca / example.js
Last active July 15, 2022 00:39
http レスポンスの処理とロジックの処理を分離させたい。
get('/tanka/:id', 'html', async (datas) => {
var { param, query } = datas
var { tanka, author, created } = await api.getTanka(param.id)
return html({ body: yo`<main><h1>${tanka}</h1><p class="author">${author.name}</p></main>` })
})
get('/author/:authorId', [ 200, 'json' ], async (datas) => {
var { param, query } = datas
var author = await api.getAuthor(param.authorId)
var tankas = await api.getTankaList(author.id)
@ishiduca
ishiduca / config.js
Created September 14, 2012 06:06
Searching embedded documents in MongoDB (mongoose)
'use strict';
module.exports = function (mongoose) {
mongoose = mongoose || require('mongoose');
var note = {
type: String
, required: true
};
var created = {
type: Date
@ishiduca
ishiduca / bin.js
Created January 26, 2021 01:40
find rss atom json-feed
#!/usr/bin/env node
var find = require('./find-rss')
process.stdin(pipe(find(JSON.stringify)).pipe(process.stdout)
var yo = require('yo-yo')
var x = yo`<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-square-x" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="#2c3e50" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z"/>
<rect x="4" y="4" width="16" height="16" rx="2" />
<path d="M10 10l4 4m0 -4l-4 4" />
</svg>`
if (process.brwoser) {
document = require('global/document')
document.body.appendChild(x)
@ishiduca
ishiduca / api-callback.js
Last active May 15, 2020 01:31
JSON-RPC2.0 ライブラリーのユーザーインターフェイスはどう設計すればいいのか?
module.exports = { upper }
function upper (params, cb) {
var paraph = params.reduce((a, b) => a.concat(b.split(' ')), []).filter(Boolean)
var result = paraph.map(a => a.slice(0, 1).toUpperCase() + a.slice(1)).join(' ')
cb(null, result)
}
@ishiduca
ishiduca / gist:2280639
Created April 2, 2012 04:09
node.js http.agent の agent.maxSockets の上限を避ける その2
var events,http, url, path;
events = require('events');
http = require('http');
url = require('url');
path = require('path');
var agents = {};
agent.onSocketsLengthChange;
if (http.getAgent) {