<commit_before>var flag = name => location.search.indexOf(name) != -1;

var DEBUG = flag('debug');
var USE_MOCK = flag('use_mock');
var SCAN_INTERVAL = 125 / 2;
var QR_RE = /^([0-9]+)\$\$([a-z0-9]+)\$\$(.+)$/;


var Mock = {
    scanRequest(data) {
        return new Promise($.getJSON('tests.json')).then(
            function(tests) {
                if (!(data in tests)) {
                    // may genuinely glitch out
                    return {
                        status: 0,
                        error: "Invalid code, try again"
                    }
                }

                var resp = tests[data]['response'];
                return (
                    resp === 'fail_request' ?
                    Promise.reject() :
                    resp
                );
            },
            () => console.error("Couldn't load tests")
        )
    }
}


function render_user(user) {
    if (typeof user === "undefined") return "";

    var user = user.user,
        firstName = user.first_name,
        lastName = user.last_name,
        rendered = "";

    if (firstName.length > 0) {
        rendered = firstName;
        if (lastName.length > 0) {
            rendered += lastName;
        }
    }

    return rendered;
}


function was_successful(data) {
    return !(data.status < 1 || data.paid < 1);
}


function messageFromData(data) {
    var message = '',
        user = render_user(data.user);
    if (user.length !== 0) {
        message = "<" + user + "> : " + message;
    }

    if (data.status < 1) {
        if (data.error.length === 0) {
            message = "Unknown error occured";
        } else {
            message = data.error;
        }

    } else if (data.paid < 1){
        message =  "Hasn't paid!";

    } else {
        message = "Sign-in successful";
    }

    return message;
}


function checkCompatibility() {
    if (!navigator.getUserMedia) {
        return "No getUserMedia support";

    } else if (!Modernizr.localstorage) {
        return "No localStorage support";

    } else if (window.location.hostname == 'localhost') {
        return null;

    } else if (window.location.protocol != 'https:') {
        return "Must be accessed over https";
    }

    return null;
}


function get_timestamp(d) {
    var pad = str => ("0" + str).substr(-2),
        hours = pad(d.getHours()),
        minutes = pad(d.getMinutes()),
        seconds = pad(d.getSeconds());

    return `${hours}:${minutes}:${seconds}`;
}


var StatusCube = React.createClass({
    propTypes: {
        "status": React.PropTypes.number.isRequired
    },
    render() {
        var color = ["red", "orange", "green"][this.props.status];
        var style = {
            "width": "25px",
            "height": "25px",
            "float": 'left',
            "backgroundColor": color
        };
        return (
            <div style={style}></div>
        );
    }
})


var Row = React.createClass({<commit_msg>Use template string C:<commit_after>var flag = name => location.search.indexOf(name) != -1;

var DEBUG = flag('debug');
var USE_MOCK = flag('use_mock');
var SCAN_INTERVAL = 125 / 2;
var QR_RE = /^([0-9]+)\$\$([a-z0-9]+)\$\$(.+)$/;


var Mock = {
    scanRequest(data) {
        return new Promise($.getJSON('tests.json')).then(
            function(tests) {
                if (!(data in tests)) {
                    // may genuinely glitch out
                    return {
                        status: 0,
                        error: "Invalid code, try again"
                    }
                }

                var resp = tests[data]['response'];
                return (
                    resp === 'fail_request' ?
                    Promise.reject() :
                    resp
                );
            },
            () => console.error("Couldn't load tests")
        )
    }
}


function render_user(user) {
    if (typeof user === "undefined") return "";

    var user = user.user,
        firstName = user.first_name,
        lastName = user.last_name,
        rendered = "";

    if (firstName.length > 0) {
        rendered = firstName;
        if (lastName.length > 0) {
            rendered += lastName;
        }
    }

    return rendered;
}


function was_successful(data) {
    return !(data.status < 1 || data.paid < 1);
}


function messageFromData(data) {
    var message = '',
        user = render_user(data.user);
    if (user.length !== 0) {
        message = "<" + user + "> : " + message;
    }

    if (data.status < 1) {
        if (data.error.length === 0) {
            message = "Unknown error occured";
        } else {
            message = data.error;
        }

    } else if (data.paid < 1){
        message =  "Hasn't paid!";

    } else {
        message = "Sign-in successful";
    }

    return message;
}


function checkCompatibility() {
    if (!navigator.getUserMedia) {
        return "No getUserMedia support";

    } else if (!Modernizr.localstorage) {
        return "No localStorage support";

    } else if (window.location.hostname == 'localhost') {
        return null;

    } else if (window.location.protocol != 'https:') {
        return "Must be accessed over https";
    }

    return null;
}


function get_timestamp(d) {
    var pad = str => `0${str}`.substr(-2),
        hours = pad(d.getHours()),
        minutes = pad(d.getMinutes()),
        seconds = pad(d.getSeconds());

    return `${hours}:${minutes}:${seconds}`;
}


var StatusCube = React.createClass({
    propTypes: {
        "status": React.PropTypes.number.isRequired
    },
    render() {
        var color = ["red", "orange", "green"][this.props.status];
        var style = {
            "width": "25px",
            "height": "25px",
            "float": 'left',
            "backgroundColor": color
        };
        return (
            <div style={style}></div>
        );
    }
})


var Row = React.createClass({
{'fraction_non_alphanumeric': 0.15019428957594189, 'fraction_numerical': 0.008109477952356817, 'mean_word_length': 1.6475849731663685, 'pattern_counts': {'":': 10, '<': 17, '<?xml version=': 0, '>': 19, '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': '1503698', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1718, 'n_words': 401}