chapters: delete old chapter samples

This commit is contained in:
Beth Griggs 2020-06-28 00:32:12 +01:00
parent 0d8170c265
commit a0906ea9ae
No known key found for this signature in database
GPG Key ID: D7062848A1AB005C
498 changed files with 0 additions and 11344 deletions

View File

@ -1,3 +0,0 @@
module.exports = (age, gap) => {
return `In ${gap} years you will be ${Number(age) + gap}<br>`
}

View File

@ -1,10 +0,0 @@
const express = require('express')
const app = express()
const past = require('./past')
const future = require('./future')
app.get('/:age', (req, res) => {
res.send(past(req.params.age, 10) + future(req.params.future, 10))
})
app.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
}
}

View File

@ -1,3 +0,0 @@
module.exports = (age, gap) => {
return `${gap} years ago you were ${Number(age) - gap}<br>`
}

View File

@ -1,11 +0,0 @@
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('hey'))
setTimeout(function myTimeout() {
console.log('I waited for you.')
}, 100)
app.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.0"
}
}

View File

@ -1,16 +0,0 @@
const util = require('util')
const express = require('express')
const debug = util.debuglog('my-app')
const app = express()
app.get('/', (req, res) => {
debug('incoming request on /', req.route)
res.send('hey')
})
setTimeout(function myTimeout() {
debug('timeout complete')
console.log('I waited for you.')
}, 100)
app.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.0"
}
}

View File

@ -1,13 +0,0 @@
const express = require('express')
const app = express()
const stylus = require('stylus')
app.get('/some.css', (req, res) => {
const css = stylus(`
body
color:black
`).render()
res.send(css)
})
app.listen(3000)

View File

@ -1,16 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.0",
"stylus": "^0.54.5"
}
}

View File

@ -1,15 +0,0 @@
const express = require('express')
const app = express()
const stylus = require('stylus')
const debug = require('debug')('my-app')
app.get('/some.css', (req, res) => {
debug('css requested')
const css = stylus(`
body
color:black
`).render()
res.send(css)
})
app.listen(3000)

View File

@ -1,17 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"debug": "^2.6.2",
"express": "^4.15.0",
"stylus": "^0.54.5"
}
}

View File

@ -1,13 +0,0 @@
const express = require('express')
const app = express()
const stylus = require('stylus')
app.get('/some.css', (req, res) => {
const css = stylus(`
body
color:black
`).render()
res.send(css)
})
app.listen(3000)

View File

@ -1,19 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.js",
"prod": "node -r pino-debug index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.0",
"pino-debug": "^1.0.3",
"stylus": "^0.54.5"
}
}

View File

@ -1,18 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.0",
"pino-debug": "^1.0.2",
"stylus": "^0.54.5"
}
}

View File

@ -1,5 +0,0 @@
function content (opts, c = 20) {
return --c ? content(opts, c) : opts.ohoh
}
module.exports = content

View File

@ -1,7 +0,0 @@
const express = require('express')
const routes = require('./routes')
const app = express()
app.use(routes)
app.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
}
}

View File

@ -1,9 +0,0 @@
const content = require('./content')
const {Router} = require('express')
const router = new Router()
router.get('/', (req, res) => {
res.send(content())
})
module.exports = router

View File

@ -1,9 +0,0 @@
function content (opts, c = 20) {
function produce (cb) {
if (--c) setTimeout(produce, 10, cb)
cb(null, opts.ohoh)
}
return produce
}
module.exports = content

View File

@ -1,10 +0,0 @@
if (process.env.NODE_ENV !== 'production') {
require('longjohn')
}
const express = require('express')
const routes = require('./routes')
const app = express()
app.use(routes)
app.listen(3000)

View File

@ -1,18 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
},
"devDependencies": {
"longjohn": "^0.2.12"
}
}

View File

@ -1,15 +0,0 @@
const content = require('./content')
const {Router} = require('express')
const router = new Router()
router.get('/', (req, res) => {
content()((err, html) => {
if (err) {
res.send(500)
return
}
res.send(html)
})
})
module.exports = router

View File

@ -1,5 +0,0 @@
function content (opts, c = 20) {
return --c ? content(opts, c) : opts.ohoh
}
module.exports = content

View File

@ -1,10 +0,0 @@
if (process.env.NODE_ENV !== 'production') {
Error.stackTraceLimit = Infinity
}
const express = require('express')
const routes = require('./routes')
const app = express()
app.use(routes)
app.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
}
}

View File

@ -1,9 +0,0 @@
const content = require('./content')
const {Router} = require('express')
const router = new Router()
router.get('/', (req, res) => {
res.send(content())
})
module.exports = router

View File

@ -1,5 +0,0 @@
function content (opts, c = 20) {
return --c ? content(opts, c) : opts.ohoh
}
module.exports = content

View File

@ -1,8 +0,0 @@
require('cute-stack')()
const express = require('express')
const routes = require('./routes')
const app = express()
app.use(routes)
app.listen(3000)

View File

@ -1,17 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cute-stack": "^1.4.3",
"express": "^4.15.2"
},
"devDependencies": {}
}

View File

@ -1,9 +0,0 @@
const content = require('./content')
const {Router} = require('express')
const router = new Router()
router.get('/', (req, res) => {
res.send(content())
})
module.exports = router

View File

@ -1,16 +0,0 @@
'use strict'
const net = require('net')
const socket = net.connect(1337, 'localhost')
const name = process.argv[2] || 'Dave'
socket.write(name)
socket.on('data', (data) => {
console.log(data.toString())
})
socket.on('close', () => {
console.log('-> disconnected by server')
})

View File

@ -1,14 +0,0 @@
'use strict'
const net = require('net')
const socket = net.connect(1337)
const name = process.argv[2] || 'Dave'
socket.write(name)
socket.pipe(process.stdout)
socket.on('close', () => {
console.log('-> disconnected by server')
})

View File

@ -1,3 +0,0 @@
'use strict'
process.stdin.pipe(require('net').connect(1338)).pipe(process.stdout)

View File

@ -1,3 +0,0 @@
'use strict'
require('net').createServer((socket) => socket.pipe(socket)).listen(1338)

View File

@ -1,13 +0,0 @@
'use strict'
const net = require('net')
net.createServer((socket) => {
console.log('-> client connected')
socket.once('data', name => {
socket.write(`Hi ${name}!`)
})
socket.on('close', () => {
console.log('-> client disconnected')
})
}).listen(1337)

View File

@ -1,13 +0,0 @@
'use strict'
const net = require('net')
net.createServer((socket) => {
console.log('-> client connected')
socket.on('data', name => {
socket.write(`Hi ${name}!`)
})
socket.on('close', () => {
console.log('-> client disconnected')
})
}).listen(1337, 'localhost')

View File

@ -1,13 +0,0 @@
'use strict'
const dgram = require('dgram')
const socket = dgram.createSocket('udp4')
const name = process.argv[2] || 'Dave'
socket.bind(1400)
socket.send(name, 1339)
socket.on('message', (data) => {
console.log(data.toString())
})

View File

@ -1,10 +0,0 @@
'use strict'
const dgram = require('dgram')
const socket = dgram.createSocket('udp4')
socket.bind(1339)
socket.on('message', (name) => {
socket.send(`Hi ${name}!`, 1400)
})

View File

@ -1,16 +0,0 @@
'use strict'
const net = require('net')
const socket = net.connect('/tmp/my.socket')
const name = process.argv[2] || 'Dave'
socket.write(name)
socket.on('data', (data) => {
console.log(data.toString())
})
socket.on('close', () => {
console.log('-> disconnected by server')
})

View File

@ -1,13 +0,0 @@
'use strict'
const net = require('net')
net.createServer((socket) => {
console.log('-> client connected')
socket.on('data', name => {
socket.write(`Hi ${name}!`)
})
socket.on('close', () => {
console.log('-> client disconnected')
})
}).listen('/tmp/my.socket')

View File

@ -1,17 +0,0 @@
'use strict'
const fs = require('fs')
const exists = (file) => new Promise((resolve, reject) => {
fs.access(file, (err) => {
if (err) {
if (err.code !== 'ENOENT') { return reject(err) }
return resolve({file, exists: false})
}
resolve({file, exists: true})
})
})
exists(process.argv[2])
.then(({file, exists}) => console.log(`"${file}" does${exists ? '' : ' not'} exist`))
.catch(console.error)

View File

@ -1,66 +0,0 @@
'use strict'
const fs = require('fs')
const path = require('path')
const tableaux = require('tableaux')
const write = tableaux(
{name: 'Name', size: 20},
{name: 'Created', size: 30},
{name: 'Inode', size: 10},
{name: 'Mode', size: 8},
{name: 'Lnks', size: 4},
{name: 'Size', size: 6}
)
function print(dir) {
fs.readdirSync(dir)
.map((file) => ({file, dir}))
.map(toMeta)
.forEach(output)
write.newline()
}
function toMeta({file, dir}) {
const stats = fs.lstatSync(path.join(dir, file))
let {birthtime, ino, mode, nlink, size} = stats
birthtime = birthtime.toUTCString()
mode = mode.toString(8)
size += 'B'
return {
file,
dir,
info: [birthtime, ino, mode, nlink, size],
isDir: stats.isDirectory(),
isSymLink: stats.isSymbolicLink()
}
}
function output({file, dir, info, isDir, isSymLink}) {
if (isSymLink) {
outputSymlink(file, dir, info)
return
}
write(file, ...info)
if (!isDir) { return }
const p = path.join(dir, file)
write.arrow()
fs.readdirSync(p).forEach((f) => {
const stats = fs.lstatSync(path.join(p, f))
const style = stats.isDirectory() ? 'bold' : 'dim'
if (stats.isSymbolicLink()) { f = '\u001b[33m' + f + '\u001b[0m'}
write[style](f)
})
write.newline()
}
function outputSymlink(file, dir, info) {
write('\u001b[33m' + file + '\u001b[0m', ...info)
process.stdout.write('\u001b[33m')
write.arrow(4)
write.bold(fs.readlinkSync(path.join(dir, file)))
process.stdout.write('\u001b[0m')
write.newline()
}
print(process.argv[2] || '.')

View File

@ -1 +0,0 @@
my-subdir/my-subsubdir/too-deep

View File

@ -1,26 +0,0 @@
'use strict'
const fs = require('fs')
const {execSync} = require('child_process')
const file = process.argv[2]
if (!file) {
console.error('specify a file')
process.exit(1)
}
try {
fs.accessSync(file)
console.error('file already exists')
process.exit(1)
} catch (e) {
makeIt()
}
function makeIt() {
const nobody = Number(execSync('id -u nobody').toString().trim())
const fd = fs.openSync(file, 'w')
fs.fchmodSync(fd, 0)
fs.fchownSync(fd, nobody, nobody)
console.log(file + ' created')
}

View File

@ -1,25 +0,0 @@
'use strict'
const fs = require('fs')
const {execSync} = require('child_process')
const file = process.argv[2]
if (!file) {
console.error('specify a file')
process.exit(1)
}
try {
fs.accessSync(file)
console.error('file already exists')
process.exit(1)
} catch (e) {
makeIt()
}
function makeIt() {
const nobody = Number(execSync('id -u nobody').toString().trim())
fs.writeFileSync(file, '')
fs.chownSync(file, nobody, nobody)
fs.chmodSync(file, 0)
console.log(file + ' created')
}

View File

@ -1,51 +0,0 @@
'use strict'
const fs = require('fs')
const path = require('path')
const tableaux = require('tableaux')
const write = tableaux(
{name: 'Name', size: 20},
{name: 'Created', size: 30},
{name: 'Inode', size: 10},
{name: 'Mode', size: 8},
{name: 'Lnks', size: 4},
{name: 'Size', size: 6}
)
function print(dir) {
fs.readdirSync(dir)
.map((file) => ({file, dir}))
.map(toMeta)
.forEach(output)
write.newline()
}
function toMeta({file, dir}) {
const stats = fs.statSync(path.join(dir, file))
let {birthtime, ino, mode, nlink, size} = stats
birthtime = birthtime.toUTCString()
mode = mode.toString(8)
size += 'B'
return {
file,
dir,
info: [birthtime, ino, mode, nlink, size],
isDir: stats.isDirectory()
}
}
function output({file, dir, info, isDir}) {
write(file, ...info)
if (!isDir) { return }
const p = path.join(dir, file)
write.arrow()
fs.readdirSync(p).forEach((f) => {
const stats = fs.statSync(path.join(p, f))
const style = stats.isDirectory() ? 'bold' : 'dim'
write[style](f)
})
write.newline()
}
print(process.argv[2] || '.')

View File

@ -1 +0,0 @@
my edit

View File

@ -1 +0,0 @@
my-file

View File

@ -1,14 +0,0 @@
{
"name": "fetching-meta-data",
"version": "1.0.0",
"description": "",
"main": "meta.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "David Mark Clements",
"license": "MIT",
"dependencies": {
"tableaux": "^1.0.1"
}
}

View File

@ -1,6 +0,0 @@
'use strict'
process.stdin.on('data', data => {
process.stderr.write(`Converting: "${data}" to base64\n`)
process.stdout.write(data.toString('base64') + '\n')
})

View File

@ -1,4 +0,0 @@
'use strict'
const encode = require('base64-encode-stream')
process.stdin.pipe(encode()).pipe(process.stdout)

View File

@ -1,16 +0,0 @@
{
"name": "piping",
"version": "1.0.0",
"main": "base64.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "David Mark Clements",
"license": "MIT",
"dependencies": {
"base64-encode-stream": "^1.0.0"
},
"devDependencies": {},
"keywords": [],
"description": ""
}

View File

@ -1 +0,0 @@
back again

View File

@ -1,15 +0,0 @@
{
"name": "watching-files-and-directories",
"version": "1.0.0",
"description": "",
"main": "watcher.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "David Mark Clements",
"license": "MIT",
"dependencies": {
"human-time": "0.0.1"
}
}

View File

@ -1,44 +0,0 @@
'use strict'
const fs = require('fs')
const human = require('human-time')
const interval = 5007
const file = process.argv[2]
let exists = false
if (!file) {
console.error('supply a file')
process.exit(1)
}
const created = ({birthtime}) =>
!exists && (Date.now() - birthtime) < interval
const missing = ({birthtime, mtime, atime, ctime}) =>
!(birthtime|mtime|atime|ctime)
const updated = (cur, prv) => cur.mtime !== prv.mtime
fs.watchFile(file, {interval}, (cur, prv) => {
if (missing(cur)) {
const msg = exists ? 'removed' : 'doesn\'t exist'
exists = false
return console.log(`${file} ${msg}`)
}
if (created(cur)) {
exists = true
return console.log(`${file} created ${human((cur.birthtime))}`)
}
exists = true
if (updated(cur, prv)) {
return console.log(`${file} updated ${human((cur.mtime))}`)
}
console.log(`${file} modified ${human((cur.mtime))}`)
})

View File

@ -1,16 +0,0 @@
{
"name": "watching-with-chokidar",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "David Mark Clements",
"license": "MIT",
"dependencies": {
"chokidar": "^1.6.0",
"human-time": "0.0.1"
}
}

View File

@ -1,28 +0,0 @@
'use strict'
const chokidar = require('chokidar')
const human = require('human-time')
const watcher = chokidar.watch(process.argv[2] || '.', {
alwaysStat: true
})
watcher.on('ready', () => {
watcher
.on('add', (file, stat) => {
console.log(`${file} created ${human((stat.birthtime))}`)
})
.on('unlink', (file) => {
console.log(`${file} removed`)
})
.on('change', (file, stat) => {
const msg = (+stat.ctime === +stat.mtime) ? 'updated' : 'modified'
console.log(`${file} ${msg} ${human((stat.ctime))}`)
})
.on('addDir', (dir, stat) => {
console.log(`${dir} folder created ${human((stat.birthtime))}`)
})
.on('unlinkDir', (dir) => {
console.log(`${dir} folder removed`)
})
})

File diff suppressed because one or more lines are too long

View File

@ -1,22 +0,0 @@
Wed Jun 08 2016 22:53:26 GMT+0100 (BST) 896961 bytes removed
Wed Jun 08 2016 22:54:14 GMT+0100 (BST) 896961 bytes removed
Wed Jun 08 2016 22:54:25 GMT+0100 (BST) 896961 bytes removed
Wed Jun 08 2016 22:54:30 GMT+0100 (BST) 896961 bytes removed
Wed Jun 08 2016 22:54:36 GMT+0100 (BST) 896961 bytes removed
Wed Jun 08 2016 22:54:41 GMT+0100 (BST) 896961 bytes removed
Wed Jun 08 2016 22:54:59 GMT+0100 (BST) 10000000 bytes removed
Wed Jun 08 2016 22:56:01 GMT+0100 (BST) 100000000 bytes removed
Wed Jun 08 2016 22:57:07 GMT+0100 (BST) 897494 bytes removed
Wed Jun 08 2016 22:57:23 GMT+0100 (BST) 10000000 bytes removed
Wed Jun 08 2016 22:57:32 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 22:57:34 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 22:57:35 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 22:58:21 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 22:59:03 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:03:21 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:03:56 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:04:14 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:04:40 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:04:45 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:50:48 GMT+0100 (BST) 897432 bytes removed
Wed Jun 08 2016 23:50:50 GMT+0100 (BST) 897432 bytes removed

View File

@ -1,16 +0,0 @@
'use strict'
setInterval(() => process.stdout.write('.'), 10).unref()
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
const bytes = fs.readFileSync(path.join(cwd, 'file.dat'))
const clean = bytes.filter(n => n)
fs.writeFileSync(path.join(cwd, 'clean.dat'), clean)
fs.appendFileSync(
path.join(cwd, 'log.txt'),
(new Date) + ' ' + (bytes.length - clean.length) + ' bytes removed\n'
)

View File

@ -1,19 +0,0 @@
'use strict'
setInterval(() => process.stdout.write('.'), 10).unref()
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
fs.readFile(path.join(cwd, 'file.dat'), (err, bytes) => {
if (err) { console.error(err); process.exit(1); }
const clean = bytes.filter(n => n)
fs.writeFile(path.join(cwd, 'clean.dat'), clean, (err) => {
if (err) { console.error(err); process.exit(1); }
fs.appendFile(
path.join(cwd, 'log.txt'),
(new Date) + ' ' + (bytes.length - clean.length) + ' bytes removed\n'
)
})
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,4 +0,0 @@
Wed Jun 08 2016 23:48:13 GMT+0100 (BST) 896977 bytes removed
Wed Jun 08 2016 23:48:17 GMT+0100 (BST) 896977 bytes removed
Wed Jun 08 2016 23:49:25 GMT+0100 (BST) 896977 bytes removed
Wed Jun 08 2016 23:50:17 GMT+0100 (BST) 896977 bytes removed

View File

@ -1,23 +0,0 @@
'use strict'
setInterval(() => process.stdout.write('.'), 10).unref()
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
const sbs = require('strip-bytes-stream')
fs.createReadStream(path.join(cwd, 'file.dat'))
.pipe(sbs((n) => n))
.on('end', function () { log(this.total) })
.pipe(fs.createWriteStream(path.join(cwd, 'clean.dat')))
function log(total) {
fs.appendFile(
path.join(cwd, 'log.txt'),
(new Date) + ' ' + total + ' bytes removed\n'
)
}

View File

@ -1,14 +0,0 @@
{
"name": "piping",
"version": "1.0.0",
"description": "",
"main": "null-byte-remover.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "David Mark Clements",
"license": "MIT",
"dependencies": {
"strip-bytes-stream": "^1.1.0"
}
}

View File

@ -1,6 +0,0 @@
Wed Jun 08 2016 22:56:41 GMT+0100 (BST) 100000000 bytes removed
Wed Jun 08 2016 22:56:54 GMT+0100 (BST) 897090 bytes removed
Wed Jun 08 2016 22:58:02 GMT+0100 (BST) 897090 bytes removed
Wed Jun 08 2016 22:58:03 GMT+0100 (BST) 897090 bytes removed
Wed Jun 08 2016 22:58:15 GMT+0100 (BST) 897090 bytes removed
Wed Jun 08 2016 22:59:08 GMT+0100 (BST) 897090 bytes removed

View File

@ -1,15 +0,0 @@
'use strict'
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
const bytes = fs.readFileSync(path.join(cwd, 'file.dat'))
const clean = bytes.filter(n => n)
fs.writeFileSync(path.join(cwd, 'clean.dat'), clean)
fs.appendFileSync(
path.join(cwd, 'log.txt'),
(new Date) + ' ' + (bytes.length - clean.length) + ' bytes removed\n'
)

View File

@ -1,21 +0,0 @@
'use strict'
const express = require('express')
const app = express()
app.get('/', (req, res) => {
pretendDbQuery(() => {
var msg = req.query.msg
if (Array.isArray(msg)) msg = msg.pop()
const yelling = (msg || '').toUpperCase()
res.send(yelling)
})
})
app.listen(3000)
function pretendDbQuery (cb) {
setTimeout(cb, 0)
}

View File

@ -1,17 +0,0 @@
'use strict'
const express = require('express')
const app = express()
app.get('/', (req, res) => {
pretendDbQuery(() => {
const yelling = (req.query.msg || '').toUpperCase()
res.send(yelling)
})
})
app.listen(3000)
function pretendDbQuery (cb) {
setTimeout(cb, 0)
}

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
}
}

View File

@ -1,87 +0,0 @@
'use strict'
const http = require('http')
const server = http.createServer((req, res) => {
if (req.method === 'GET') {
res.setHeader('Content-Type', 'text/html')
if (req.url === '/') return res.end(html())
res.setHeader('Content-Type', 'application/json')
if (req.url === '/friends') return res.end(friends())
return
}
if (req.method === 'POST') {
if (req.url === '/') return action(req, res)
}
})
function html (res) {
return `
<div id=friends></div>
<form>
<input id=friend> <input type=submit value="Add Friend">
</form>
<script>
void function () {
var friend = document.getElementById('friend')
var friends = document.getElementById('friends')
function load () {
fetch('/friends', {
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
}
}).catch((err) => console.error(err))
.then((res) => res.json())
.then((arr) => friends.innerHTML = arr.map((f) => atob(f)).join('<br>'))
}
load()
document.forms[0].addEventListener('submit', function () {
fetch('/', {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({cmd: 'add', friend: friend.value})
}).catch((err) => console.error(err))
.then(load)
})
}()
</script>
`
}
function friends () {
return JSON.stringify(friends.list)
}
friends.list = [Buffer.from('Dave').toString('base64')]
friends.add = (friend) => {
friends.list.push(Buffer.from(friend).toString('base64'))
}
function action (req, res) {
var data = ''
req.on('data', (chunk) => data += chunk)
req.on('end', () => {
try {
data = JSON.parse(data)
} catch (e) {
console.error(e)
res.end('{"ok": false}')
return
}
if (data.cmd === 'add') {
try {
friends.add(data.friend)
} catch (e) {
console.error(e)
res.end('{"ok": false}')
}
}
})
}
server.listen(3000)

View File

@ -1,80 +0,0 @@
'use strict'
const http = require('http')
const server = http.createServer((req, res) => {
if (req.method === 'GET') {
res.setHeader('Content-Type', 'text/html')
if (req.url === '/') return res.end(html())
res.setHeader('Content-Type', 'application/json')
if (req.url === '/friends') return res.end(friends())
return
}
if (req.method === 'POST') {
if (req.url === '/') return action(req, res)
}
})
function html (res) {
return `
<div id=friends></div>
<form>
<input id=friend> <input type=submit value="Add Friend">
</form>
<script>
void function () {
var friend = document.getElementById('friend')
var friends = document.getElementById('friends')
function load () {
fetch('/friends', {
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
}
}).catch((err) => console.error(err))
.then((res) => res.json())
.then((arr) => friends.innerHTML = arr.map((f) => atob(f)).join('<br>'))
}
load()
document.forms[0].addEventListener('submit', function () {
fetch('/', {
method: 'post',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({cmd: 'add', friend: friend.value})
}).catch((err) => console.error(err))
.then(load)
})
}()
</script>
`
}
function friends () {
return JSON.stringify(friends.list)
}
friends.list = [Buffer('Dave').toString('base64')]
friends.add = (friend) => friends.list.push(Buffer(friend).toString('base64'))
function action (req, res) {
var data = ''
req.on('data', (chunk) => data += chunk)
req.on('end', () => {
try {
data = JSON.parse(data)
} catch (e) {
res.end('{"ok": false}')
return
}
if (data.cmd === 'add') {
friends.add(data.friend)
}
res.end('{"ok": true}')
})
}
server.listen(3000)

View File

@ -1,78 +0,0 @@
'use strict'
const http = require('http')
const Ajv = require('ajv')
const ajv = new Ajv
const schema = {
title: 'UserReg',
properties: {
id: {type: 'integer'},
name: {type: 'string'},
privileges: {
anyOf: [
{type: 'string'},
{type: 'boolean'},
{type: 'array', items: {type: 'string'}},
{type: 'object'}
]
}
},
additionalProperties: false,
required: ['id', 'name']
}
const validate = ajv.compile(schema)
const {STATUS_CODES} = http
const server = http.createServer((req, res) => {
if (req.method !== 'POST') {
res.statusCode = 404
res.end(STATUS_CODES[res.statusCode])
return
}
if (req.url === '/register') {
register(req, res)
return
}
res.statusCode = 404
res.end(STATUS_CODES[res.statusCode])
})
function register (req, res) {
var data = ''
req.on('data', (chunk) => data += chunk)
req.on('end', () => {
try {
data = JSON.parse(data)
} catch (e) {
res.end('{"ok": false}')
return
}
const valid = validate(data, schema)
if (!valid) {
console.error(validate.errors)
res.end('{"ok": false}')
return
}
if (data.hasOwnProperty('privileges')) {
createAdminUser(data)
res.end('{"ok": true, "admin": true}')
} else {
createUser(data)
res.end('{"ok": true, "admin": false}')
}
})
}
function createAdminUser (user) {
const key = user.id + user.name
// ...
}
function createUser (user) {
// ...
}
server.listen(3000)

View File

@ -1,53 +0,0 @@
'use strict'
const http = require('http')
const {STATUS_CODES} = http
const server = http.createServer((req, res) => {
if (req.method !== 'POST') {
res.statusCode = 404
res.end(STATUS_CODES[res.statusCode])
return
}
if (req.url === '/register') {
register(req, res)
return
}
res.statusCode = 404
res.end(STATUS_CODES[res.statusCode])
})
function register (req, res) {
var data = ''
req.on('data', (chunk) => data += chunk)
req.on('end', () => {
try {
data = JSON.parse(data)
} catch (e) {
res.end('{"ok": false}')
return
}
// privileges can be multiple types, boolean, array, object, string,
// but the presence of the key means the user is an admin
if (data.hasOwnProperty('privileges')) {
createAdminUser(data)
res.end('{"ok": true, "admin": true}')
} else {
createUser(data)
res.end('{"ok": true, "admin": false}')
}
})
}
function createAdminUser (user) {
const key = user.id + user.name
// ...
}
function createUser (user) {
// ...
}
server.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "json-validation",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ajv": "^4.11.5"
}
}

View File

@ -1,4 +0,0 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.7.0
ignore: {}
patch: {}

View File

@ -1,19 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"audit": "auditjs"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
},
"devDependencies": {
"auditjs": "^2.0.2"
}
}

View File

@ -1,32 +0,0 @@
'use strict'
const express = require('express')
const app = express()
app.get('/', (req, res) => {
const {prev = '', handoverToken = '', lang = 'en'} = req.query
pretendDbQuery((err, status) => {
if (err) {
res.sendStatus(500)
return
}
res.send(`
<h1>Current Status</h1>
<div id=stat>
${status}
</div>
<div>
<a href="${prev}${handoverToken}/${lang}"> Back to Control HQ </a>
</div>
`)
})
})
function pretendDbQuery (cb) {
const status = 'ON FIRE!!! HELP!!!'
cb(null, status)
}
app.listen(3000)

View File

@ -1,15 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2"
}
}

View File

@ -1,34 +0,0 @@
'use strict'
const express = require('express')
const he = require('he')
const app = express()
app.get('/', (req, res) => {
const {prev = '', handoverToken = '', lang = 'en'} = req.query
pretendDbQuery((err, status) => {
if (err) {
res.sendStatus(500)
return
}
const href = he.encode(`${prev}${handoverToken}/${lang}`)
res.send(`
<h1>Current Status</h1>
<div id=stat>
${he.escape(status)}
</div>
<br>
<a href="${href}"> Back to Control HQ </a>
`)
})
})
function pretendDbQuery (cb) {
const status = 'ON FIRE!!! HELP!!!'
cb(null, status)
}
app.listen(3000)

View File

@ -1,16 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.2",
"he": "^1.1.1"
}
}

View File

@ -1,33 +0,0 @@
'use strict'
const express = require('express')
const escapeHtml = require('escape-html')
const app = express()
app.get('/', (req, res) => {
const {prev = '', handoverToken = '', lang = 'en'} = req.query
pretendDbQuery((err, status) => {
if (err) {
res.sendStatus(500)
return
}
const href = escapeHtml(`/${prev}${handoverToken}/${lang}`)
res.send(`
<h1>Current Status</h1>
<div id=stat>
${escapeHtml(status)}
</div>
<br>
<a href="${href}"> Back to Control HQ </a>
`)
})
})
function pretendDbQuery (cb) {
const status = 'ON FIRE!!! HELP!!!'
cb(null, status)
}
app.listen(3000)

View File

@ -1,17 +0,0 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"escape-html": "^1.0.3",
"express": "^4.15.2",
"he": "^1.1.1"
}
}

Some files were not shown because too many files have changed in this diff Show More