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
function rgbToLab( R, G, B ) { | |
R = ( R / 255 ); | |
G = ( G / 255 ); | |
B = ( B / 255 ); | |
if ( R > 0.04045 ) R = Math.pow( ( R + 0.055 ) / 1.055, 2.4 ); | |
else R = R / 12.92; | |
if ( G > 0.04045 ) G = Math.pow( ( G + 0.055 ) / 1.055, 2.4 ); | |
else G = G / 12.92; | |
if ( B > 0.04045 ) B = Math.pow( ( B + 0.055 ) / 1.055, 2.4 ); |
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
class MealBuilder { | |
init() { | |
this.meal = new Meal(); | |
} | |
addMain(type) { | |
this.meal.main = new MainItem(type); | |
} |
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 nodes = [ | |
{ | |
links: [ 1, 3 ], // node 0 is linked to node 1 and 3 | |
weightLinks: [ 5, 15 ], // the distance between node 0 and 1 is 5, between 0 and 3 is 15 | |
distance: Infinity | |
}, { | |
links: [ 0, 2 ], // node 1 is linked to node 0 and 2 | |
weightLinks: [ 5, 5, ], // the distance between node 1 and 0 is 5, between 1 and 2 is 5 | |
distance: Infinity | |
}, |
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
class Singleton { | |
constructor() { | |
if (typeof Singleton.instance === 'object') { | |
return Singleton.instance; | |
} | |
Singleton.instance = this; | |
return this; |
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
class Car { | |
constructor(size, price, maxSpeed) { | |
this.size = size; | |
this.price = price; | |
this.maxSpeed = maxSpeed; | |
} | |
} | |
class CarFactory { |
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 getDistance = (A, B) => Math.sqrt( Math.pow( B.x - A.x, 2 ) + Math.pow( B.y - A.y, 2 ) ); |
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
for FILE in $(find . -name "*.svg"); do | |
grep -qR $(basename "$FILE") * || echo "you can remove $FILE" | |
done |
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
class TimeTracker { | |
constructor() { | |
this.timers = {}; | |
} | |
logLoadTimes() { | |
var loadTimes = chrome.loadTimes(); | |
console.log( `commitLoadTime .............. ${( loadTimes.commitLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` ); | |
console.log( `finishDocumentLoadTime ...... ${( loadTimes.finishDocumentLoadTime - loadTimes.startLoadTime ).toFixed( 2 )}s` ); |
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
let partition = ( a, n ) => a.length ? [ a.splice( 0, n ), ...partition( a, n ) ] : []; | |
partition( [ 1, 2, 3, 4, 5, 6, 7, 8 ], 2 ); | |
// [ | |
// [ 1, 2 ], | |
// [ 3, 4 ], | |
// [ 5, 6 ], | |
// [ 7, 8 ] | |
// ] |
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 arr = "The quick brown fox jumps over the lazy dog".split( '' ); | |
arr.reduce( ( countMap, item ) => { | |
countMap[ item ] = ( countMap[ item ] || 0 ) + 1; | |
return countMap; | |
}, {} ); |