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
// Example 1. | |
var firstFloatingPointNumber = 1.0; | |
var secondFloatingPointNumber = 0.7; | |
var result = firstFloatingPointNumber - secondFloatingPointNumber; // 0.30000000000000004, instead of 0.3. | |
// To fix that precision issue. | |
result = (firstFloatingPointNumber - secondFloatingPointNumber)/ 10; // 0.3 |
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
upstream secured { | |
server 0.0.0.0:8443; | |
} | |
server { | |
listen 80; | |
server_name example.com www.example.com; | |
location / { | |
add_header Cache-Control public; |
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
var dates = [1, 2, 3]; | |
var done = dates.map(function (date) { | |
return new Promise(function (resolve, reject) { | |
var json = ['a', 'b', 'c']; | |
if (date > Math.random() * 10) { | |
setTimeout(reject, Math.random() * 5000, date); | |
}else { | |
setTimeout(resolve, Math.random() * 5000, json[Math.ceil(Math.random() * 3) - 1]); | |
} | |
}); |
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
// PART 1a - Uncomment the following lines if running on Node; | |
// var _ = require("lodash"); | |
// var Firebase = require('firebase'); | |
// PART 1b - Uncomment the following lines if running on Chrome Dev Tool; | |
// var script = document.createElement('script'); | |
// script.type = 'text/javascript'; | |
// script.src = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js'; | |
// document.head.appendChild(script); | |
// var script = document.createElement('script'); |
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
/** | |
* 1 - Start off everything from the origin (0, 0) just like how to draw something on a graph in Mathematics | |
* where the Cartesian Plane has a +ve and -ve x- and y- axes and the circle is drawn on it by having a | |
* centroid at the origin (0, 0); | |
* 2 - Do the same thing for finding an angle from a coordinate as you know a circle has 360 degree, however | |
* the method to find a particular angle from the coordiante you have chosen is kind of not doing what | |
* you would have expected. Say, the method you use to find the angle is by using Math.atan2, it actually | |
* returns a computed angle from the X axis and the range of the returned value falls between -pi and +pi. | |
*/ | |
/** |
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
spdy:connection:server id=0 frame +249ms { type: 'HEADERS', | |
id: 105, | |
priority: { parent: 0, exclusive: true, weight: 183 }, | |
fin: true, | |
writable: true, | |
headers: | |
{ ':method': 'GET', | |
':authority': 'semafore.motss.koding.io:3000', | |
':scheme': 'https', | |
':path': '/bower_components/polymer/polymer-micro.html', |
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
// compute week number based on date and first day of the week is Sunday. | |
// Eg. Let _date = '2015-11-12', | |
// Ref 1 for week number starting from Monday: http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php?year=2020 | |
// Ref 2 for week number starting from Sunday: http://www.timeanddate.com/calendar/custom.html?year=2026&country=69&fdow=7&wno=4&df=1 | |
// To get week numbers for calendars starting from Sunday (US calendar system). | |
function getWeek(_date) { | |
let now = new Date(_date); // new Date('2015-11-12'); | |
now = new Date(now.getFullYear(), now.getMonth(), now.getDate() - now.getDay() + 4); // FIrst 4-day week of a year. | |
let onejan = new Date(now.getFullYear(), 0, 1); |
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
// http://stackoverflow.com/questions/10964966/detect-ie-version-prior-to-v9-in-javascript | |
// http://tanalin.com/en/articles/ie-version-js/ | |
var ie = (function (){ | |
if (window.ActiveXObject === undefined) return null; | |
if (!document.querySelector) return 7; | |
if (!document.addEventListener) return 8; | |
if (!window.atob) return 9; | |
if (!document.__proto__) return 10; | |
return 11; | |
})(); |
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
// Given a integer n, output the first n numbers of the Fibonacci sequence efficiently. | |
// Input: 5 | |
// Output: [1, 1, 2, 3, 5] | |
function fib(n) { | |
if (n < 2) { | |
return 1; | |
} | |
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
var gulp = require('gulp'); | |
var del = require('del'); | |
var runSequence = require('run-sequence'); | |
// var minifyHTML = require('gulp-minify-html'); | |
var minifyInline = require('gulp-minify-inline'); | |
var size = require('gulp-size'); | |
var uglify = require('gulp-uglify'); | |
var htmlmin = require('gulp-htmlmin'); | |
var options = { |
OlderNewer