<commit_before>#!/usr/bin/env node

var mapnik = require('mapnik')
  , mercator = require('mapnik/sphericalmercator')
  , mappool = require('mapnik/pool')
  , http = require('http')
  , url = require('url');
  
// create a pool of 10 maps
// this allows us to manage concurrency under high load
var maps = mappool.create(5);

var usage = 'usage: app.js <stylesheet> <port>';

var stylesheet = process.ARGV[2];

if (!stylesheet) {
   console.log(usage);
   process.exit(1);
}

var port = process.ARGV[3];

if (!port) {
   console.log(usage);
   process.exit(1);
}

var aquire = function(id,options,callback) {
    methods = {
        create: function(cb) {
                var obj = new mapnik.Map(options.width || 256, options.height || 256);
                // catch problem loading map
                try { obj.load(id) }
                catch (err) { callback(err, null) }
                if (options.buffer_size) obj.buffer_size(options.buffer_size);
                cb(obj);
            },
            destroy: function(obj) {
                obj.clear();
                delete obj;
            }
    };
    maps.acquire(id,
                  methods,
                  function(obj) {
                    callback(null, obj);
                  }
   );
};

var parseXYZ = function(req,callback) {
    matches = req.url.match(/(\d+)/g);
    if (matches && matches.length == 3) {
        try {
            callback(null,
               { z: parseInt(matches[0]),
                 x: parseInt(matches[1]),
                 y: parseInt(matches[2])
               });
        } catch (err) {
            callback(err,null);
        }
    } else {
          var query = url.parse(req.url, true).query;
          if (query &&
                query.x !== undefined &&
                query.y !== undefined &&
                query.z !== undefined) {
             try {
             callback(null,
               { z: parseInt(query.z),
                 x: parseInt(query.x),
                 y: parseInt(query.y)
               }<commit_msg>allow for TMS url scheme as well os OSM<commit_after>#!/usr/bin/env node

var mapnik = require('mapnik')
  , mercator = require('mapnik/sphericalmercator')
  , mappool = require('mapnik/pool')
  , http = require('http')
  , url = require('url');


var TMS_SCHEME = false;

// create a pool of 10 maps
// this allows us to manage concurrency under high load
var maps = mappool.create(5);

var usage = 'usage: app.js <stylesheet> <port>';

var stylesheet = process.ARGV[2];

if (!stylesheet) {
   console.log(usage);
   process.exit(1);
}

var port = process.ARGV[3];

if (!port) {
   console.log(usage);
   process.exit(1);
}

var aquire = function(id,options,callback) {
    methods = {
        create: function(cb) {
                var obj = new mapnik.Map(options.width || 256, options.height || 256);
                // catch problem loading map
                try { obj.load(id) }
                catch (err) { callback(err, null) }
                if (options.buffer_size) obj.buffer_size(options.buffer_size);
                cb(obj);
            },
            destroy: function(obj) {
                obj.clear();
                delete obj;
            }
    };
    maps.acquire(id,
                  methods,
                  function(obj) {
                    callback(null, obj);
                  }
   );
};

var parseXYZ = function(req,callback) {
    matches = req.url.match(/(\d+)/g);
    if (matches && matches.length == 3) {
        try {
            var x = parseInt(matches[1]);
            var y = parseInt(matches[2]);
            var z = parseInt(matches[0]);
            if (TMS_SCHEME)
                y = (Math.pow(2,z)-1) - y;
            callback(null,
               { z: z,
                 x: x,
                 y: y
               });
        } catch (err) {
            callback(err,null);
        }
    } else {
          var query = url.parse(req.url, true).query;
          if (query &&
                query.x !== undefined &&
                query.y !== undefined &&
                query.z !== undefined) {
             try {
             callback(null,
               { z: parseInt(query.z),
                 x: parseInt(query.x),
                 y: parseInt(query.y)
               }
{'fraction_non_alphanumeric': 0.13676814988290398, 'fraction_numerical': 0.008430913348946136, 'mean_word_length': 1.484584060500291, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4088552', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1245, 'n_words': 283}