Skip to content

Instantly share code, notes, and snippets.

import Direction from './direction';
function randomCoords(xMax, yMax) {
return {x: Math.floor(Math.random() * xMax), y: Math.floor(Math.random() * yMax)};
}
var SnakeGameLogic = function SnakeGameLogic(rows, cols, initialSnakePoints, initialDirection) {
var appleCoords = randomCoords(cols, rows);
var getApplePoint = function getApplePoint() {
return appleCoords;
@vanceingalls
vanceingalls / data.json
Last active October 25, 2015 01:39
d3.unconf 2015
[
{
"date": "10/1/2015",
"miles_driven": 35,
"trips": [
{
"miles_driven": 17,
"time": "13:26"
},
{
def rotx(x, string, encrypt=true)
i = 0
alpha = 'abcdefghijklmnopqrstuvwxyz'
newStr = ''
alpha.reverse! unless encrypt
# convert to one cycle
x = x > 26 ? x % 26 : x
def rotx(x, string, encrypt=true)
i = 0
alpha = 'abcdefghijklmnopqrstuvwxyz'
newStr = ''
alpha.reverse! unless encrypt
# convert to one cycle
x = x > 26 ? x % 26 : x
function Promise(){
this._callbacks = [];
}
Promise.prototype.resolve = function (data) {
if (typeof this._data !== 'undefined') {
// assuming console
console.error('This promise has already been resolved');
return;
}
// works in private scope w/ es5
function resolve (str) {
return str.split('.').reduce(function (prev, curr, ind) {
return ind < 2 ? eval(prev)[curr] : prev[curr];
});
}
@vanceingalls
vanceingalls / gist:5145902
Created March 12, 2013 19:03
works in private scope w/ es5
function resolve (str) {
return str.split('.').reduce(function (prev, curr, ind) {
return ind < 2 ? eval(prev)[curr] : prev[curr];
});
}
@vanceingalls
vanceingalls / robot.js
Created December 5, 2012 23:35
Jeffrey
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
var clone = robot.clone();
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);