chapters: delete old chapter samples
This commit is contained in:
@@ -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')
|
||||
})
|
||||
@@ -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')
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
process.stdin.pipe(require('net').connect(1338)).pipe(process.stdout)
|
||||
@@ -1,3 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
require('net').createServer((socket) => socket.pipe(socket)).listen(1338)
|
||||
@@ -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)
|
||||
@@ -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')
|
||||
@@ -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())
|
||||
})
|
||||
@@ -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)
|
||||
})
|
||||
@@ -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')
|
||||
})
|
||||
@@ -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')
|
||||
@@ -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)
|
||||
@@ -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] || '.')
|
||||
@@ -1 +0,0 @@
|
||||
/tmp
|
||||
@@ -1 +0,0 @@
|
||||
my-symlink
|
||||
@@ -1 +0,0 @@
|
||||
my edit
|
||||
-1
@@ -1 +0,0 @@
|
||||
another-file
|
||||
@@ -1 +0,0 @@
|
||||
my-file
|
||||
@@ -1 +0,0 @@
|
||||
../meta.js
|
||||
@@ -1 +0,0 @@
|
||||
my-subdir/my-subsubdir/too-deep
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
@@ -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] || '.')
|
||||
@@ -1 +0,0 @@
|
||||
my edit
|
||||
@@ -1 +0,0 @@
|
||||
my-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"
|
||||
}
|
||||
}
|
||||
@@ -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')
|
||||
})
|
||||
@@ -1,4 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const encode = require('base64-encode-stream')
|
||||
process.stdin.pipe(encode()).pipe(process.stdout)
|
||||
@@ -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": ""
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
back again
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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))}`)
|
||||
})
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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
Binary file not shown.
@@ -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
|
||||
-16
@@ -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'
|
||||
)
|
||||
@@ -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
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -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
|
||||
@@ -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'
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user