const date = new Date(2012, 11, 20, 3, 0, 0)
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
/* | |
* CHALLANGE: | |
* Cache `index.html` file using service worker. | |
* | |
* This bit of code is included in <script> tag of index.html | |
* if (navigator.serviceWorker) { | |
* navigator.serviceWorker.register('serviceworker.js', {scope: '/'}) | |
* } | |
* | |
*/ |
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
/* | |
This module creates an HTTPS web server and serves static content | |
from a specified directory on a specified port. | |
To generate a new cert: | |
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 | |
To remove the passphrase requirement: |
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 deltaDate(input, days, months, years) { | |
return new Date( | |
input.getFullYear() + years, | |
input.getMonth() + months, | |
Math.min( | |
input.getDate() + days, | |
new Date( | |
input.getFullYear() + years, | |
input.getMonth() + months + 1, | |
0 |
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
// src: https://github.com/LeCoupa/awesome-cheatsheets | |
// Date Object CheatSheet | |
// The Date object is used to work with dates and times. | |
// More: http://www.w3schools.com/jsref/jsref_obj_date.asp | |
// 1. Instantiating a Date. | |
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
{ | |
"USD": { | |
"symbol": "$", | |
"name": "US Dollar", | |
"symbol_native": "$", | |
"decimal_digits": 2, | |
"rounding": 0, | |
"code": "USD", | |
"name_plural": "US dollars" | |
}, |
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 NumberFormatter(locale, opts) { | |
var formatNumber, | |
defaults = { | |
style: 'currency', | |
currency: 'EUR' | |
}; | |
opts = opts || {}; | |
opts = Object.assign({}, defaults, opts); | |
formatNumber = new Intl.NumberFormat(locale, opts); |
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
sudo pkill -9 -u user |
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
const events = new Map(); | |
class EventBus { | |
/** | |
* Register an event handler for the given type. | |
* | |
* @param {String} type Type of event to listen for. | |
* @param {Function} handler Function to call in response to given event. | |
*/ | |
on(type, handler) { |
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 parseFormData(formData) { | |
const formEntries = new FormData(formData).entries(); | |
const data = {}; | |
for (var [formElementName, value] of formEntries) { | |
data[formElementName] = value; | |
} | |
return data; | |
} |