Quiz: https://mobile.twitter.com/wesbos/status/794211901685149696
Explanation: http://www.2ality.com/2015/01/es6-destructuring.html#default-values
The key rules of this model are:
// inline type declaration for ES6 Promise object | |
// see full at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/es6-promise/es6-promise.d.ts | |
declare class Promise { | |
constructor(callback: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void); | |
then(onFulfilled?: (any) => any, onRejected?: (any) => any|void); | |
} | |
const isPromise: (p:any) => boolean = p => typeof p === 'object' && typeof p.then === 'function'; | |
const promiseAll: (promises:any[]) => Promise = promises => new Promise((resolve, reject) => { |
With angular-cli, it helps create an angular2 app quickly. All required tools are provisioned in a simple command ng new
, including Protractor - the end-to-end testing tool for angular.
To perform the testing, run ng e2e
. It will first run webdriver-manager update
to download & install webdrivers, see pree2e
script in package.json.
However, the below error may be encountered if you are in a corporate network:
[15:10:59] E/downloader - { Error: unable to get local issuer certificate
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1060:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
// A custom property on an array is **not iterable** | |
const arr = [1,2]; | |
arr[10] = 10; // => [1, 2, undefined*8, 10] | |
arr['ok'] = 'ok'; | |
// for-in: enumerable properties: | |
for (const index in arr) console.log(arr[index]); // => 1, 2, 10, 'ok' | |
// for-of: iterable | |
for (const value of arr) console.log(value); // => 1, 2, undefined*8, 10 |
brew install tmux
Run tmux -CC
or tmux -CC attach
in iTerm2 and then menu is shown on terminal:
#!/bin/bash | |
# try to kill existing process | |
ps aux | awk '/[s]sh -D 7070/ {print $2}' | xargs kill | |
# delay 1s | |
sleep 1 | |
# start SOCKS proxy | |
ssh -D 7070 -fN user@host |
In order to keep a page up-to-date or simulate notification push, we can fetching data from server by sending requests (eg. ajax) periodically. This is so-called polling, but this will cause security risks that session never timeout.
It's not easy to fix this issue with a simple configuration in web server (eg. Tomcat),