🚩 TODO Explain some ES6 language features
Node 5 is awesome! <3 By default, it comes with lots of ES6 features.
Among them are, for example, arrow functions. And there's the spread operator which, in combination with the arguments object, makes writing a promisify()
function beautifully simple:
function promisify (foo) {
return function () {
Live example: http://codepen.io/abk955/pen/YwQmMJ
1. Creating the clock structure (in Jade
)
- The countdown clock is supposed to display seconds, minutes, hours and days.
This file contains 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 | |
/* Usage: node file-gen [mb] | |
* | |
* Example: Generate a 1 GB file | |
* $ node file-gen 1024 | |
* time: 9163.383ms | |
*/ | |
const fs = require('fs') |
This file contains 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
@ECHO off | |
:: delete all upgrade logs | |
:: >nul 2>&1 = drop stdout and stderr output | |
DEL UpgradeLog*.htm >nul 2>&1 | |
:: loop over all backup directories | |
FOR /d %%G IN (Backup*) DO ( | |
:: /s = remove all sub directories, too | |
:: /q = remove quietly, without confirmation |
This file contains 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
const http = require('http') | |
const url = require('url') | |
const apiPort = 3000 | |
const proxyPort = 3001 | |
const apiResStatus = 200 | |
const apiResBody = `"Hi, I'm the API!"` | |
const clientReqMethod = 'GET' |
This file contains 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
const { Readable } = require('stream') | |
const charArray = 'abcdefghijklmnopqrstuvwxyz'.split('') | |
class AlphabetStream extends Readable { | |
constructor () { | |
super() | |
this.position = 0 | |
} |
This file contains 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
docker ps -a -q | xargs -r docker rm -f | |
docker images -a -q | xargs -r docker rmi -f |
This file contains 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
$code = { | |
param ($id) | |
$start = Get-Date | |
# your code here | |
Start-Sleep 1 | |
$stop = Get-Date | |
$total = ($stop - $start).TotalMilliSeconds | |
"[$id] $total ms" | |
} |
OlderNewer