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
macro random { | |
case { _ ($expr:expr (,) ...) } => { | |
var matches = match.patternEnv.$expr.match; | |
var randomIndex = Math.floor(Math.random() * matches.length); | |
var randomMatch = matches[randomIndex].match; | |
return randomMatch | |
} | |
} | |
random(console.log(1), console.log(2), console.log(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
require('harp').server(__dirname + '/public', { port: process.env.PORT || 5000 }); | |
var marked = require('./node_modules/harp/node_modules/terraform/node_modules/marked'); | |
var highlight = require('highlight.js'); | |
marked.setOptions({ | |
langPrefix: '', | |
highlight: function (code, language) { | |
if (language) { | |
return highlight.highlight(language, code).value; |
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* fib () { | |
var [a, b, n] = [1, 1, 1]; | |
while (true) { | |
yield [a, n]; | |
[a, b, n] = [b, a + b, n + 1]; | |
} | |
} | |
for (let [n, i] of fib()) { |
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 [first, second, ...rest] = [1, 2, 3, 4, 5]; | |
console.log('first =', first); | |
console.log('second =', second); | |
console.log('rest =', rest); | |
// => first = 1 | |
// => second = 2 | |
// => rest = [3, 4, 5] | |
function printPoint({x: x, y: y}) { |
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 sum (...args) { | |
return args.reduce((a, b) => a + b, 0); | |
} | |
var nums = [1,2,3]; | |
// ES5 | |
console.log('sum.apply(null, nums) =', sum.apply(null, nums)); | |
// => sum.apply(null, nums) = 6 |
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 nums = [1, 2, 3]; | |
for (var i in nums) { | |
setTimeout(() => { | |
console.log('var i =', nums[i]); | |
}, 1000 * i); | |
} | |
for (let i in nums) { | |
setTimeout(() => { |
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
ko.bindingHandlers.number = { | |
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { | |
var value = ko.unwrap(valueAccessor()); | |
valueAccessor = function () { | |
return value.toString().replace('.', ','); | |
}; | |
ko.bindingHandlers.text.update(element, valueAccessor, allBindings, viewModel, bindingContext); | |
} | |
}; |
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
define('itemFactory', function () { | |
function Item() { | |
this.value = Math.ceil(Math.random() * 1000); | |
}; | |
return Item; | |
}); | |
define('firstView', ['factory!itemFactory'], function (item) { | |
console.log('First view; ' + JSON.stringify(item)); |
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
(defn FizzBuzz | |
"Returns 'Fizz', 'Buzz' or 'FizzBuzz' if n is divisible by | |
3, 5 or both, respectively, or else just n." | |
[n] | |
(condp #(zero? (mod %2 %1)) n | |
15 "FizzBuzz" | |
3 "Fizz" | |
5 "Buzz" | |
(str n))) |
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 whenCacheInSync(callback) { | |
// 1. Checking | |
var onChecking = function () { | |
window.applicationCache.removeEventListener('checking', onChecking); | |
window.applicationCache.addEventListener('noupdate', onNoUpdate); | |
window.applicationCache.addEventListener('downloading', onDownloading); | |
}; | |
// 1A. No updates, load app |
NewerOlder