<commit_before>var runner = require('./runner')

var usageMessage =
    "\n    literapi [-vah] http://api.server:port/root file1 [file2 [...]]" +
    "\n      -v         Show version number" +
    "\n      -a         Show all results, not just errors" +
    "\n      -d         Delay 50ms between calls (additional -d will double the delay)" +
    "\n      -w         Overwrite the document with annotations about successes and failures" +
    "\n      -q         Quiet mode: only returns ok/fail" +
    "\n      -h         Show this help"

function usage() {

  console.log(usageMessage)
  usageMessage = "\n\nPlease specify some options"
}

function extract_options(params) {

  // Make a shallow copy of params, as we will be munging it
  params = params.slice()

  // Start with default options
  var options =
    { serial: true
    , delay: 25
    , write: false
    }

  // Parse option flags from params
  while (params[0] && params[0].length && params[0][0] === '-') {
    for (var opt = params.shift(); opt = opt.slice(1); ) {
      switch (opt[0]) {
        case 'w':
          options.write = true
          break
        case 'v':
          console.log(LiterAPI.getVersion())
          break
        case 'p':
          options.serial = false
          break
        case 's':
          options.serial = true
          break
        case 'd':
          options.delay = options.delay ? (options.delay * 2) : 50
          break
        case 'h':
          usage()
          break
        case 'a':
          options.reporter = require('vows/lib/vows/reporters/spec')
          break
        case 'q':
          options.quiet = true
          options.reporter = require('./reporters/quiet')
          break
        default:
          console.log("Unrecognized option: -" + opt[0])
      }
    }
  }

  // We require at least 2 arguments: the host and a file to run
  if (params.length < 2) {
    usage()
    process.exit()
  }

  options.root = params.shift()
  options.files = params

  return options
}

/* Run the command-line
 *
 * Takes an array of command-line arguments. If none are passed, will use the arguments from `process`.
 */
function run(params) {

  var options = extract_options(params || process.argv.slice(2))

  if (!options.serial) {
    console.log("Unfortunately, due to the ways vows work, tests *must* be run serially for now.")
    options.serial = true
  }

  runner(options).run()
}

module.exports = run
<commit_msg>Fix -v version output<commit_after>var runner = require('./runner')
  , LiterAPI = require('./')

var usageMessage =
    "\n    literapi [-vah] http://api.server:port/root file1 [file2 [...]]" +
    "\n      -v         Show version number" +
    "\n      -a         Show all results, not just errors" +
    "\n      -d         Delay 50ms between calls (additional -d will double the delay)" +
    "\n      -w         Overwrite the document with annotations about successes and failures" +
    "\n      -q         Quiet mode: only returns ok/fail" +
    "\n      -h         Show this help"

function usage() {

  console.log(usageMessage)
  usageMessage = "\n\nPlease specify some options"
}

function extract_options(params) {

  // Make a shallow copy of params, as we will be munging it
  params = params.slice()

  // Start with default options
  var options =
    { serial: true
    , delay: 25
    , write: false
    }

  // Parse option flags from params
  while (params[0] && params[0].length && params[0][0] === '-') {
    for (var opt = params.shift(); opt = opt.slice(1); ) {
      switch (opt[0]) {
        case 'w':
          options.write = true
          break
        case 'v':
          console.log(LiterAPI.getVersion())
          break
        case 'p':
          options.serial = false
          break
        case 's':
          options.serial = true
          break
        case 'd':
          options.delay = options.delay ? (options.delay * 2) : 50
          break
        case 'h':
          usage()
          break
        case 'a':
          options.reporter = require('vows/lib/vows/reporters/spec')
          break
        case 'q':
          options.quiet = true
          options.reporter = require('./reporters/quiet')
          break
        default:
          console.log("Unrecognized option: -" + opt[0])
      }
    }
  }

  // We require at least 2 arguments: the host and a file to run
  if (params.length < 2) {
    usage()
    process.exit()
  }

  options.root = params.shift()
  options.files = params

  return options
}

/* Run the command-line
 *
 * Takes an array of command-line arguments. If none are passed, will use the arguments from `process`.
 */
function run(params) {

  var options = extract_options(params || process.argv.slice(2))

  if (!options.serial) {
    console.log("Unfortunately, due to the ways vows work, tests *must* be run serially for now.")
    options.serial = true
  }

  runner(options).run()
}

module.exports = run
<|endoftext|>


<commit_before>'use strict';

var program = require('commander');
var pkg = require('../package.json');
var open = require('open');
var nachosHome = require('./');

program
  .version(pkg.version)
  .description('A cli tool to get nachos home')
  .usage('[command]');

program
  .command('open')
  .description('Open the nachos home folder')
  .action(function () {
    open(nachosHome());
  });

program
  .command('print [innerPath]')
  .description('Print the nachos home folder')
  .option('-j, --json', 'output as json')
  .action(function (innerPath, options) {
    var path = nachosHome(innerPath);

    console.log(options.json ? {path: path} : path);
  });

/**
 * Handle cli arguments
 *
 * @param {string[]} argv - string array of the arguments
 */
module.exports = function (argv) {
  program
    .parse(argv);

  if (!argv.length) {
    console.log(nachosHome());
  }
};<commit_msg>fix when no parameters given<commit_after>'use strict';

var program = require('commander');
var pkg = require('../package.json');
var open = require('open');
var nachosHome = require('./');

program
  .version(pkg.version)
  .description('A cli tool to get nachos home')
  .usage('[command]');

program
  .command('open')
  .description('Open the nachos home folder')
  .action(function () {
    open(nachosHome());
  });

program
  .command('print [innerPath]')
  .description('Print the nachos home folder')
  .option('-j, --json', 'output as json')
  .action(function (innerPath, options) {
    var path = nachosHome(innerPath);

    console.log(options.json ? {path: path} : path);
  });

/**
 * Handle cli arguments
 *
 * @param {string[]} argv - string array of the arguments
 */
module.exports = function (argv) {
  program
    .parse(argv);

  if (argv.length <= 2) {
    console.log(nachosHome());
  }
};
<|endoftext|>


<commit_before>'use strict';

angular.module('app').directive('bubbles', [function() {
    var colorFromString = function(str) {
        str = str || '';

        var i, hash;
        i = hash = 0;
        while (i < str.length) {
            hash = str.charCodeAt(i++) + ((hash << 5) - hash);
        }

        var colour = '#';
        for (i = 0; i < 3; ++i) {
            var part = (hash >> i * 8) & 0xFF;
            part = Math.max(Math.min(part, 200), 50);
            colour += ('00' + part.toString(16)).slice(-2);
        }
        return colour;
    };

    var computeNodes = function(data, clusterBy) {
        var nodes = _.map(data, function(d) {
            return {
                id : d,
                r : 10,
                x : 0,
                y : 0,
                cluster : Math.round(Math.random())
            };
        });

        return nodes;
    };

    var getClusterCenter = function(data, clusterBy, width, height) {
        return [
            { x : width / 3, y : height / 2 },
            { x : (width / 3) * 2, y : height / 2 },
        ];
    };

    return {
        restrict : 'EA',
        scope : {
            data : '='
        },
        templateUrl : 'directives/bubbles/bubbles.html',
        link : function($scope, element) {
            var svg = angular.element(element).find('div.d3');

            var padding = {
                top : 100,
                right : 100,
                bottom : 100,
                left : 100
            };
            var width = svg.width();
            var height = svg.height();

            svg = d3.select(svg.get(0))
                    .append('svg')
                    .attr('width', width)
                    .attr('height', height);

            width = width - padding.left - padding.right;
            height = height - padding.top - padding.bottom;
            svg = svg.append('g')
                     .attr('width', width)
                     .attr('height', height)
                     .translate([padding.left, padding.top]);

            $scope.data = _.range(30);
            var nodes = computeNodes($scope.data);

            var clusterCenters = getClusterCenter(nodes, '', width, height);
            _.each(nodes, function(d) {
                d.x = clusterCenters[d.cluster].x;
                d.y = clusterCenters[d.cluster].y;
            });

            var bubbles = svg.selectAll('circle.bubble')
                             .data(nodes, d3.f('id'));
            // Create bubbles
            bubbles.enter().append('circle')
                           .attr('class', 'bubble')
                           .attr('r', d3.f('r'))
                           .on('mouseenter', function() {
                                d3.select(this).classed('hover', true);
                           })
                           .on('mouseleave', function() {
                                d3.select(this).classed('hover', false);
                           });

            var force = d3.layout.force().nodes(nodes).size([width, height]);
            var charge = function(d) {
                return -Math.pow(d.r, 2.0) / 3;
            };
            // Enable and start the force layout
            force.gravity(-0.01).charge(charge).friction(0.9).on('tick', function(e) {
                bubbles.each(function(d) {
                    d.x = d.x + (clusterCenters[d.cluster].x - d.x) * e.alpha * (0.3);
                    d.y = d.y + (clusterCenters[d.cluster].y - d.y) * e.alpha * (0.3);
                }).attr('cx', d3.f('x'))
                  .attr('cy', d3.f('y'));
            });
            force.start();

            // Switches
            $scope.switches = [
                2008,
                2015
            ];

            $scope.activateSwitch = function(theSwitch) {
                if ($scope.switches.indexOf(theSwitch) >= 0) {
                    $scope.activeSwitch = theSwitch;
                }
            };

            $scope.activateSwitch($scope.switches[0]);
        }
    };
}]);<commit_msg>refresh bubbles function<commit_after>'use strict';

angular.module('app').directive('bubbles', [function() {
    var colorFromString = function(str) {
        str = str || '';

        var i, hash;
        i = hash = 0;
        while (i < str.length) {
            hash = str.charCodeAt(i++) + ((hash << 5) - hash);
        }

        var colour = '#';
        for (i = 0; i < 3; ++i) {
            var part = (hash >> i * 8) & 0xFF;
            part = Math.max(Math.min(part, 200), 50);
            colour += ('00' + part.toString(16)).slice(-2);
        }
        return colour;
    };

    var computeNodes = function(data, clusterBy) {
        var nodes = _.map(data, function(d) {
            return {
                id : d.id,
                name : d.name,
                r : 12,
                x : 0,
                y : 0,
                fill : colorFromString(clusterBy(d)),
                cluster : clusterBy(d)
            };
        });

        return nodes;
    };

    var getClusterCenter = function(data, clusterBy, width, height) {
        return [
            { x : width / 3, y : height / 2 },
            { x : (width / 3) * 2, y : height / 2 },
        ];
    };

    return {
        restrict : 'EA',
        scope : {
            data : '='
        },
        templateUrl : 'directives/bubbles/bubbles.html',
        link : function($scope, element) {
            var svg = angular.element(element).find('div.d3');

            var padding = {
                top : 100,
                right : 100,
                bottom : 100,
                left : 100
            };
            var width = svg.width();
            var height = svg.height();

            svg = d3.select(svg.get(0))
                    .append('svg')
                    .attr('width', width)
                    .attr('height', height);

            width = width - padding.left - padding.right;
            height = height - padding.top - padding.bottom;
            svg = svg.append('g')
                     .attr('width', width)
                     .attr('height', height)
                     .translate([padding.left, padding.top]);

            var force = d3.layout.force();
            var charge = function(d) {
                return -Math.pow(d.r, 2.0) / 3;
            };

            // Switches
            $scope.switches = [
                '2008',
                '2015'
            ];

            $scope.activateSwitch = function(theSwitch) {
                if ($scope.switches.indexOf(theSwitch) >= 0) {
                    $scope.activeSwitch = theSwitch;
                }
            };

            $scope.activateSwitch($scope.switches[0]);

            // Refresh function
            var refresh = function() {
                var clusterBy = function(d) {
                    return d[$scope.activeSwitch];
                };
                var nodes = computeNodes($scope.data, clusterBy);

                var clusterCenters = getClusterCenter(nodes, clusterBy, width, height);
                _.each(nodes, function(d) {
                    d.x = clusterCenters[d.cluster].x;
                    d.y = clusterCenters[d.cluster].y;
                });

                var bubbles = svg.selectAll('circle.bubble')
                                 .data(nodes, d3.f('id'));
                // Create bubbles
                bubbles.enter().append('circle')
                               .attr('class', 'bubble')
                               .attr('r', d3.f('r'))
                               .attr('fill', d3.f('fill'))
                               .attr('stroke', function(d) {
                                    return d3.rgb(d.fill).darker(1.5);
                               })
                               .attr('id', d3.f('name'))
                               .on('mouseenter', function() {
                                    d3.select(this).classed('hover', true);
                               })
                               .on('mouseleave', function() {
                                    d3.select(this).classed('hover', false);
                               });

                force.nodes(nodes).size([width, height]);
                // Enable and start the force layout
                force.gravity(-0.01).charge(charge).friction(0.9).on('tick', function(e) {
                    bubbles.each(function(d) {
                        d.x = d.x + (clusterCenters[d.cluster].x - d.x) * e.alpha * (0.3);
                        d.y = d.y + (clusterCenters[d.cluster].y - d.y) * e.alpha * (0.3);
                    }).attr('cx', d3.f('x'))
                      .attr('cy', d3.f('y'));
                });
                force.start();
            };

            $scope.$watch(function() { return $scope.data.length; }, function() {
                if ($scope.data.length > 0) {
                    refresh();
                }
            }, true);
        }
    };
}]);<|endoftext|>


<commit_before>var argv = require('minimist')(process.argv.slice(2));
var fs = require("fs");
var lib = require('./list.js');

var config = (JSON.parse(fs.readFileSync(argv.config || './config.json', 'utf8')));

if(argv._[0] === 'generate'){
  var csv = fs.readFileSync(argv.input || './input.csv', 'utf8');
  csv = csv.split('\n').slice(0,-2);
  var names = [], map = {},kills={};
  for(var i = 0; i < csv.length; i++){
    csv[i] = csv[i].split(',');
    names.push(csv[i][0]);
    map[csv[i][0]] = csv[i].slice(1);
    kills[csv[i][2]] = 0;
  }
  list = lib.generateList(names);
  game = {list:list,kills:kills,people:map};
  console.log(game);
}<commit_msg>added writing the file<commit_after>var argv = require('minimist')(process.argv.slice(2));
var fs = require("fs");
var lib = require('./list.js');

var config = (JSON.parse(fs.readFileSync(argv.config || './config.json', 'utf8')));

if(argv._[0] === 'generate'){
  var csv = fs.readFileSync(argv.input || './input.csv', 'utf8');
  csv = csv.split('\n').slice(0,-2);
  var names = [], map = {},kills={};
  for(var i = 0; i < csv.length; i++){
    csv[i] = csv[i].split(',');
    names.push(csv[i][0]);
    map[csv[i][0]] = csv[i].slice(1);
    kills[csv[i][2]] = 0;
  }
  list = lib.generateList(names);
  game = {list:list,kills:kills,people:map};
  console.log(game);
  fs.writeFile(argv.output || "./game.json", JSON.stringify(game));
}<|endoftext|>


<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const config = require('./config');

const HEADERS = ['X-Content-Security-Policy', 'Content-Security-Policy'];

module.exports = function cspFactory(routes) {
  return function csp(req, res, next) {
    if (routes.indexOf(req.path) > -1) {
      HEADERS.forEach(function(header) {
        res.setHeader(header, "default-src 'self' " + config.get('personaUrl'));
      });
    }
    next();
  };
};
<commit_msg>update CSP to allow dataUri images<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const config = require('./config');

const HEADERS = ['X-Content-Security-Policy', 'Content-Security-Policy'];
const VALUE = [
  "default-src 'self' " + config.get('personaUrl'),
  "img-src 'self' data:"
].join(';');

module.exports = function cspFactory(routes) {
  return function csp(req, res, next) {
    if (routes.indexOf(req.path) > -1) {
      HEADERS.forEach(function(header) {
        res.setHeader(header, VALUE);
      });
    }
    next();
  };
};
<|endoftext|>


<commit_before>(function() {
  var CSS, compilers, resolve;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  resolve = require('path').resolve;
  compilers = require('./compilers');
  CSS = (function() {
    function CSS(path) {
      this.path = resolve(path);
      this.path = require.resolve(this.path);
    }
    CSS.prototype.compile = function() {
      console.log(require.cache);
      delete require.cache[this.path];
      return require(this.path);
    };
    CSS.prototype.createServer = function() {
      return __bind(function(req, res, next) {
        var content;
        content = this.compile();
        res.writeHead(200, {
          'Content-Type': 'text/css'
        });
        return res.end(content);
      }, this);
    };
    return CSS;
  })();
  module.exports = {
    CSS: CSS,
    createPackage: function(path) {
      return new CSS(path);
    }
  };
}).call(this);
<commit_msg>build<commit_after>(function() {
  var CSS, compilers, resolve;
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  resolve = require('path').resolve;
  compilers = require('./compilers');
  CSS = (function() {
    function CSS(path) {
      this.path = resolve(path);
      this.path = require.resolve(this.path);
    }
    CSS.prototype.compile = function() {
      delete require.cache[this.path];
      return require(this.path);
    };
    CSS.prototype.createServer = function() {
      return __bind(function(req, res, next) {
        var content;
        content = this.compile();
        res.writeHead(200, {
          'Content-Type': 'text/css'
        });
        return res.end(content);
      }, this);
    };
    return CSS;
  })();
  module.exports = {
    CSS: CSS,
    createPackage: function(path) {
      return new CSS(path);
    }
  };
}).call(this);
<|endoftext|>