Skip to content

Instantly share code, notes, and snippets.

View bbatliner's full-sized avatar

Brendan Batliner bbatliner

  • Chicago
View GitHub Profile
import os
import signal
from contextlib import contextmanager
from types import FrameType
from typing import Callable, Iterator, Optional, Tuple
from typing_extensions import assert_never
@contextmanager
def signal_fence(
// Higher order memoize function
// fn returns a promise (not synchronous)
function memoize (fn) {
const lookup = {}
const memoized = function () {
const args = Array.from(arguments)
if (args in lookup) {
return lookup[args]
}
return fn.apply(this, args).then(val => {
@bbatliner
bbatliner / memoization.js
Last active February 26, 2017 03:20
A simple demonstration of memoization for the Fibonacci function
// Higher order memoize function
function memoize (fn) {
const lookup = {}
const memoized = function () {
const args = Array.from(arguments)
if (args in lookup) {
return lookup[args]
}
return (lookup[args] = fn.apply(this, args))
}

League of Stats

Motivating question

How can we quantify an individual's influence on the outcome of a single game of League of Legends? Which metrics (indivdual, team, or enemy metrics) are the strongest predictors of game outcome?

Methods

For any individual, we determine or calculate the following metrics:

@bbatliner
bbatliner / stampit.js
Created May 4, 2016 03:24
I rewrote the examples from the stampit (https://github.com/stampit-org/stampit) readme in vanilla ES6. Great way to understand the inner machinations of Javascript!
// Use a closure for data privacy
const a = function() {
const priv = 'a';
return {
getA() {
return priv;
}
};
};
@bbatliner
bbatliner / oop.js
Last active May 4, 2016 02:22
Data privacy and extension with Javascript!
var Person = function (firstName, lastName) {
function privateGetName() {
return `${firstName} ${lastName}`;
}
return {
getName() {
return privateGetName();
},
speak() {
console.log('Hello!');
function multimode(arr) {
const counts = new Map();
for (let i = 0; i < arr.length; i++) {
counts.set(arr[i], (counts.get(arr[i]) || 0) + 1);
}
let maxCount, maxElem;
counts.forEach((count, index) => {
if (maxCount === undefined || count > maxCount) {
maxCount = count;
maxElem = index;
var bodyElement = document.querySelector("body");
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
var delay = 0;
function changeColor() {