Test code from http://stackoverflow.com/questions/17589178/why-should-i-use-restify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# npm install -g yamljs json-schema-generator | |
# json-pretty came from [here](https://gist.github.com/CatTail/fc172a7fe6f300528665e279592c6500) | |
cat "${1:-/dev/stdin}" | json-pretty | json-schema-generator | tail -n +2 | json2yaml -d 10 - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app._router.stack // registered routes | |
.filter(r => r.route) // take out all the middleware | |
.map(r => r.route.path) // get all the paths |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
const chunks = [] | |
process.stdin.setEncoding('utf8') | |
process.stdin.on('readable', () => { | |
const chunk = process.stdin.read() | |
if (chunk) { | |
chunks.push(chunk) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function repeat(str, count) { | |
return (new Array(count + 1)).join(str) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node test.js | |
at Object.<anonymous> (/Users/cattail/workspace/upyun/choppe/test.js:3:9) hello | |
at Object.<anonymous> (/Users/cattail/workspace/upyun/choppe/test.js:5:9) world |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const dgram = require('dgram') | |
const Packet = require('native-dns-packet') | |
const server = dgram.createSocket('udp4', (msg, rinfo) => { | |
console.log(rinfo) | |
console.log(msg, Buffer.byteLength(msg)) | |
console.log(bufferToString(msg, 16, 1, 2)) | |
console.log(Packet.parse(msg)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const MAP = { | |
'A': '.-', | |
'B': '-...', | |
'C': '-.-.', | |
'D': '-..', | |
'E': '.', | |
'F': '..-.', | |
'G': '--.', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wrap async function to use as express middleware or route | |
// let wrap = fn => (...args) => fn(...args).catch(args[2]) | |
function wrapRoute(fn) { | |
return function () { | |
return fn.apply(undefined, arguments) | |
.catch(arguments[arguments.length - 1]); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
PROGRAM_NAME="choppe" | |
PROGRAM="node app.js" | |
function getpid() | |
{ | |
ps aux | grep "$PROGRAM" | grep -v grep | awk '{ print $2 }' | |
} |