I hereby claim:
- I am lukealbao on github.
- I am lukealbao (https://keybase.io/lukealbao) on keybase.
- I have a public key ASCa2ZGlr6ZsHFfLwNxDhb4gC_4OhzbFTc5qP4MLhQA-Ggo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
// Given a function, integerFormat, that takes an array of numbers and returns a new | |
// array of numbers, like integerFormat([30.1, 60.3, 29.6]) => [30, 60, 30], | |
// you can create a parameterized function to round to any decimal point: | |
function roundToNearest (numbers, resolution) { | |
var leftShift = Math.pow(10, resolution); | |
return integerFormat(numbers.map(n => n * leftShift)).map(n => n / leftShift); | |
} |
'use strict'; | |
// https://nodejs.org/api/process.html#process_process_nexttick_callback_args | |
// | |
// Says: | |
// | |
// "It runs before any additional I/O events (including timers) fire | |
// in subsequent ticks of the event loop." | |
// | |
// Question is, does "additional" mean events whose listeners are added |
/* | |
* A conversion of the hex2ebcdic.js conversion utility. The original | |
* exported a function that used a big switch statement. Now it is | |
* a hash table that will be used by a single `encode` function. | |
* | |
* Author: Luke Albao <[email protected]> | |
* Copyright: First Performance Corporation | |
*/ | |
// To run this from the command line: |
var inventory = { | |
'000001': { | |
name: 'Banana Slicer', | |
price: 2.99 | |
}, | |
'000002': { | |
name: 'Three Wolves Tea Cozy', | |
price: 14.95 | |
} | |
}; |
#! /bin/bash -e | |
## | |
## To install ZeroMQ, you can download this file and run it directly in the shell: | |
## | |
## $> sudo wget <uri> | sh | |
## | |
## You can get the <uri> by clicking on the `Raw` button above the Gist. | |
## Changes: | |
## * In order to install the latest version, change the version number in the SOURCE | |
## variable below (line 15). |
def build_candidates(input_string, lexicon=LEXICON): | |
code = encode(''.join(re.findall('[a-z]+', input_string.lower()))) | |
d = {} | |
for word in lexicon: | |
_code = lexicon.encoded(word) | |
if code % _code == 0: | |
d[word] = lexicon[word] | |
return d.keys() |
def encode(text, decode=False): | |
"Credit for this strategy goes to http://stackoverflow.com/a/16872684" | |
table = {'a':2, 'b':3, 'c':5, 'd':7, 'e':11, 'f':13, 'g':17, 'h':19, | |
'i':23, 'j':29, 'k':31, 'l':37, 'm':41, 'n':43,'o':47, 'p':53, 'q':59, | |
'r':61, 's':67, 't':71, 'u':73, 'v':79, 'w':83, 'x':89, 'y':97, 'z':101} | |
if not decode: | |
return reduce(mul,[table[char] for char in text]) if text else '' |
function rootSearch (root, game, depth) { | |
var alpha = -Infinity; | |
var beta = Infinity; | |
var moves = getMoves(root, game); // Array[Object{player: number, game: number}, ...] | |
var nodeScore; | |
var bestMove; | |
for (var i = 0, l = moves.length; i < l; i++) { | |
nodeScore = alphaBeta(moves[i].player, moves[i].game, depth, | |
alpha, beta, true); |
/* | |
* Go to hash location associated with line of code. | |
* Assigning line in the if clause is done because parseInt | |
* returns falsy if its result is NaN. | |
*/ | |
function goToLine(line) { | |
if (line = parseInt(line)) { | |
document.location.hash = "#L" + line; | |
} |