Skip to content

Instantly share code, notes, and snippets.

@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 / films.md
Last active February 15, 2023 06:58
@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 / memo.md
Created June 4, 2019 00:53
5日分の分量で作る

半熟のゆで卵のような「作ったその時でないと美味しくないもの」ではなく、玉子焼きのような「保存の効くもの」は、漫然と作っておくのでなく、分量を決めて作っておいたほうがいいんじゃないのかと思いついたので、その思いつきをメモ。 一律のサイズ化への過程として

const { through, duplex } = require('mississippi')
module.exports = function semaphore (
max = 1,
f = (data, index, done) => done(null, data)
) {
var current = 0
var index = 0
const buf = []
const fizz = n => n % 3 === 0 ? 'Fizz' : '';
const buzz = n => n % 5 === 0 ? 'Buzz' : '';
const test = n => ([fizz, buzz].map(f => f(n)).filter(Boolean).join(' ') || n;
for (let i = 0; i < 31; i++) console.log(`"${test(i+1)}"`)
@ishiduca
ishiduca / jsonrpc-request.json
Created July 17, 2018 03:26
jsonschema for jsonrpc2.0
{
"type": "object",
"required": true,
"additionalProperties": false,
"properties": {
"jsonrpc": {
"name": "jsonrpc",
"type": "string",
"required": true,
"enum": [