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
| // Use Gists to store code you would like to remember later on | |
| console.log(window); // log the "window" object to the console |
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
| /** | |
| * Returns download time from server | |
| * | |
| * @param {number} cwnd - Initial Congestion Window size | |
| * @param {number} rtt - Roundtrip Time in Milliseconds | |
| * @param {number} packetSize - Packet Size in Bytes | |
| * @param {number} totalSize - Total Transfer Size in Bytes | |
| * @return {number} time - Download Time in Milliseconds | |
| */ | |
| function downloadTime(cwnd, rtt, packetSize, totalSize) { |
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 delegate(element, eventName, selector, handler) { | |
| var el = null; | |
| element.addEventListener(eventName, function delegatedListener(e) { | |
| el = e.target; | |
| while (el !== element && el.parentNode) { | |
| if (el.nodeType === 1 && selectorMatches(el, selector)) { | |
| handler(e, el); | |
| break; | |
| } |
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 INIT = 'INIT'; | |
| function createStore(reducer, initialState) { | |
| var state = initialState; | |
| var subscribers = []; | |
| function getState() { | |
| return state; | |
| } | |
| function dispatch(action) { |
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
| // 0 based index | |
| var iParent = (i) => Math.floor((i-1)/2); | |
| var iLeftChild = (i) => 2*i + 1; | |
| var iRightChild = (i) => 2*i + 2; | |
| function heapsort(list, count) { | |
| // first build a heap | |
| maxHeapify(list, count); | |
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
| // Simple JavaScript Templating | |
| // John Resig - http://ejohn.org/ - MIT Licensed | |
| // http://ejohn.org/blog/javascript-micro-templating/ | |
| (function() { | |
| var cache = {}; | |
| function tmpl(str, data){ | |
| // Figure out if we're getting a template, or if we need to | |
| // load the template - and be sure to cache the result. | |
| var fn = !/\W/.test(str) ? |
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
| var Events = { | |
| on: function(type, fn, context) { | |
| this.events = this.events || {}; | |
| this.events[type] = this.events[type] || []; | |
| fn = typeof fn === 'function' ? fn : context[fn]; | |
| this.events[type].push({ fn: fn, context: context || this }); | |
| return this.off.bind(this, type, fn, context); | |
| }, |
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
| process.stdin.setEncoding('utf8'); | |
| process.stdin.on('data', function (buf) { | |
| var tokens = formatInput(buf); | |
| var a = parseInt(tokens[0]); | |
| var b = parseInt(tokens[1]); | |
| console.log(a+b); | |
| process.exit(); | |
| }); | |
| function formatInput(input) { |
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 prefixFactory(prefix) { | |
| return function prefixer(string) { | |
| return string.split(' ') | |
| .map( s => prefix + s) | |
| .join(' '); | |
| }; | |
| } | |
| export default prefixFactory; |
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
| import classPrfx from 'postcss-class-prefix'; | |
| import precss from 'precss'; // for scss support | |
| module: { | |
| loaders: [ | |
| { | |
| test: /\.scss$/, | |
| loaders: [ | |
| 'style', | |
| 'css', |
OlderNewer