Skip to content

Instantly share code, notes, and snippets.

View mlms13's full-sized avatar
⚗️

Michael Martin mlms13

⚗️
View GitHub Profile
@mlms13
mlms13 / main.js
Last active August 29, 2015 14:23
Promises and Events! and Pseudo-Code!
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 */);
});
@mlms13
mlms13 / pro.js
Last active August 29, 2015 14:23
A promise library for professionals.
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);
@mlms13
mlms13 / upgrades.js
Last active January 24, 2017 21:32
List unpurchased upgrades in Cookie Clicker
// 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
@mlms13
mlms13 / cycle.css
Created July 10, 2015 19:03
Jeet cycling
li {
background: #ddd;
height: 40px;
margin-top: 5px;
margin-bottom: 5px;
}
@media screen and (min-width: 640px) {
li {
*zoom: 1;
float: left;
@mlms13
mlms13 / Ferble.js
Last active August 29, 2015 14:25
It's a ferble.
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();
@mlms13
mlms13 / riskroll.js
Last active August 29, 2015 14:26
Attacker vs Defender with big armies in risk
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) {
@mlms13
mlms13 / uphxlib.fish
Last active August 29, 2015 14:26
Update haxelib dev repos in fish-shell
function uphxlib
# upgrade normal haxe repositories
echo 'a' | haxelib upgrade
# keep track of the current directory
set current_dir (pwd)
# update all 'dev' repo git repositories
for lib in (haxelib list | cut -d: -f2- | grep 'dev:')
set dev_dir (echo $lib | rev | cut -c 2- | rev | cut -d '[' -f2- | cut -c5-)
// get names and ratings for BFZ cards from ChannelFireball
function getRatings() {
var list = [].slice.apply($('.postContent h1').not(":first").not(":last"));
return list.map(function(el) {
var rating = $(el).next().next().clone().find("b").remove().end().text()
return {
name: el.textContent,
rating: parseFloat(rating)
};
});
@mlms13
mlms13 / lovefield.d.ts
Created November 22, 2015 05:41
Typescript definition file for Lovefield. I didn't make this.
// Type definitions for Lovefield v2.0.62
// Project: http://google.github.io/lovefield/
// Definitions by: freshp86 <https://github.com/freshp86>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../es6-promise/es6-promise.d.ts"/>
declare module lf {
export enum Order { ASC, DESC }
var sections = [{
id: "A",
flag: false,
subsections: [{
id: "A1",
subsections: [{
id: "A1a",
flag: true
}, {
id: "A1b"