Skip to content

Instantly share code, notes, and snippets.

View avdg's full-sized avatar

Anthony Van de Gejuchte avdg

View GitHub Profile
@avdg
avdg / solution.js
Last active November 30, 2015 12:22
Code vs zombies
"use strict";
// Policy:
// - Keep zombies away from humans
// - Cluster zombies
// - Kill all at once
/**
* Save humans, destroy zombies!
**/
. ~/.nvm/nvm.sh
npm install uglify-js
wget "https://code.jquery.com/jquery-2.1.4.js" -Ojquery.js
nvm install 0.10
time node node_modules/.bin/uglifyjs jquery.js > jquery.min.js
nvm install 0.12
time node node_modules/.bin/uglifyjs jquery.js > jquery.min.js
diff --git a/extensions/tools/commands/creepClone.js b/extensions/tools/commands/creepClone.js
index 3a02c7f..908da15 100644
--- a/extensions/tools/commands/creepClone.js
+++ b/extensions/tools/commands/creepClone.js
@@ -7,11 +7,11 @@ var duplicateCreep = function (creep, priority, silence) {
silence = silence === true;
// Find and add to queue
- if (typeof creep.memory.spawn === "string") {
- spawn = Game.getObjectById(creep.memory.spawn).name;
function duplicate(value, count) {
var output = [];
var duplicator = [value];
var base = 1;
while (count > 0) {
if ((base & count) > 0) {
output = output.concat(duplicator);
count -= base;
}
"use strict";
var https = require("https");
var querystring = require("querystring");
// Display help if necessary
if ((process.argv[2] === "--help" || process.argv[2] === undefined) && process.argv[3] === undefined) {
console.log("Usage: " + process.argv[0] + " " + process.argv[1] + " <email> <password> [branch=default]");
process.exit();
}
@avdg
avdg / main.js
Last active August 29, 2015 14:26
Screeps fetch api
var writeApiData = function() {
var parseFunction = function(obj) {
// Note: Function.prototype.toString() is implementation defined, may not work on non-v8 or future v8 js engines
// See: http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.2
var args = obj.toString();
args = args.substr(0, args.indexOf(")"));
args = args.substr(args.indexOf("(") + 1);
args = args === "" ? [] : args.split(",");
var data = {
"_type": "function",
@avdg
avdg / terrain.js
Created July 13, 2015 22:32
Just blah
'use strict';
// TODO use high performance array?
var types = {
plain: 0,
swamp: 1,
lava: 2,
wall: 3
};
@avdg
avdg / room.js
Last active August 29, 2015 14:24
Untested code!
'use strict';
function hasWall(list, returnValueDefaultsTrue) {
if (!Array.isArray(list)) {
return returnValueDefaultsTrue === undefined ? true : returnValueDefaultsTrue;
}
for (var i = 0; i < list.length; i++) {
if (list[i].type === "terrain" && list[i].terrain === "wall") {
return true;
@avdg
avdg / huffman.js
Created June 28, 2015 19:35
Some random uncompleted huffman tree implementation
// Priority stack implementation over here https://github.com/avdg/screeps/blob/master/extensions/tools/library/priorityStack.js
// Assume AI.priorityStack = require(<path to priorityQueue>);
/**
* A basic huffman tree compression algorithm
*
* @param input String Input to convert
*
* @return string
*/