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 roll() { | |
return Math.ceil(Math.random() * 6); | |
} | |
function compare() { | |
var one = [roll(), roll(), roll()].sort(function (a, b) { return b-a }).slice(0,2); | |
var two = [roll(), roll()].sort(function (a, b) { return b-a }); | |
var score = 0; | |
one.forEach(function (item, index) { |
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 splitIntoGroups(chunks, str) { | |
var splitAt = str.charAt(0) === '"' ? | |
// if the string starts with a quote at this point, | |
// find the next quote or the end of the string | |
str.indexOf('"', 1) > -1 ? str.indexOf('"', 1) : str.length : | |
// otherwise, break at the next space | |
str.indexOf(' ', 1) > -1 ? str.indexOf(' ', 1) : str.length, | |
word = str.substring(0, splitAt).replace('"', '').trim(); |
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
li { | |
background: #ddd; | |
height: 40px; | |
margin-top: 5px; | |
margin-bottom: 5px; | |
} | |
@media screen and (min-width: 640px) { | |
li { | |
*zoom: 1; | |
float: left; |
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
// I rewrite these way too often, so here they are: | |
// upgrades | |
Game.UpgradesById | |
.filter(function (up) { | |
return !up.bought && up.pool != "prestige" && up.pool != "toggle" && up.pool != "debug"; | |
}) | |
.map(_ => _.name); | |
// achievements |
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 Pro(callback) { | |
this.isResolved; | |
this.isRejected; | |
this.thens = []; | |
this.catches = []; | |
var resolve = function (data) { | |
if (this.isResolved || this.isRejected) return; | |
this.thens.forEach(function (fn) { | |
fn(data); |
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 tellMeWhenThatThingHappens() { | |
var promise = new Promise(function (resolve, reject) { | |
window.addEventListener('thatAwesomeThingHappens', function () { | |
resolve(/* maybe with some data here */); | |
}); | |
// if it's possible for that awesome thing to fail... | |
window.addEventListener('refusingToBeAwesome', function () { | |
reject(/* maybe with an error */); | |
}); |
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
// beautiful | |
function findAnagram(parent, child) { | |
// split the parent string into chars and iterate | |
return parent.split('').map(function (char, index, arr) { | |
// map each char in parent to an array of substrings with the same length as child.length | |
// and alphabetize the substrings for easy comparison later | |
return arr.slice(index, index + child.length).sort().join(''); | |
}).filter(function (subset) { | |
// compare the alphabetized substring to the alphabetized child | |
return subset === child.split('').sort().join(''); |
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 mdeps = require('module-deps'), | |
_ = require('lodash'), | |
deps = []; | |
var md = mdeps({ | |
transform: 'hbsfy', | |
global: true | |
}); | |
md.on('end', function () { |
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
// `gulp stylus --prod` will enable "production mode" | |
// `gulp stylus` will leave the prod flag undefined, so it will do a dev build | |
var gulp = require('gulp'), | |
gutil = require('gulp-util'), | |
prod = gulp.env.prod; | |
gulp.task('stylus', ['cleancss'], function () { | |
var stylus = require('gulp-stylus'), | |
prefix = require('gulp-autoprefixer'), | |
minify = require('gulp-minify-css'); |
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 foo = { | |
filter: function () {} | |
}; | |
var bar = []; | |
// return filtered array or object | |
function filterer(baz) { | |
return baz.filter(); | |
} |