<commit_before>angular.module('StackWho')

  .controller('AppController', ['$scope', '$http', '$location', 'config', function($scope, $http, $location, config) {
    
    'use strict';

    // TODO: We use this on the backend as well. It's time to move this into a common lib
    // and come up with a proper build process
    var Lexer = function(){

        var self = {};

        var locationRegex = /location:(((?!answers:)[-A-Za-z0-9, ])+)/i,
            answersRegex  = /answers:(((?!location:)[-A-Za-z0-9, ])+)/i;

        self.tokenize = function(str){

            var locationMatch = str.match(locationRegex);
            var answerTagsMatch = str.match(answersRegex);

            var token = {
                locations: [],
                answerTags: []
            };

            var sanitize = function(word){
                return word && word.trim().toLowerCase();
            };

            var empty = function(word){
                return word && word.length > 0;
            };

            token.locations     =   locationMatch && locationMatch.length > 1 && 
                                    locationMatch[1]
                                    .split(',')
                                    .map(sanitize)
                                    .filter(empty) || [];

            token.answerTags   =   answerTagsMatch && answerTagsMatch.length > 1 && 
                                    answerTagsMatch[1]
                                    .split(',')
                                    .map(sanitize)
                                    .filter(empty) || [];

            return token;
        };

        return self;
    };

    var lexer = new Lexer();

    var tokens = lexer.tokenize($location.search().cmd || '');

    $scope.searchStringLocation = tokens.locations.join(',');
    $scope.searchStringTags = tokens.answerTags.join(',');

    $scope.displayUsers = [];

    $scope.createQueryLink = function(){
      var cmd = createQueryCommand().replace(/\s/g, '%20');
      return encodeURIComponent('http://www.ninya.io/#/?cmd=' + cmd);
    };

    var server = config.backendEndpoint + '/users';<commit_msg>fix(app): always use proper host<commit_after>angular.module('StackWho')

  .controller('AppController', ['$scope', '$http', '$location', 'config', function($scope, $http, $location, config) {
    
    'use strict';

    // TODO: We use this on the backend as well. It's time to move this into a common lib
    // and come up with a proper build process
    var Lexer = function(){

        var self = {};

        var locationRegex = /location:(((?!answers:)[-A-Za-z0-9, ])+)/i,
            answersRegex  = /answers:(((?!location:)[-A-Za-z0-9, ])+)/i;

        self.tokenize = function(str){

            var locationMatch = str.match(locationRegex);
            var answerTagsMatch = str.match(answersRegex);

            var token = {
                locations: [],
                answerTags: []
            };

            var sanitize = function(word){
                return word && word.trim().toLowerCase();
            };

            var empty = function(word){
                return word && word.length > 0;
            };

            token.locations     =   locationMatch && locationMatch.length > 1 && 
                                    locationMatch[1]
                                    .split(',')
                                    .map(sanitize)
                                    .filter(empty) || [];

            token.answerTags   =   answerTagsMatch && answerTagsMatch.length > 1 && 
                                    answerTagsMatch[1]
                                    .split(',')
                                    .map(sanitize)
                                    .filter(empty) || [];

            return token;
        };

        return self;
    };

    var lexer = new Lexer();

    var tokens = lexer.tokenize($location.search().cmd || '');

    $scope.searchStringLocation = tokens.locations.join(',');
    $scope.searchStringTags = tokens.answerTags.join(',');

    $scope.displayUsers = [];

    $scope.createQueryLink = function(){
      var cmd = createQueryCommand().replace(/\s/g, '%20');
      return encodeURIComponent('http://www.ninya.io/#/?cmd=' + cmd);
    };

    // since the site operates under stackwho.herokuapp.com and ninya.io we need to use origin except when we are on localhost
    // because then we either want to use localhost or one of the production backends
    var host = location.origin.indexOf('ninya.io') > -1 || location.origin.indexOf('stackwho.herokuapp.com') > -1
               ? location.origin : config.backendEndpoint;

    var server = host + '/users';
{'fraction_non_alphanumeric': 0.1367703451214316, 'fraction_numerical': 0.0051129100979974435, 'mean_word_length': 1.5613747954173487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '650075', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1204, 'n_words': 284}