<commit_before>define(function(require) {
    var sandbox = require('./sandbox');
    var groups = require('./examples');
    var parallel = require('./utils/async').parallel;
    var prop = require('./utils/common').prop;
    var $ = require('jquery');

    // https://github.com/josscrowcroft/javascript-sandbox-console
    function initCommands($p, editor, previews, dims) {
        $p.append($playback(editor, previews, dims));
        $p.append($templates(editor, groups));
    }

    function $playback(editor, previews, dims) {
        var playClass = 'play';
        var stopClass = 'stop';
        var sb = sandbox();

        // XXX: presumes deps are in the right order
        sandbox.load(sb, ['module',
            'components/is/is', 'components/annotate.js/lib/annotate',
            'cube', 'math', 'object',
            'functional'], function() {
            sb.inject(sb.functional, sb.window);
        });

        return $('<div>', {'class': 'playback command'}).
            addClass(playClass).
            on('click', function() {
                var $e = $(this);

                if($e.hasClass(stopClass)) $e.addClass(playClass).removeClass(stopClass);
                else {
                    $e.addClass(stopClass).removeClass(playClass);

                    sb.eval('function getInit() {var init;' +
                        editor.getValue() +
                        ';return init;}'
                    );
                    var res = sb.evaluateInit(sb.getInit(), dims);

                    previews.evaluate(res, function(vars, ticks) {
                        sb.ticks = ticks;
                        sb.eval('function getEffect() {var effect;' +
                            editor.getValue() +
                            ';return effect;}'
                        );

                        var ret = sb.evaluateEffect(sb.getEffect(), dims, vars);
                        ret.playing = $e.hasClass(stopClass);

                        return ret;
                    });
                }

            });
    }

    function encapsulate(code) {
        return '(function() {' + code + '})();';
    }

    function dimsToString(dims) {
        return '{x: ' + dims.x + ', y: ' + dims.y + ', z: ' + dims.z +'}';
    }

    function $templates(editor, groups) {
        var $ret = $('<select/>', {'class': 'codeTemplates'});

        $ret.append($('<option/>'));

        for(var group in groups) {
            generateGroups($ret, group, getUrls(group, groups[group]));
        }

        $ret.on('change', function() {
            var $e = $(this);
            var val = $e.val();

            if(val) editor.setValue($(':selected', $e).data('code'));
        });

        return $ret;
    }

    function generateGroups($p, group, urls) {
        parallel(function(url, cb, i) {
            $.get(url, function(code) {
                cb(null, {url: url, i: i, code: code});
            });
        }, Object.keys(urls), function(err, data) {
            createOptions(err, data, group, urls, $p);
        });
    }

    function createOptions(err, data, group, urls, $p) {<commit_msg>Remove some redundant code<commit_after>define(function(require) {
    var sandbox = require('./sandbox');
    var groups = require('./examples');
    var parallel = require('./utils/async').parallel;
    var prop = require('./utils/common').prop;
    var $ = require('jquery');

    // https://github.com/josscrowcroft/javascript-sandbox-console
    function initCommands($p, editor, previews, dims) {
        $p.append($playback(editor, previews, dims));
        $p.append($templates(editor, groups));
    }

    function $playback(editor, previews, dims) {
        var playClass = 'play';
        var stopClass = 'stop';
        var sb = sandbox();

        // XXX: presumes deps are in the right order
        sandbox.load(sb, ['module',
            'components/is/is', 'components/annotate.js/lib/annotate',
            'cube', 'math', 'object',
            'functional'], function() {
            sb.inject(sb.functional, sb.window);
        });

        return $('<div>', {'class': 'playback command'}).
            addClass(playClass).
            on('click', function() {
                var $e = $(this);

                if($e.hasClass(stopClass)) $e.addClass(playClass).removeClass(stopClass);
                else {
                    $e.addClass(stopClass).removeClass(playClass);

                    sb.eval('function getInit() {var init;' +
                        editor.getValue() +
                        ';return init;}'
                    );
                    var res = sb.evaluateInit(sb.getInit(), dims);

                    previews.evaluate(res, function(vars, ticks) {
                        sb.ticks = ticks;
                        sb.eval('function getEffect() {var effect;' +
                            editor.getValue() +
                            ';return effect;}'
                        );

                        var ret = sb.evaluateEffect(sb.getEffect(), dims, vars);
                        ret.playing = $e.hasClass(stopClass);

                        return ret;
                    });
                }

            });
    }

    function $templates(editor, groups) {
        var $ret = $('<select/>', {'class': 'codeTemplates'});

        $ret.append($('<option/>'));

        for(var group in groups) {
            generateGroups($ret, group, getUrls(group, groups[group]));
        }

        $ret.on('change', function() {
            var $e = $(this);
            var val = $e.val();

            if(val) editor.setValue($(':selected', $e).data('code'));
        });

        return $ret;
    }

    function generateGroups($p, group, urls) {
        parallel(function(url, cb, i) {
            $.get(url, function(code) {
                cb(null, {url: url, i: i, code: code});
            });
        }, Object.keys(urls), function(err, data) {
            createOptions(err, data, group, urls, $p);
        });
    }

    function createOptions(err, data, group, urls, $p) {
{'fraction_non_alphanumeric': 0.15766062602965403, 'fraction_numerical': 0.0, 'mean_word_length': 1.61006018916595, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '7417459', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1637, 'n_words': 347}