<commit_before>(function() {
    var totalCount = 0;
    var loadAmount = 9;
    var currentImg = 0;

    $(window).scroll(function(e) {
        // Lazy Load when reached the bottom
        if($(window).scrollTop() + $(window).innerHeight() >= $('.gallery')[0].scrollHeight) {
            loadImageSet();
        }
    });

    var temp = "<li><a><img class='gal-img' src=''/></a></li>";

    function loadImageSet() {
        var c = Math.min(totalCount + 1, currentImg + loadAmount);
        for (var i = currentImg; i < c; i++) {
           getImage(i);
        }
        currentImg = c
    }

    function getImage(i) {
        var newImage = $(temp);
        newImage.find('img').attr("src", '/images/' + i);
        newImage.find('a').attr("href", '/detail/' + i);

        $('.gallery-list').prepend(newImage);
    }

    $.ajax({
        url: '/count',
        type: 'GET',
        success: function (data) {
            totalCount = data.count;

            loadImageSet();
        },
         error: function (error) {
            console.log('fail: ' + data);
        }
    });

})()<commit_msg>Made gallery load newest [highest index] first. If redirected from juxtagraph, image you just created will be in first spot<commit_after>(function() {
    var totalCount = 0;
    var loadAmount = 9;
    var currentImg = 0;
    var temp = "<li><a><img class='gal-img' src=''/></a></li>";

    $(window).scroll(function(e) {
        // Lazy Load when reached the bottom
        if (totalCount == 0) {
            return;
        }

        if($(window).scrollTop() + $(window).innerHeight() >= $('.gallery')[0].scrollHeight) {
            loadImageSet();
        }
    });

    function loadImageSet() {
        var c = Math.max(-1, currentImg - loadAmount);
        for (var i = currentImg; i > c; i--) {
           getImage(i);
        }
        currentImg = c
    }

    function getImage(i) {
        var newImage = $(temp);
        newImage.find('img').attr("src", '/images/' + i);
        newImage.find('a').attr("href", '/detail/' + i);

        $('.gallery-list').append(newImage);
    }

    $.ajax({
        url: '/count',
        type: 'GET',
        success: function (data) {
            totalCount = data.count;
            currentImg = data.count;

            loadImageSet();
        },
         error: function (error) {
            console.log('fail: ' + data);
        }
    });

})()
{'fraction_non_alphanumeric': 0.1769837972579975, 'fraction_numerical': 0.004570004154549232, 'mean_word_length': 1.846335697399527, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 16, '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': '2717228', 'n_tokens_mistral': 754, 'n_tokens_neox': 720, 'n_words': 168}