<commit_before>(function ($) {
    $('body').prepend('<h1>It runs! </h1>');

    $.ajax({
        method: 'GET',
        url: 'data/data.json'
    }).done(function (todos) {
        console.log(todos);
        // Got data of all existing todo's, produce the DOM and append to container
        $('#todo-list').append(
            todos.map(function (todo, index) {
                return '' +
                    '<li>' +
                        '<label for="todo-input-' + index + '">' +
                            '<input type="checkbox" id="todo-input-' + index + '">&nbsp;' +
                             todo +
                        '</label>' +
                    '</li>';
            }));
    });

    // handler for add item to the to do list
    $('#add-todo-form').on('submit', function (e) {
        e.preventDefault();
        console.log('submitting to do item', e);

        var newItem = $('#add-todo-form > input').val();

        if (!newItem) {
            alert('Please put something in the input');
            return;
        }

        $.ajax({
            method: 'GET',
            url: 'data/add-item.json'
        }).done(function (data) {
            console.log('add item data', data);
            alert('Item added!');
            // Server responds OK, item added. Now we sync the UI.
            var todo = newItem;
            var index  = $('#todo-list > li').length;
            $('#todo-list').append('' +
                '<li>' +
                    '<label for="todo-input-' + index + '">' +
                        '<input type="checkbox" id="todo-input-' + index + '">&nbsp;' +
                         todo +
                    '</label>' +
                '</li>')
        }).fail(function (xhr) {
            console.warn('add item fail', xhr);
        });

    });


}(jQuery));<commit_msg>DRY - todo item maker<commit_after>(function ($) {
    $('body').prepend('<h1>It runs! </h1>');

    $.ajax({
        method: 'GET',
        url: 'data/data.json'
    }).done(function (todos) {
        console.log(todos);
        // Got data of all existing todo's, produce the DOM and append to container
        $('#todo-list').append(
            todos.map(function (todo, index) {
                return makeTodoItem(todo, index);
            }));
    });

    // handler for add item to the to do list
    $('#add-todo-form').on('submit', function (e) {
        e.preventDefault();
        console.log('submitting to do item', e);

        var newItem = $('#add-todo-form > input').val();

        if (!newItem) {
            alert('Please put something in the input');
            return;
        }

        $.ajax({
            method: 'GET',
            url: 'data/add-item.json'
        }).done(function (data) {
            console.log('add item data', data);
            alert('Item added!');
            // Server responds OK, item added. Now we sync the UI.
            var todo = newItem;
            var index  = $('#todo-list > li').length;
            $('#todo-list').append(makeTodoItem(todo, index));
        }).fail(function (xhr) {
            console.warn('add item fail', xhr);
        });

    });

    function makeTodoItem (text, index) {
        return '<li>' +
                    '<label for="todo-input-' + index + '">' +
                        '<input type="checkbox" id="todo-input-' + index + '">&nbsp;' +
                         text +
                    '</label>' +
                '</li>';
    }


}(jQuery));
{'fraction_non_alphanumeric': 0.17321479782047605, 'fraction_numerical': 0.0011471178663607685, 'mean_word_length': 1.4105044920525225, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 26, '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': '2041346', 'n_tokens_mistral': 1009, 'n_tokens_neox': 993, 'n_words': 244}