<commit_before>(function () {
    'use strict';

    angular.module('users')
        .service('userService', ['$http', '$q', UserService]);
    /**
     * Users DataService
     * Uses embedded, hard-coded data model; acts asynchronously to simulate
     * remote data service call(s).
     *
     * @returns {{loadAll: Function}}
     * @constructor
     */
    function UserService($http, $q) {
        var random_user_url = 'http://api.randomuser.me';

        this.getUsers = getUsers;
        this.getUser = getUser;

        function getUsers(numberOfUsers) {
            //if numberOfUsers is falsy (null, undefined, 0, '', NaN, false), set to 5
            numberOfUsers = numberOfUsers || 5;

            //get the nunmber of users from http://api.randomuser.me, and return a promise
            return $q.all(getUserRequestList(numberOfUsers));
        }

        //get a single user
        function getUser() {
            return new UserCall($http);
        }

        function getUserRequestList(userCount) {
            var users = [];
            for (var i = 0; i < userCount; i++) {
                users.push(new UserCall($http));
            }
            return users;
        }

        //Fancy object to get a User from http://api.randomuser.me
        function UserCall($http) {
            var userCall = this;
            //register the method on this object against memory leaks
            userCall.extractUser = function (response) {
                return response.data.results.map(function (user) {
                    return user.user;
                })[0]
            };

            //return a promise which will return a user from the JSON call
            return $http.get(random_user_url).then(userCall.extractUser);
        }
    }
})
();
<commit_msg>documentation<commit_after>(function () {
    'use strict';

    angular.module('users')
        .service('userService', ['$http', '$q', UserService]);
    /**
     * Users DataService
     * Uses embedded, hard-coded data model; acts asynchronously to simulate
     * remote data service call(s).
     *
     * @returns {{loadAll: Function}}
     * @constructor
     *
     * DIFFERENCE BETWEEN SERVICE & FACTORY (from the angular source:)
     *  because services are instantiated with new(), binding to the instance works!
     *
     *   var Ping = function($http) {
     *     this.$http = $http;
     *     this.send = send;
     *
     *     function send() { return $http.send('/ping')}
     *   };
     *   someModule.controller('Ctrl', ['ping', function(ping) {
     *     ping.send();
     *   }]);
     *
     * factories are used when only 1 function is needed, usually to wrap $http
     *  $provide.factory('ping', ['$http', function($http) {
     *     return function ping() {
     *       return $http.send('/ping');
     *     };
     *   someModule.controller('Ctrl', ['ping', function(ping) {
     *     ping();
     *   }]);
     *
     */
    function UserService($http, $q) {
        var random_user_url = 'http://api.randomuser.me';

        this.getUsers = getUsers;
        this.getUser = getUser;

        function getUsers(numberOfUsers) {
            //if numberOfUsers is falsy (null, undefined, 0, '', NaN, false), set to 5
            numberOfUsers = numberOfUsers || 5;

            //get the nunmber of users from http://api.randomuser.me, and return a promise
            return $q.all(getUserRequestList(numberOfUsers));
        }

        //get a single user
        function getUser() {
            return new UserCall($http);
        }

        function getUserRequestList(userCount) {
            var users = [];
            for (var i = 0; i < userCount; i++) {
                users.push(new UserCall($http));
            }
            return users;
        }

        //Fancy object to get a User from http://api.randomuser.me
        function UserCall($http) {
            var userCall = this;
            //register the method on this object against memory leaks
            userCall.extractUser = function (response) {
                return response.data.results.map(function (user) {
                    return user.user;
                })[0]
            };

            //return a promise which will return a user from the JSON call
            return $http.get(random_user_url).then(userCall.extractUser);
        }
    }
})
();

{'fraction_non_alphanumeric': 0.12079615648592999, 'fraction_numerical': 0.0025165865934568747, 'mean_word_length': 1.8206451612903225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6485186', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1176, 'n_words': 331}