text:
var cplane, dialogWM, toolWM;
var generateRandomColour;
(function () {
    var genHues = [];

    generateRandomColour = function (sat, val) {
        var hue, tries = 0, acceptableDiff = 50*Math.pow(0.9, genHues.length);
        do {
            hue = Math.floor(Math.random() * 360);
            var diffs = genHues.map(function (e) { return Math.abs(hue - e); });
            var minDiff = Math.min.apply(this, diffs);
        } while (minDiff < acceptableDiff && tries++ < 20);

        var c = new Colour();
        c.setHSV(hue, sat, val);
        genHues.push(hue);
        return c;
    };
})();

function MathJSFunction(expr, scope) {
    this.expr = expr;
    this.node = math.parse(expr);
    this.compiledNode = this.node.compile();
    this.scope = scope || {};
    this.className = "MathJSFunction";
    this.type = "cartesian";
    this.variables = [];
    if (scope) for (var prop in scope) if (scope.hasOwnProperty(prop)) {
        this.variables.push(prop);
    }
}
MathJSFunction.prototype.eval = function (v) {
    return this.compiledNode.eval(this.scope)(v);
};
MathJSFunction.prototype.get = function (variableName) {
    return this.scope[variableName];
};
MathJSFunction.prototype.set = function (variableName, v) {
    this.scope[variableName] = v;
};
MathJSFunction.prototype.serialise = function () {
    return {
        expr: this.expr,
        scope: this.scope,
        className: this.className
    };
};
MathJSFunction.deserialise = function (obj) {
    return new MathJSFunction(obj.expr, obj.scope);
};
MathJSFunction.prototype.toString = function () {
    return this.node.toString().replaceAll(/ *function +/g, "")
        .replaceAll(/ +/g, "")
        .replaceAll(/([+\-=])/g, " $1 ")
        .replaceAll(/([,])/g, "$1 ");
};

function MathJSPolarFunction(expr, scope) {
    MathJSFunction.call(this, expr, scope);
    this.className = "MathJSPolarFunction";
    this.type = "polar";
}
MathJSPolarFunction.prototype = Object.create(MathJSFunction.prototype);
MathJSPolarFunction.prototype.constructor = MathJSPolarFunction;
MathJSPolarFunction.deserialise = function (obj) {
    return new MathJSPolarFunction(obj.expr, obj.scope);
};

function MathJSParametricFunction(exprX, exprY, scope) {
    this.exprX = exprX;
    this.exprY = exprY;
    var expr = "f(t) = [" + exprX + ", " + exprY + "]";
    MathJSFunction.call(this, expr, scope);
    this.compiledNode = this.node.compile();
    this.className = "MathJSParametricFunction";
    this.type = "parametric";
}
MathJSParametricFunction.prototype = Object.create(MathJSFunction.prototype);
MathJSParametricFunction.prototype.constructor = MathJSParametricFunction;
MathJSParametricFunction.prototype.eval = function (v) {
    var data = this.compiledNode.eval(this.scope)(v)._data;
    return new Vector2D(data[0], data[1]);
};
MathJSParametricFunction.prototype.serialise = function () {
    return {
        exprX: this.exprX,
        exprY: this.exprY,
        scope: this.scope,
        className: this.className
    };
};
MathJSParametricFunction.deserialise = function (obj) {
    return new MathJSParametricFunction(obj.exprX, obj.exprY, obj.scope);
};

function PlaneNode() {
    this.id = generateUUID();
    this.name = "";
    this.visible = true;
    this.draw = function () {};
}

/**
 * Node for MathFunctions that handles drawing independently of the canvas.
 * @param func The MathFunction that is to be drawn to the canvas.
 * @param style A colour code for styling the line drawn.
 * @param start An X value where the drawing will begin (null if fully continuous)
 * @param end An X value where the drawing will end (null if fully continuous)
 * @constructor
 */
function FunctionNode(func, style, start, end) {
    PlaneNode.call(this);
    this.func = func;
    this.style = style ? new Colour(style) : generateRandomColour(0.8, 0.8);
    this.start = isNull(start) ? null : start; // null = edge of screen for cartesian funcs
    this.end = isNull(end) ? null : end;
    this.resolution = 50; // inverse of parameter step
    this.derivative = {
        visible: false,
        style: null
    };
    this.integral = {
        visible: false,
        style: null
    };
    this.draw = function (plane) {
        try {
            this.func.eval(2);
        } catch (e) {
            TBI.error("Function error: " + e.message);
            this.visible = false;
        }
        if (!plane.plugins.scale || !this.visible) return;
        var scalePlugin = plane.plugins.scale,
            self = this;

        var set = plane.settings.functions, scaleSet = scalePlugin.settings.scale;
        var threshold = set.threshold;
        var start, end, step, loc;
        var path = new SVGPathBuilder(plane.helper),
            derivativePath = new SVGPathBuilder(plane.helper),
            integralPath = new SVGPathBuilder(plane.helper);

        function isValid(loc) {
            return loc.clamp(threshold.negate(), threshold).equals(loc);
        }

        var lastCoord;
        function addCoord(coord) {
            loc = plane.getLocationOfCoordinate(coord);
            if (isValid(loc))
                path.append(loc);
            else path.close();
            if (self.integral.visible) {
                if (isNull(lastCoord))
                    integralPath.append(
                        plane.getLocationOfCoordinate(
                            new Vector2D(coord.x, 0)));

                if (isValid(loc))
                    integralPath.append(loc);
                else if (!isNull(lastCoord))
                    integralPath.append(
                        plane.getLocationOfCoordinate(
                            new Vector2D(lastCoord.x, 0)));
            }
            if (self.derivative.visible && !isNull(lastCoord)) {
                var rise = coord.y - lastCoord.y,
                    run = coord.x - lastCoord.x;
                loc = plane.getLocationOfCoordinate(new Vector2D(
                    (coord.x + lastCoord.x) / 2,
                    rise / run
                ));
                if (isValid(loc))
                    derivativePath.append(loc);
                else derivativePath.close();
            }

            lastCoord = coord;
        }

        switch (this.func.type.toLowerCase()) {
            case "cartesian":
                var factor = plane.getFactor();
                var scaleX = plane.computeScale(factor.x, scaleSet.minInterval, scaleSet.maxInterval);

                if (this.start == null) {
                    start = plane.getCoordinateFromLocation(new Vector2D(0 - (factor.x * scaleX), 0)).x;
                    start = Math.ceil(start/scaleX)*scaleX;
                } else start = this.start;

                if (this.end == null) {
                    end = plane.getCoordinateFromLocation(new Vector2D(plane.width + (factor.x * scaleX), 0)).x;
                    end = Math.ceil(end/scaleX)*scaleX;
                } else end = this.end;

                step = scaleX/this.resolution;

                for (var x=start;x<=end;x+=step)
                    addCoord(new Vector2D(x, this.func.eval(x)));
                addCoord(new Vector2D(end, this.func.eval(end)));

                break;
            case "polar":
                this.start = start = this.start || -16;
                this.end = end = this.end || 16;
                step = 1/this.resolution;

                start *= Math.PI;
                end *= Math.PI;
                step *= Math.PI;

                for (var a=start;a<=end;a+=step)
                    addCoord(Vector2D.fromPolar(a, this.func.eval(a)));
                addCoord(Vector2D.fromPolar(end, this.func.eval(end)));

                break;
            case "parametric":
                this.start = start = this.start || -16;
                this.end = end = this.end || 16;
                step = 1/this.resolution;

                start *= Math.PI;
                end *= Math.PI;
                step *= Math.PI;

                for (var t=start;t<=end;t+=step)
                    addCoord(this.func.eval(t));
                addCoord(this.func.eval(end));

                break;
            default:
                break;
        }

        //plane.$.globalCompositeOperation = "destination-over";
        //plane.helper.linePlot(plot, this.width, this.style);
        //plane.$.globalCompositeOperation = "source-over";
        var plot = path.apply([this.id, "func"].join(" "), "functions");
        plot.style.stroke = this.style.toRGBA();

        if (this.derivative.visible) {
            var dplot = derivativePath.apply([this.id, "derivative"].join(" "), "functions");
            dplot.style.stroke = isNull(this.derivative.style) ?
                this.style.toRGBA() :
                this.derivative.style.toRGBA();
        }
        if (this.integral.visible) {
            if (lastCoord)
                integralPath.append(
                    plane.getLocationOfCoordinate(
                        new Vector2D(lastCoord.x, 0)));
            integralPath.close(true);

            var iplot = integralPath.apply([this.id, "integral"].join(" "), "functions");
            iplot.style.stroke = "transparent";
            iplot.style.fill = isNull(this.integral.style) ?
                this.style.toRGBA() :
                this.integral.style.toRGBA();
        }

        plane.helper.appendGroup("functions");
    };
    this.serialise = function () {
        var obj = {
            id: this.id,
            visible: this.visible,
            start: this.start,
            end: this.end,
            style: this.style.toRGBA(),
            resolution: this.resolution,
            derivative: {
                visible: this.derivative.visible,
                style: this.derivative.style ? this.derivative.style.toRGBA() : null
            },
            integral: {
                visible: this.integral.visible,
                style: this.integral.style ? this.integral.style.toRGBA() : null
            },
            func_type: this.func.type.toLowerCase(),
            className: this.func.className,
            variables: {}
        };

        var self = this;
        if (this.func.variables) this.func.variables.forEach(function (e) {
            obj.variables[e] = self.func.scope[e];
        });
        if (this.func.serialise)
            obj.func = this.func.serialise();
        else obj.func = objectToInputs(this, true);
        return JSON.stringify(obj);
    };
}
FunctionNode.prototype = Object.create(PlaneNode.prototype);
FunctionNode.prototype.constructor = FunctionNode;
FunctionNode.deserialise = function (str) {
    var obj = JSON.parse(str);
    var func;
    if (obj.className && window[obj.className]
        && typeof(window[obj.className].deserialise) == "function") {
        func = window[obj.className].deserialise(obj.func);
    }

    if (isNull(func)) {
        var funcstr = null;
        if (!isNull(obj.func[0]) && obj.func[0].search(/^f\([A-Za-z]\) *= */) != -1)
            funcstr = obj.func[0];

        switch (obj.func_type) {
            case "cartesian":
                func = new MathJSFunction(funcstr || "f(x) = " + obj.func[0], obj.variables);
                break;
            case "polar":
                func = new MathJSPolarFunction(funcstr || "f(a) = " + obj.func[0], obj.variables);
                break;
            case "parametric":
                func = new MathJSParametricFunction(obj.func[0], obj.func[1], obj.variables);
                break;
            default:
                func = null;
        }
    }

    if (isNull(func)) return;
    var node = new FunctionNode(func, obj.style, obj.start, obj.end);
    node.id = obj.id || generateUUID();
    node.visible = isNull(obj.visible) ? true : obj.visible;
    node.resolution = obj.resolution;
    node.derivative = {
        visible: obj.derivative.visible,
        style: obj.derivative.style ? new Colour(obj.derivative.style) : null
    };
    node.integral = {
        visible: obj.integral.visible,
        style: obj.integral.style ? new Colour(obj.integral.style) : null
    };
    return node;
};

var PlotTypes = {"line": "line", "scatter": "scatter"};

function PlotNode(plot, type, style) {
    PlaneNode.call(this);
    this.plot = plot.map(function (o) {
        if (o instanceof Vector2D)
            return o;
        else if (o.length && o.length == 2)
            return new Vector2D(o[0], o[1]);
        else if (!isNull(o['x']) && !isNull(o['y']))
            return new Vector2D(o.x, o.y);
    });
    this.type = type || "line";
    this.style = style ? new Colour(style) : generateRandomColour(0.8, 0.8);
    this.closed = false;
    this.matrix = [[1,0],[0,1]];

    this.draw = function (plane) {
        if (!this.visible) return;
        var threshold = plane.settings.functions.threshold;

        var path, self = this;
        switch (this.type) {
            case "scatter":
                path = new SVGPathCollectionBuilder(plane.helper, function (builder, coord) {
                    var locs = [
                        new Vector2D(4, 4),
                        new Vector2D(-4, 4),
                        new Vector2D(4, -4),
                        new Vector2D(-4, -4)
                    ];
                    locs.forEach(function (e) {
                        builder.move(coord);
                        builder.line(e, true);
                    });
                    builder.close();
                }, function (path) {
                    path.style.stroke = self.style.toRGBA();
                }, [this.id, "plot"].join(" "), "plots");

                this.plot.forEach(function (e) {
                    var image = new Vector2D(0, 0);
                    image.x = self.matrix[0][0] * e.x
                            + self.matrix[0][1] * e.y;
                    image.y = self.matrix[1][0] * e.x
                            + self.matrix[1][1] * e.y;

                    var loc = plane.getLocationOfCoordinate(image);
                    if (loc.clamp(threshold.negate(), threshold).equals(loc))
                        path.append(loc);
                });

                break;
            case "line":
            default:
                path = new SVGPathBuilder(plane.helper);

                this.plot.forEach(function (e) {
                    var image = new Vector2D(0, 0);
                    image.x = self.matrix[0][0] * e.x
                            + self.matrix[0][1] * e.y;
                    image.y = self.matrix[1][0] * e.x
                            + self.matrix[1][1] * e.y;

                    var loc = plane.getLocationOfCoordinate(image);
                    if (loc.clamp(threshold.negate(), threshold).equals(loc))
                        path.append(loc);
                    else path.close();
                });
                path.close(self.closed);

                var plot = path.apply([this.id, "plot"].join(" "), "plots");
                plot.style.stroke = this.style.toRGBA();
        }

        plane.helper.appendGroup("plots");
    };
    this.serialise = function () {
        var obj = {
            id: this.id,
            name: this.name,
            visible: this.visible,
            plot: this.plot,
            type: this.type,
            style: this.style.toRGBA(),
            closed: this.closed,
            matrix: this.matrix
        };
        return JSON.stringify(obj);
    };
}
PlotNode.prototype = Object.create(PlaneNode.prototype);
PlotNode.prototype.constructor = PlotNode;
PlotNode.deserialise = function (str) {
    var obj = JSON.parse(str);
    var node = new PlotNode(obj.plot, obj.type, obj.style);
    node.id = obj.id;
    node.visible = obj.visible;
    node.closed = obj.closed;
    node.name = obj.name;
    node.matrix = [[1,0],[0,1]];
    if (!isNull(obj.matrix) && !isNull(obj.matrix[0]) && !isNull(obj.matrix[1])) {
        node.matrix = obj.matrix;
    }

    return node;
};

function CrtPlanePlugin(config) {
    var noop = function () {},
        self = this;

    this.config = config;
    this.name = config.name;
    this.settings = config.settings || {};
    this.draw = function (plane) {
        return (config.draw || noop)(plane, self);
    };
    this.update = function (plane) {
        return (config.update || noop)(plane, self);
    };
    this.tick = function (plane) {
        return (config.tick || noop)(plane, self);
    };
    this.creation = function (plane) {
        return (config.creation || noop)(plane, self);
    };

    var pub = config.iface || {};

    for (var prop in pub) if (pub.hasOwnProperty(prop))
        this[prop] = pub[prop];
}

var objectToInputs;
$(function () {
Require([
    "/assets/js/tblib/base.js",
    "/assets/js/tblib/util.js",
    "/assets/js/tblib/loader.js",
    "/assets/js/tblib/math.js",
    "/assets/js/tblib/ui.js",
    "/assets/js/jswm2.js",
    "/assets/js/math.min.js"
], function () {

    function CrtPlane3(svg, parent) {
        if (isNull(parent)) parent = $(svg).parent()[0];
        WideSVG.call(this, svg, parent);
        this.settings = {
            functions: {
                threshold: new Vector2D(4e4, 2e4)
            }
        };
        this.plugins = {

        };
        this.objects = {

        };
        this.state = {
            center: new Vector2D(0, 0),
            extents: new Vector2D(32, 18),
            dimensions: new Vector2D(0, 0)
        };
        this.previous = {

        };
        this.triggerNextUpdate = true;

        this.addPlugin = function (plugin) {
            if (isNull(plugin)) return this;
            this.plugins[plugin.name] = plugin;

            var currSettings = Object.copy(this.settings);
            this.updateSettings(plugin.settings, "settings");
            this.updateSettings(currSettings, "settings");

            var currState = Object.copy(this.state);
            this.updateSettings(plugin.state, "state");
            this.updateSettings(currState, "state");

            this.updateSettings(plugin.config.iface);

            this.addEventHandler("update", plugin.update);
            this.addEventHandler("tick", plugin.tick);
            this.addEventHandler("draw", plugin.draw);
            plugin.creation(this);

            return this;
        };
        this.addObject = function (constructor) {
            var node = new (constructor.bind.apply(constructor, arguments));
            this.objects[node.id] = node;
            this.triggerNextUpdate = true;
            this.triggerEvent("new-object", node);
            return this;
        };

        this.getProperty = function (property) {
            var propTree = property.split(".");
            for (var i=0,c=this;i<propTree.length-1;i++) {
                c = c[propTree[i]];
                if (c === undefined) return null;
            }
            return c[propTree[propTree.length-1]];
        };
        this.setProperty = function (property, value, ignore) {
            var propTree = property.split(".");
            for (var i=0,c=this;i<propTree.length-1;i++) {
                c = c[propTree[i]];
                if (c === undefined) return null;
            }
            c[propTree[propTree.length-1]] = value;
            if (!ignore) this.triggerNextUpdate = true;
        };

        this.updateSettings = function (obj, name, ignore) {
            if (!isNull(name)) name += ".";
            else name = "";

            for (var prop in obj) if (obj.hasOwnProperty(prop)) {
                if (!isNull(this.getProperty(name+prop)) && typeof(obj[prop]) == "object") {
                    if (obj[prop].constructor == Object)
                        this.updateSettings(obj[prop], name+prop, ignore);
                    else if (typeof(obj[prop].copy) == "function")
                        this.setProperty(name+prop, obj[prop].copy(), ignore);
                    else
                        this.setProperty(name+prop, obj[prop], ignore);
                } else this.setProperty(name+prop, obj[prop], ignore);
            }
            return this;
        };

        this.getFactor = function () { return new Vector2D(this.width, this.height).divide(this.state.extents); };
        this.getLocationOfCoordinate = function (coord) { return this.helper.getLocationOfCoordinate(coord, this.state.extents, this.state.center); };
        this.getCoordinateFromLocation = function (loc) { return this.helper.getCoordinateFromLocation(loc, this.state.extents, this.state.center); };

        this.loop = function (delta) {
            var dims = new Vector2D(this.width, this.height);
            this.state.dimensions = dims;
            if (isNull(this.previous.dimensions) || !this.previous.dimensions.equals(dims))
                this.triggerNextUpdate = true;

            this.triggerEvent("tick", delta);
            if (this.triggerNextUpdate) {
                this.triggerEvent("update");
                this.draw();
                this.triggerEvent("post-update");
                this.triggerNextUpdate = false;
            }
            this.updateSettings(this.state, "previous", true);
        };

        this.draw = function () {
            this.helper.clear();

            for (var obj in this.objects) if (this.objects.hasOwnProperty(obj)) {
                this.objects[obj].draw(this);
            }

            this.triggerEvent("draw");
        }
    }
    CrtPlane3.prototype = Object.create(WideSVG.prototype);
    CrtPlane3.MasterSettings = {
        scale: {
            minor: {
                minInterval: 25,
                maxInterval: 35
            },
            minInterval: 75,
            maxInterval: 110
        }
    };

    var plugins = {};
    function loadPlugin(pluginName) {
        loader.addTask(function (resolve) {
            require("/assets/js/apps/crtpl3-"+pluginName+".js", function (plugin) {
                plugins[plugin.name] = plugin;
                resolve();
            });
        });
    }

    loadPlugin("scale");
    loadPlugin("anim");
    loadPlugin("nav");
    loadPlugin("persist");
    loader.start();

    PlotTypes = new Enum("line", "scatter");

    $(document).on("pageload", function () {
        cplane = new CrtPlane3(gebi("main-plane"))
            .addPlugin(plugins["scale"])
            .addPlugin(plugins["animation"])
            .addPlugin(plugins["navigation"])
            .addPlugin(plugins["persistency"]);

        dialogWM = new JSWM($(".dialog-container")[0]);
        toolWM = new JSWM($(".tool-container")[0]);

        if (!isNull(localStorage.getItem("crtpl3-save")))
            cplane.load(localStorage.getItem("crtpl3-save"));
        else {
            cplane.updateSettings(CrtPlane3.MasterSettings, "settings");
            var demoObjects = [
                new MathJSFunction("f(x) = 3x^3 + (1/5)x^2 - 3x - 2"),
                //new RelationFunc(2, 3, 10),
                new MathJSFunction("f(x) = sin(x)"),
                new MathJSFunction("f(x) = 2^x"),
                new MathJSPolarFunction("f(a) = 2sin(4a)"),
                new MathJSParametricFunction(
                    "sin(a t)",
                    "cos(b t)",
                    {a: 1, b: 0.9}
                )
            ];
            demoObjects.forEach(function (e) {
                cplane.addObject(FunctionNode, e);
            });
        }

        $("[data-icon-src]").each(function () {
            var self = $(this);

            var src = self.attr("data-icon-src");
            $.ajax({
                url: src,
                success: function (response) {
                    self[0].appendChild(response.documentElement);
                }
            });
        });

        function bindToPlane(query, evt, planeEvt) {
            if (isNull(planeEvt)) planeEvt = evt;
            $(query).on(evt, function (event) {
                cplane.triggerEvent(planeEvt, event);
            });
        }

        function refreshUI() {
            var id = $(".object-list").val();
            var obj = cplane.objects[id];
            if (isNull(id) || id == "-" || isNull(obj)) {
                $(".fn-defined-only").removeClass("fn-defined");
                return;
            }

            // $("svg .selected").removeClass("selected");
            $("svg .selected").attr("class", function (i, c) {
                if (!c) return;
                return c.replace(/(^| )selected($| )/g, "$1$2");
            });
            // $("."+id).addClass("selected");
            $("svg ."+id).attr("class", function (i, c) {
                if (!c) return;
                return c + " selected";
            });

            TBI.UI.toggleButton($(".hide-function")[0], obj.visible, true);
            $(".fn-defined-only").addClass("fn-defined");

            updateInfoBox();
            updateScaleLocking();
        }

        function getCurrentObject() {
            var id = $(".object-list").val();
            if (isNull(id) || id == "-") return null;

            return cplane.objects[id];
        }

        function bindToSelectedObject(query, handler, evt) {
            if (isNull(evt)) evt = "click";
            $(query).on(evt, function (event, args) {
                handler.apply(this, [getCurrentObject(), event, args]);
                cplane.triggerNextUpdate = true;
            });
        }

        function updateScaleLocking() {
            if (!cplane.plugins["navigation"]) return;
            var set = cplane.settings.controls,
                x = TBI.UI.isToggled($(".lock-x")[0]),
                y = TBI.UI.isToggled($(".lock-y")[0]);

            if (!x && !y) set.mode = "free";
            else if (x && !y) set.mode = "x-fixed";
            else if (!x && y) set.mode = "y-fixed";
            else set.mode = "square";
        }

        function updateObjectList() {
            var select = $(".object-list")[0];
            var obj = {};
            for (var prop in cplane.objects) if (cplane.objects.hasOwnProperty(prop))
                obj[prop] = prop;

            TBI.UI.fillSelect(select, obj, function (option, id) {
                var o = cplane.objects[id];

                if (o.name) option.textContent = o.name;
                else if (o.func) option.innerHTML = o.func.toString(true);
                else if (o.plot) option.innerHTML = o.plot.toString();

                if (!o.visible)
                    option.className += " hidden";
                return option;
            });
        }

        function switchView(val) {
            $(".info-box").slideDown();
            $(".info-box-view-select li").removeClass("active");
            $(".info-box-view-select li[rel='"+val+"']").addClass("active");
            $(".info-box-view").removeClass("show");
            $(".info-box "+val).addClass("show");
        }

        function evalExpression(expr, el) {
            try {
                var f = math.parse(expr).compile();
                var val = f.eval(getVariableObject());
                if (el) $(el).val(val);
                return isNull(val) ? 0 : val;
            } catch (e) {
                TBI.error("Failed to evaluate expression: " + e.message);
            }
        }

        objectToInputs = function (obj) {
            function normalise(str) {
                return str.removeAll(/f\([^\)]*\) *= */);
            }
            switch (obj.func.type.toLowerCase()) {
                case "cartesian":
                case "polar":
                    return [
                        normalise(obj.func.toString())
                    ];
                case "parametric":
                    var str = obj.func.toString();
                    return normalise(str)
                        .replace(/^[\(\[]/, "")
                        .replace(/[\)\]]$/, "")
                        .split(", ");
                default:
                    return [];
            }
        };

        function updateInfoBox() {
            var obj = getCurrentObject();
            var $v = $(".info-box .edit-function-view"),
                $p = $(".info-box .edit-plot-view");

            if (isNull(obj)) {

                $v.find(".function-id").val("");
                $v.find(".function-type").val("cartesian").trigger("change");
                $v.find(".function-colour").val(generateRandomColour(0.8, 0.8).toHex());
                $v.find(".function-start").val("");
                $v.find(".function-end").val("");
                $v.find(".function-resolution").val(50);
                $v.find(".function-inputs .function-input").val("");
                TBI.UI.fillSelect($v.find(".variable-select")[0], {});
                $v.find(".variable-select").val("new").trigger("change");
                TBI.UI.toggleButton($v.find(".derivative-toggle")[0], false);
                TBI.UI.toggleButton($v.find(".integral-toggle")[0], false);

                $p.find(".plot-id").val("");
                $p.find(".plot-type").val("line").trigger("change");
                $p.find(".plot-colour").val(generateRandomColour(0.8, 0.8).toHex());
                $p.find(".plot-matrix").find(".0-1,.1-0").val(0);
                $p.find(".plot-matrix").find(".0-0,.1-1").val(1);
                $p.find(".plot-name").val("");
                TBI.UI.toggleButton($p.find(".plot-closed")[0], false);
                $p.find(".plot-input").val("(0, 1), (2, 3)");

            } else if (obj instanceof FunctionNode) {

                //switchView(".edit-function-view");
                $v.find(".function-id").val(obj.id);
                $v.find(".function-type")
                    .val(obj.func.type.toLowerCase())
                    .trigger("change");
                $v.find(".function-colour").val(obj.style ? obj.style.toHex() : generateRandomColour().toHex());
                $v.find(".function-start").val(isNull(obj.start) ? "" : obj.start);
                $v.find(".function-end").val(isNull(obj.end) ? "" : obj.end);
                $v.find(".function-resolution").val(obj.resolution);
                TBI.UI.toggleButton($v.find(".derivative-toggle")[0], obj.derivative.visible);
                TBI.UI.toggleButton($v.find(".integral-toggle")[0], obj.integral.visible);

                var inputs = objectToInputs(obj);
                $v.find(".function-inputs.show .function-input")
                    .each(function (i, e) {
                        if (i < inputs.length)
                            $(e).val(inputs[i]);
                        else
                            $(e).val("");
                    });

                var vars = {
                    "new": null
                };
                if (obj.func.variables) obj.func.variables.forEach(function (e) {
                    vars[e] = obj.func.scope[e];
                });

                var selection = $v.find(".variable-select").val();
                TBI.UI.fillSelect($v.find(".variable-select")[0], vars, function (option, prop, val) {
                    option.innerHTML = prop;
                    option.value = prop;
                    option.dataset.value = val;
                    return option;
                });
                $v.find(".variable-select").val(selection || "-").trigger("change");

            } else if (obj instanceof PlotNode) {

                //switchView(".edit-plot-view");
                $p.find(".plot-id").val(obj.id);
                $p.find(".plot-type")
                    .val(obj.type.toLowerCase())
                    .trigger("change");
                $p.find(".plot-colour").val(obj.style ? obj.style.toHex() : generateRandomColour().toHex());
                $p.find(".plot-matrix.0-0").val(obj.matrix[0][0]);
                $p.find(".plot-matrix.0-1").val(obj.matrix[0][1]);
                $p.find(".plot-matrix.1-0").val(obj.matrix[1][0]);
                $p.find(".plot-matrix.1-1").val(obj.matrix[1][1]);
                $p.find(".plot-name").val(obj.name || "");
                TBI.UI.toggleButton($p.find(".plot-closed")[0], obj.closed);

                $p.find(".plot-input").val(obj.plot.map(function (v) { return v.toString(); }).join(", "));

            } else {
                TBI.error("Object type not supported");
            }

        }

        function getVariableObject() {
            var obj = {};
            $(".variable-select").find("option").each(function (i, e) {
                if (!isNaN(parseFloat(e.dataset.value)))
                    obj[e.value] = parseFloat(e.dataset.value);
            });
            return obj;
        }

        function setVariable() {
            var el = $(".variable-value");
            var val = evalExpression(el.val(), el);

            var currVar = $(".variable-select").val() || "";
            var option = $(".variable-select").find("option[value='"+currVar+"']");
            if (option.length == 0 || currVar == "new")
                currVar = addVariable();
            else
                option.attr("data-value", val);

            return currVar;

        }

        function addVariable() {
            var select = $(".variable-select")[0];
            var currVar = $(select).val() || "";
            if (currVar.toLowerCase() != "new") {
                $(".variable-select")
                    .val("new")
                    .trigger("change");
                return;
            }
            var name = $(".variable-name").val();
            if (isNull(name)) return;
            var valEl = $(".variable-value");
            var value = evalExpression(valEl.val(), valEl);

            var option = $(select).find("option[value='"+name+"']");
            if (option.length > 0) {
                option = option[0];
                option.dataset.value = value;
            } else {
                option = document.createElement("option");
                option.innerHTML = name;
                option.value = name;
                option.dataset.value = value;
                select.appendChild(option);
            }

            TBI.UI.updateSelect(select);
            $(select).val(name)
                .trigger("change");
            return name;
        }

        function inputsToMathFunction() {
            try {
                var result = null;
                var inputList = $(".function-inputs.show .function-input").map(function (i, e) { return $(e).val(); });
                switch ($(".function-type").val()) {
                    case "cartesian":
                        result = new MathJSFunction("f(x) = " + inputList[0], getVariableObject());
                        break;
                    case "polar":
                        result = new MathJSPolarFunction("f(a) = " + inputList[0], getVariableObject());
                        break;
                    case "parametric":
                        result = new MathJSParametricFunction(inputList[0], inputList[1], getVariableObject());
                        break;
                    default:
                        return null;
                }
                if (isNull(result)) return null;

                result.eval(2);
                return result;
            } catch (e) {
                TBI.error("Function failed to parse: " + e.message);
                return null;
            }
        }

        function inputsToPlot() {
            try {
                var result = null;
                var coords = $(".plot-input").val().replaceAll(/(^\(|\)$)/g, "").split(/\), *\(/);
                coords = coords.map(function (c) {
                    var parts = c.split(/, */).map(parseFloat);
                    return new Vector2D(parts[0], parts[1]);
                });

                return coords;
            } catch (e) {
                TBI.error("Plot failed to parse: " + e.message);
                return null;
            }
        }

        function submitFunction() {
            var varname = setVariable();

            var id = $(".function-id").val() || generateUUID();

            var start = isNull($(".function-start").val()) ? null :
                parseInt($(".function-start").val());
            var end = isNull($(".function-end").val()) ? null :
                parseInt($(".function-end").val());
            var resolution = Math.abs(parseInt($(".function-resolution").val())) || 50;

            var func = inputsToMathFunction();
            if (isNull(func))
                return TBI.error("Failed to save function.");
            var style = new Colour($(".function-colour").val()) || Colours.black;

            var obj = getCurrentObject();
            if (isNull(obj)) obj = new FunctionNode(func, style);
            else {
                obj.func = func;
                obj.style = style;
            }

            obj.id = id;
            obj.start = start;
            obj.end = end;
            obj.resolution = resolution;
            obj.derivative.visible = TBI.UI.isToggled($(".derivative-toggle")[0]);
            obj.integral.visible = TBI.UI.isToggled($(".integral-toggle")[0]);

            cplane.objects[id] = obj;
            cplane.triggerNextUpdate = true;
            updateObjectList();
            $(".object-list").val(id).trigger("update");
            if (!isNull(varname)) $(".variable-select").val(varname).trigger("update");

            cplane.triggerEvent("save");
        }

        function submitPlot() {
            var id = $(".plot-id").val() || generateUUID();

            var plot = inputsToPlot();
            if (isNull(plot))
                return TBI.error("Failed to save plot.");
            var style = new Colour($(".plot-colour").val()) || Colours.black;
            var name = $(".plot-name").val();
            var closed = TBI.UI.isToggled($(".plot-closed")[0]);
            var type = $(".plot-type").val();
            var mat = [
                [parseFloat($(".plot-matrix.0-0").val()), parseFloat($(".plot-matrix.0-1").val())],
                [parseFloat($(".plot-matrix.1-0").val()), parseFloat($(".plot-matrix.1-1").val())]
            ];

            var obj = getCurrentObject();
            if (isNull(obj)) obj = new PlotNode(plot, type, style);
            else {
                obj.plot = plot;
                obj.type = type;
                obj.style = style;
            }

            obj.id = id;
            obj.closed = closed;
            obj.name = name;
            obj.matrix = mat;

            cplane.objects[id] = obj;
            cplane.triggerNextUpdate = true;
            updateObjectList();
            $(".object-list").val(id).trigger("update");

            cplane.triggerEvent("save");
        }

        cplane.addEventHandler("post-update", updateObjectList);

        bindToPlane("#main-plane", "mousedown");
        bindToPlane("#main-plane", "mouseup");
        bindToPlane("#main-plane", "mousemove");

        cplane.addEventHandler("mouseup", function (plane, event) {
            var uuidRe = /([0-9A-Fa-f]{8}\-([0-9A-Fa-f]{4}\-){3}[0-9A-Fa-f]{12})/;
            if (!isNull(plane.state.deltaCenter)
                && plane.state.deltaCenter.equals(Vector2D.zero)
                && event.target.getAttribute("class").search(uuidRe) != -1) {
                $(".object-list").val(event.target.getAttribute("class").match(uuidRe)[1])
                    .trigger("change");
            }
        });

        $(".object-list").change(refreshUI);

        bindToSelectedObject(".hide-function", function (obj) {
            var prop = "objects." + obj.id + ".style.a";
            if (!cplane.plugins.animation) {
                obj.visible = TBI.UI.isToggled(this);
                cplane.triggerEvent("save");
                return;
            }

            if (cplane.propertyLocked(prop)) return;
            obj.visible = true;
            if (TBI.UI.isToggled(this)) {
                obj.style.a = 0;
                cplane.addAnimation(prop, 1, 600);
            } else {
                obj.style.a = 1;
                cplane.addAnimation(prop, 0, 600, null, function () {
                    obj.style.a = 1;
                    obj.visible = false;
                });
            }
        }, "change");

        bindToSelectedObject(".remove-function", function (obj) {
            if (!cplane.plugins.animation) {
                delete cplane.objects[obj.id];
                cplane.triggerEvent("save");
                return;
            }

            cplane.addAnimation("objects."+obj.id+".style.a", 0, 600, null, function (plane) {
                delete plane.objects[obj.id];
                $(".object-list").val("-").trigger("update");
                cplane.triggerEvent("save");
            });
        }, "click");

        bindToSelectedObject(".edit-function", function () {
            var obj = getCurrentObject();
            if (obj instanceof FunctionNode)
                switchView(".edit-function-view");
            else if (obj instanceof PlotNode)
                switchView(".edit-plot-view");

            updateInfoBox();
        }, "click");

        $(".return-to-origin").click(function () {
            if (!cplane.plugins.animation) {
                cplane.state.center = new Vector2D(0, 0);
                cplane.triggerEvent("save");
                return;
            }
            cplane.addAnimation("state.center", Vector2D.zero);
        });

        $(".zoom-in").click(function () {
            if (!cplane.plugins["navigation"]) return;

            var set = cplane.settings.controls;
            cplane.zoom(1/set.buttonZoomFactor);
        });

        $("#main-plane").on("mousewheel", function (event) {
            if (!cplane.plugins["navigation"]) return;

            var set = cplane.settings.controls;
            var delta = event.originalEvent.wheelDelta;
            if (delta > 0) cplane.zoom(1/set.scrollZoomFactor);
            else if (delta < 0) cplane.zoom(set.scrollZoomFactor);
        });

        $(".zoom-out").click(function () {
            if (!cplane.plugins["navigation"]) return;

            var set = cplane.settings.controls;
            cplane.zoom(set.buttonZoomFactor);
        });

        $(".lock-x").on("change", updateScaleLocking);
        $(".lock-y").on("change", updateScaleLocking);

        if (cplane.plugins["navigation"]) {
            var m = cplane.settings.controls.mode;
            if (m) {
                TBI.UI.toggleButton($(".lock-x")[0], m === "x-fixed" || m === "square");
                TBI.UI.toggleButton($(".lock-y")[0], m === "y-fixed" || m === "square");
            }
        }

        cplane.addEventHandler("post-update", updateInfoBox);

        $(".info-box-view-select li").click(function () {
            if (!$(this).hasClass("active"))
                switchView($(this).attr("rel"));
        });

        $(".info-box-hide").click(function () {
            $(".info-box").slideUp();
        });

        $(".info-box-show").click(function () {
            $(".info-box").slideDown();
        });

        $(".function-type").change(function () {
            var val = $(this).val();
            if (isNull(val) || val == "-") $(".type-selection-needed").removeClass("type-selection-fulfilled");
            else {
                $(".type-selection-needed").addClass("type-selection-fulfilled");
                $(".function-inputs").removeClass("show");
                $("."+val+"-inputs").addClass("show");
            }
        });

        $(".evaluate-expression").click(function () {
            var el = $($(this).attr("data-for") || $(this).attr("for"));
            evalExpression(el.val(), el);
        });

        $(".add-function").click(function () {
            switchView(".edit-function-view");
            $(".object-list").val("-").trigger("change");
            updateInfoBox();
        });

        $(".add-plot").click(function () {
            switchView(".edit-plot-view");
            $(".object-list").val("-").trigger("change");
            updateInfoBox();
        });

        $(".variable-select").change(function () {
            var val = $(this).val();
            if (isNull(val) || val == "-") {
                $(".variable-name").attr("disabled", true);
                $(".variable-name").val("");
                $(".variable-value").attr("disabled", true);
                $(".variable-value").val(0).trigger("update");
                updateSlider(0);
                $(".variable-demo").text("name");
            } else if (val.toLowerCase() == "new") {
                $(".variable-name").attr("disabled", false);
                $(".variable-name").val("");
                $(".variable-value").attr("disabled", false);
                $(".variable-value").val(0).trigger("update");
                $(".variable-demo").text("name");
                updateSlider(0);
            } else {
                $(".variable-name").attr("disabled", true);
                $(".variable-name").val(val);
                var variableValue = $(this).find("option[value='"+val+"']").attr("data-value");
                $(".variable-value").attr("disabled", false);
                $(".variable-value").val(variableValue).trigger("update");
                updateSlider(variableValue);
                $(".variable-demo").text(val);
            }
        });

        $(".variable-value").on("blur", submitFunction);

        $(".variable-set").click(submitFunction);

        $(".variable-add").click(addVariable);

        $(".variable-remove").click(function () {
            var $s = $(".variable-select");
            var currVar = $s.val();
            if (currVar !== "new" && currVar !== "-") {
                var option = $s.find("option[value='"+currVar+"']");
                if (option.length > 0)
                    $(option[0]).remove();
            }
            $s.val("-").trigger("change");
        });

        $(".edit-function-submit").click(submitFunction);

        $(".function-start").on("blur", submitFunction);
        $(".function-end").on("blur", submitFunction);
        $(".function-colour").on("change", submitFunction);
        $(".derivative-toggle").on("change", submitFunction);
        $(".integral-toggle").on("change", submitFunction);

        $(".edit-plot-submit").click(submitPlot);
        $(".plot-colour").on("change", submitPlot);
        $(".plot-closed").on("change", submitPlot);
        $(".plot-matrix").on("blur", submitPlot);
        $(".plot-name").on("blur", submitPlot);

        bindToSelectedObject(".plot-matrix-reset", function (obj) {
            if (obj instanceof PlotNode)
                obj.matrix = [[1,0],[0,1]];
            updateInfoBox();
        });

        var gotoBody = [
            "<form class='goto-form'>",
                "<div class='control-row'>",
                    "<input type='number' class='goto-x-input' />",
                    "<input type='number' class='goto-y-input' />",
                    "<input type='submit' value='Go' />",
                "</div>",
            "</form>"
        ].join("\n");

        $(".goto-coords").click(function () {
            var win = dialogWM.createWindow("Go To Coordinates", gotoBody, {
                x: "35%",
                y: "35%",
                width: "30%",
                height: "30%",
                flags: JSWM.WindowFlags.bound | JSWM.WindowFlags.resize,
                onClose: function () { /*$(".shadow").removeClass("show");*/ }
            });

            var $win = $(win.element);

            $win.find(".goto-x-input").val(cplane.state.center.x);
            $win.find(".goto-y-input").val(cplane.state.center.y);
            $win.find(".goto-form").on("submit", function (event) {
                if (event.preventDefault) event.preventDefault();

                var c = new Vector2D(
                    parseFloat($win.find(".goto-x-input").val()),
                    parseFloat($win.find(".goto-y-input").val())
                );

                if (cplane.plugins["animation"])
                    cplane.addAnimation("state.center", c);
                else cplane.state.center = c;

                //win.close();

                return false;
            });

            // $(".shadow").addClass("show");
        });

        var measurementToolWindow,
            updateMeasurementTool = function (coords) {
                var $c = $(".measurement-crosshair"),
                    sel = cplane.objects[$(".object-list").val()],
                    off = new Vector2D(
                        $("#main-plane").offset().left,
                        $("#main-plane").offset().top
                    );

                var loc = cplane.getLocationOfCoordinate(coords),
                    screen = loc.add(off);

                if (isNull(sel)) {
                    $c.css("left", screen.x)
                        .css("top", screen.y);
                } else switch (sel.func.type.toLowerCase()) {
                    case "cartesian":
                        var y = sel.func.eval(coords.x);

                        $c.css("left", screen.x);
                        $c.css("top", cplane.getLocationOfCoordinate(
                            new Vector2D(y)).add(off).y);
                        break;

                    case "polar":
                    case "parametric":
                    default:
                        $c.css("left", screen.x);
                        $c.css("top", screen.y);
                }

                coords = cplane.getCoordinateFromLocation(new Vector2D(
                    parseFloat($c.css("left")),
                    parseFloat($c.css("top"))
                ).subtract(off));

                $(".measurement-tool-x").val(coords.x);
                $(".measurement-tool-y").val(coords.y);

            },
            measurementMousemove = function (event) {
                var off = new Vector2D(
                    $("#main-plane").offset().left,
                    $("#main-plane").offset().top
                );

                updateMeasurementTool(cplane.getCoordinateFromLocation(
                    new Vector2D(
                        event.clientX,
                        event.clientY
                    ).subtract(off)
                ));
            };
        $("[name='tool-select']").on("change", function () {
            var val = TBI.UI.getRadioInput("tool-select"),
                possibilities = $("[name='tool-select']")
                    .toArray()
                    .map(function (e) { return e.value; });

            $(".tool-container").removeClass(possibilities.join(" "));
            $(".tool-container").addClass(val);

            switch (val) {
                case "measurement":
                    if (!measurementToolWindow ||
                        !measurementToolWindow.element ||
                        !measurementToolWindow.element.parentElement) {

                        if (measurementToolWindow && measurementToolWindow.element)
                            delete measurementToolWindow.element;

                        measurementToolWindow =
                            toolWM.createWindow("Measurement", $(".measurement-tool-template").html(), {
                                x: "50%",
                                y: "50%",
                                width: 300,
                                height: 190,
                                flags: JSWM.WindowFlags.bound | JSWM.WindowFlags.resize,
                                onClose: function () {
                                    $("#tool-select-navigation")[0].checked = true;
                                    $("#tool-select-navigation").trigger("change");
                                }
                            });

                        var $e = $(measurementToolWindow.element);
                        $e.find(".measurement-tool-x").on("change", function () {
                            updateMeasurementTool(new Vector2D(
                                parseFloat($(this).val()),
                                parseFloat($e.find(".measurement-tool-y").val())
                            ));
                        });
                        $e.find(".measurement-tool-y").on("change", function () {
                            updateMeasurementTool(new Vector2D(
                                parseFloat($e.find(".measurement-tool-x").val()),
                                parseFloat($(this).val())
                            ));
                        });
                    }
                    $("#main-plane").on("mousemove", measurementMousemove);
                    break;
                default:
                    $("#main-plane").off("mousemove", measurementMousemove);
                    break;
            }
        });

        var updateSlider = (function () {
            var lastUpdated = new Date().getTime();
            return function (val) {
                if (new Date().getTime() - 50 <= lastUpdated) return;
                else lastUpdated = new Date().getTime();

                var $s = $(".variable-slider"),
                    min = parseFloat($s.attr("min")),
                    max = parseFloat($s.attr("max"));

                if (val < min)
                    $(".variable-slider-start").val(parseFloat(val)).trigger("change");
                if (val > max)
                    $(".variable-slider-end").val(parseFloat(val)).trigger("change");

                $s.val(parseFloat(val));
            };
        })();

        $(".variable-slider-start").on("change", function () {
            $(".variable-slider").attr("min", $(this).val());
        });
        $(".variable-slider-end").on("change", function () {
            $(".variable-slider").attr("max", $(this).val());
        });
        $(".variable-value").on("change", function () {
            updateSlider($(this).val());
        });
        $(".variable-slider").on("change", function () {
            var val = $(".variable-select").val();
            if (isNull(val) || val == "-") return false;
            $(".variable-value").val($(this).val());

            submitFunction();
        });

        var sliderTimers = [];
        function setSliderTimer(sign, obj, variable) {
            var $s = $(".variable-slider"),
                min = parseFloat($s.attr("min")),
                max = parseFloat($s.attr("max")),
                bounce = true,
                interval = 1000/20,
                duration = 2000;

            //if (sliderTimer instanceof TBI.Timer)
            //    sliderTimer.clear();

            if (sign !== 0 && !isNull(obj) && !isNull(variable)
                    && variable !== "new"
                    && variable !== "-") {
                sliderTimers.push(new TBI.Timer(function (timer) {
                    var val = obj.func.scope[variable],
                        step = (interval / duration) * (max - min);

                    var newval = val + sign * step;
                    if (newval > max) {
                        if (bounce) {
                            newval = max - (newval - max);
                            setSliderTimer(sign * -1, obj, variable);
                        } else newval = min + (newval - max);
                    }

                    if (newval < min) {
                        if (bounce) {
                            newval = min + (min - newval);
                            setSliderTimer(sign * -1, obj, variable);
                        } else newval = max - (min - newval);
                    }

                    if (isNaN(obj.func.scope[variable]) || !cplane.objects[obj.id])
                        return timer.clear();

                    // $s.val(newval).trigger("change");
                    obj.func.scope[variable] = newval;
                    cplane.triggerNextUpdate = true;
                }, interval, true, "cplane-" + obj.id + "-" + variable));
            } else {
                var timer = TBI.TimerDB["cplane-" + obj.id + "-" + variable];
                if (timer) timer.clear();
            }
        }

        bindToSelectedObject(".variable-slider-forwards", function (obj) {
            console.log(obj);
            setSliderTimer( 1, obj, $(".variable-select").val());
        }, "click");

        bindToSelectedObject(".variable-slider-backwards", function (obj) {
            setSliderTimer(-1, obj, $(".variable-select").val());
        }, "click");

        bindToSelectedObject(".variable-slider-stop", function (obj) {
            setSliderTimer( 0, obj, $(".variable-select").val());
        }, "click");

        $(".variable-slider-stop-all").click(function () {
            sliderTimers.forEach(function (t) {
                if (t instanceof TBI.Timer) t.clear();
            });
            sliderTimers = [];
        });
        $(".save").click(function () {
            cplane.triggerEvent("save", true);
        });
    });
});
});


text:
import sys
import py_compile

if len(sys.argv) < 4:
    print "Usage: %s src.py file.py file.pyc" % sys.argv[0]
    sys.exit(1)

try:
    py_compile.compile(sys.argv[2], sys.argv[3], sys.argv[1], doraise=True)
except py_compile.PyCompileError as compileError:
    exc_value = compileError.exc_value
    if compileError.exc_type_name == SyntaxError.__name__:
        # py_compile.compile stashes the type name and args of the exception
        # in the raised PyCompileError rather than the exception itself.  This
        # is especially annoying because the args member of some SyntaxError
        # instances are lacking the source information tuple, but do have a
        # usable lineno.
        error = exc_value[0]
        try:
            linenumber = exc_value[1][1]
            line = exc_value[1][3]
            print '%s:%s: %s: "%s"' % (sys.argv[1], linenumber, error, line)
        except IndexError:
            print '%s: Syntax error: "%s"' % (sys.argv[1], error)
    else:
        print "%s: Unhandled compile error: (%s) %s" % (
            sys.argv[1], compileError.exc_type_name, exc_value)
    sys.exit(1)
except:
    exc_type, exc_value, exc_traceback = sys.exc_info()
    print "%s: Unhandled exception: %s" % (sys.argv[1], exc_value)
    sys.exit(1)

redpajama_set_name: RedPajamaGithub


text:
This intention replaces an extension of an
adapter class with a direct implementation of the listeners.


text:
FROM php:5.6-fpm

RUN apt-get update -y && \
    apt-get upgrade -y

RUN apt-get -qq install -y libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
        libssl-dev \
        libpq-dev \
        libpcre3-dev \
        wget \
    && docker-php-ext-install -j$(nproc) iconv mcrypt mbstring \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install -j$(nproc) pgsql pdo_pgsql \
    && docker-php-ext-install -j$(nproc) zip

COPY php.ini /usr/local/etc/php/

WORKDIR /code


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"
><TITLE
>Qtc.Core.QIODevice</TITLE
><LINK HREF="haddock.css" REL="stylesheet" TYPE="text/css"
>

Qtc.Core.QIODevice

class QatEnd x0 x1

class QbytesAvailable x0 x1

class QbytesToWrite x0 x1

class QcanReadLine x0 x1

class Qclose x0 x1 xr

class QerrorString x1

isOpen

class QisReadable x1

class QisSequential x0 x1

isTextModeEnabled

class QisWritable x1

class Qopen x0 x1

openMode

peek

class Qpos x0 x1 xr

class Qqpos x1 xr

class Qqread x1

class QreadAll x1

class QreadLine x1

class Qreset x0 x1 xr

class Qseek x0 x1

class QsetErrorString x0 x1

class QsetOpenMode x0 x1

setTextModeEnabled

class Qqsize x0 x1 xr

class Qqqsize x1 xr

class QwaitForBytesWritten x0 x1

class QwaitForReadyRead x0 x1

class Qwrite x1

class QwriteData x0 x1

qIODevice_delete

qIODevice_deleteLater

class QchildEvent x0 x1

class QconnectNotify x0 x1

class QcustomEvent x0 x1

class QdisconnectNotify x0 x1

class Qevent x0 x1

class QeventFilter x0 x1

class Qreceivers x0 x1

class Qsender x0 x1

class QtimerEvent x0 x1


text:
package com.tspoon.androidtoolbelt;

import android.app.Application;

import com.crashlytics.android.Crashlytics;
import com.tspoon.androidtoolbelt.component.service.ServiceHolder;
import com.tspoon.androidtoolbelt.component.service.ServiceHolderImplTest;

import timber.log.Timber;

public class App extends Application {

    private static final boolean TEST_MODE = false;

    private static ServiceHolder sServiceHolder;

    @Override
    public void onCreate() {
        super.onCreate();

        Timber.plant(new Timber.DebugTree());

        try {
            if (TEST_MODE) {
                sServiceHolder = new ServiceHolderImplTest();
            } else {
                Class adapterClass = Class.forName(ServiceHolder.QUALIFIED_NAME);
                sServiceHolder = (ServiceHolder) adapterClass.newInstance();
            }
        } catch (Exception e) {
            Timber.e(e, "Error initializing ServiceHolder.");
            Crashlytics.logException(e);
        }
    }

    public static ServiceHolder getServiceHolder() {
        return sServiceHolder;
    }
}


text:
var fs = require('fs');
// MySQL Packages
var mysql = require('mysql');
var mysql_connection = new Object();

// MongoDB Package
var mongodb = require('mongodb');
var mongodb_connection = new Object();

// Module
module.exports = {
    JSON2CSV:
    function JSON2CSV(data, callback) {
        var key = Object.keys(data[0]);
        var results = "";
        for (var n=0; n<key.length; n++) {
            if ( n == key.length - 1 ) {
                results += key[n];
            } else {
                results += key[n] + ",";
            }
        }
        results += "\r\n";
        for (var n=0; n<data.length; n++) {
            for (var i=0; i<key.length; i++) {
                if ( i == key.length - 1 ) {
                    results += data[n][key[i]];
                } else {
                    results += data[n][key[i]] + ",";
                }
            }
            results += "\r\n";
        }
        callback(results);
    },
    ReadConfig:
    function ReadConfig(config, callback) {
        fs.readFile(config, function(err, data) {
            callback(JSON.parse(data.toString('utf8')));
        });
    },
    UpdateConfig:
    function UpdateConfig(config, data, callback) {
        fs.writeFile(config, JSON.stringify(data), function(err, data) {
            console.log(err);
        });
    },
    Connect:
    function Connect(service, config, callback) {
        if (service.toLowerCase().indexOf("mysql") != -1) {
            mysql_connection = mysql.createConnection(config);
            callback({message:"success"});
        } else if (service.toLowerCase().indexOf("mongodb") != -1) {
            var MongoClient = require('mongodb').MongoClient;
            MongoClient.connect("mongodb://" + config.host + ":" + config.port + "/" + config.database, function(err, db) {
                mongodb_connection = db;
                callback({message:"success"});
            });
        }
    },
    Create:
    function Create(service, table, id, data, callback) {
        if (service.toLowerCase().indexOf("mysql") != -1) {
            mysql_connection.query("INSERT INTO " + mysql.escape(table).replace(/'/g,"") + " SET ? ;", data, function(err, results, fields) {
                if (err) {
                    callback({message:"error",description:err});
                } else {
                    callback(results);
                }
            });
        } else if (service.toLowerCase().indexOf("mongodb") != -1) {
            mongodb_connection.collection(table).insert(data, function (err, results) {
                if (err) {
                    callback({message:"error",description:err});
                } else {
                    callback(results);
                }
            });
        }
    },
    Read:
    function Read(service, table, id, data, callback) {
        if (service.toLowerCase().indexOf("mysql") != -1) {
            var query = "";
            if (Object.getOwnPropertyNames(id).length === 0) {
                query = "SELECT * FROM " + mysql.escape(table).replace(/'/g,"") + ";";
            } else {
                var condition = "";
                for (var n=0; n<Object.keys(id).length; n++) {
                    condition += Object.keys(id)[n] + " = \"" + mysql.escape(id[Object.keys(id)[n]]).replace(/'/g,"") +"\"";
                    if (n != Object.keys(id).length - 1) {
                        condition += " AND ";
                    }
                }
                query = "SELECT * FROM " + mysql.escape(table).replace(/'/g,"") + " WHERE " + condition + ";";
            }
            mysql_connection.query(query, data, function(err, results, fields) {
                if (err) {
                    callback({message:"error",description:err});
                } else {
                    callback(results);
                }
            });
        } else if (service.toLowerCase().indexOf("mongodb") != -1) {
            mongodb_connection.collection(table).find(id).toArray(function(err, results) {
                if (err) {
                    callback({message:"error",description:err});
                } else {
                    callback(results);
                }
            });
        }
    },
    Update:
    function Update(service, table, id, data, callback) {
        if (service.toLowerCase().indexOf("mysql") != -1) {
            mysql_connection.query("UPDATE " + mysql.escape(table) + " SET ? WHERE " + mysql.escape(id).replace(/'/g,"") + ";", data, function(err, results, fields) {
                callback({message:"error",description:err});
            });
        } else if (service.toLowerCase().indexOf("mongodb") != -1) {
            delete data._id;
            mongodb_connection.collection(table).update(id,{$set:data}, function (err, results) {
                callback({message:"error",description:err});
            });
        }
    },
    Delete:
    function Delete(service, table, id, data, callback) {
        if (service.toLowerCase().indexOf("mysql") != -1) {
            mysql_connection.query("DELETE FROM " + mysql.escape(table) + " WHERE " + mysql.escape(id).replace(/'/g,"") + ";", data, function(err, results, fields) {
                callback({message:"error",description:err});
            });
        } else if (service.toLowerCase().indexOf("mongodb") != -1) {
            mongodb_connection.collection(table).remove(id, function (err, results) {
                callback({message:"error",description:err});
            });
        }
    },
    Destroy:
    function Destroy(service, callback) {
        if (service.toLowerCase().indexOf("mysql") != -1) {
            mysql_connection.destroy();
            callback({message:"success"});
        } else if (service.toLowerCase().indexOf("mongodb") != -1) {
            mongodb_connection.close();
            callback({message:"success"});
        }
    }
}


text:
package br.com.objectos.jabuticava;

import br.com.objectos.metainf.Services;
import br.com.objectos.pojo.plugin.AbstractPlugin;
import br.com.objectos.pojo.plugin.BuilderProperty;
import br.com.objectos.pojo.plugin.BuilderPropertyAction;
import br.com.objectos.pojo.plugin.Plugin;
import br.com.objectos.pojo.plugin.Property;

import com.squareup.javapoet.TypeName;

/**
 * @author marcio.endo@objectos.com.br (Marcio Endo)
 */
@Services(Plugin.class)
public class CadastroRfbPlugin extends AbstractPlugin {

  @Override
  protected void configure() {
    when(property(instanceOf(Cpf.class))).execute(CpfAction.INSTANCE);
    when(property(instanceOf(Cnpj.class))).execute(CnpjAction.INSTANCE);
    when(property(instanceOf(CadastroRfb.class))).execute(CadastroRfbAction.INSTANCE);
  }

  private enum CpfAction implements BuilderPropertyAction {

    INSTANCE;

    @Override
    public final BuilderProperty execute(Property property) {
      return BuilderProperty.of(
          property.standardBuilderProperty(),
          execute0(property));
    }

    private BuilderProperty execute0(Property property) {
      return BuilderProperty.methodBuilder(property)
          .name()
          .addParameter(TypeName.LONG, "cpf")
          .assignment("$T.valueOf(cpf)", Cpf.class)
          .build();
    }

  }

  private enum CnpjAction implements BuilderPropertyAction {

    INSTANCE;

    @Override
    public final BuilderProperty execute(Property property) {
      return BuilderProperty.of(
          property.standardBuilderProperty(),
          execute0(property));
    }

    private BuilderProperty execute0(Property property) {
      return BuilderProperty.methodBuilder(property)
          .name()
          .addParameter(TypeName.LONG, "cnpj")
          .assignment("$T.valueOf(cnpj)", Cnpj.class)
          .build();
    }

  }

  private enum CadastroRfbAction implements BuilderPropertyAction {

    INSTANCE;

    @Override
    public final BuilderProperty execute(Property property) {
      return BuilderProperty.of(
          property.standardBuilderProperty(),
          executeCpf(property),
          executeCnpj(property));
    }

    private BuilderProperty executeCpf(Property property) {
      return BuilderProperty.methodBuilder(property)
          .nameSuffix("Cpf")
          .addParameter(TypeName.LONG, "cpf")
          .assignment("$T.valueOf(cpf)", Cpf.class)
          .build();
    }

    private BuilderProperty executeCnpj(Property property) {
      return BuilderProperty.methodBuilder(property)
          .nameSuffix("Cnpj")
          .addParameter(TypeName.LONG, "cnpj")
          .assignment("$T.valueOf(cnpj)", Cnpj.class)
          .build();
    }

  }

}


text:
export const SHOW_SNACKBAR = 'SHOW_SNACKBAR';
export const HIDE_SNACKBAR = 'HIDE_SNACKBAR';


text:
#ifndef _Stopwatch_hpp_
#define _Stopwatch_hpp_

#include <chrono>

class Stopwatch
{
    public:
        Stopwatch() = default;
        Stopwatch(const Stopwatch& s);
        Stopwatch& operator=(const Stopwatch& s);

        unsigned int getTime();
        float getFloatTime();

        void start();
        void stop();

        void restart();

        bool isStarted();

    private:
        std::chrono::high_resolution_clock::time_point startTime;
        bool started;
};

#endif /* _Stopwatch_hpp_ */


text:
import i18next from 'i18next';
import intervalPlural from 'i18next-intervalplural-postprocessor/lib';
import settings from './settings';

export const LANGUAGES = [
    {id: 'en', title: 'English'},
    {id: 'ru', title: 'Русский'},
    {id: 'ptbr', title: 'Português'}
];

LANGUAGES
    .map(lang => lang.id)
    .forEach(lang => addTranslation(lang, require('../translations/' + lang)));

export function initTranslations() {
    return new Promise((resolve, reject) => {
        Object.assign(intervalPlural.options, {
            intervalRegex: /^\((\S*)\)\((.*)\)$/
        });
        i18next.use(intervalPlural).init({
            lng: settings.get('language'),
            interpolation: {
                escapeValue: false
            },
            fallbackLng: 'en'
        }, err => err ? reject(err) : resolve());
    });
}

export function addTranslation(lang, json) {
    i18next.on('initialized', () => {
        i18next.services.resourceStore.addResourceBundle(lang, i18next.options.ns[0], json);
    });
}

export default i18next;


text:
package com.vaadin.tests.util;

import java.io.File;

import com.vaadin.server.SystemError;
import com.vaadin.server.VaadinService;
import com.vaadin.server.VaadinSession;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;

/**
 * Provides sample directory based on application directory. If this fails then
 * sampleDirectory property is read. If no sample directory is resolved, then a
 * panel displaying error message is added to main window.
 *
 * @author Vaadin Ltd.
 *
 */
public class SampleDirectory {

    /**
     * Get sample directory.
     *
     * @param application
     * @return file pointing to sample directory
     */
    public static File getDirectory(VaadinSession application,
            LegacyWindow uI) {
        String errorMessage = "Access to application "
                + "context base directory failed, "
                + "possible security constraint with Application "
                + "Server or Servlet Container.
";
        File file = VaadinService.getCurrent().getBaseDirectory();
        if ((file == null) || (!file.canRead())
                || (file.getAbsolutePath() == null)) {
            // cannot access example directory, possible security issue with
            // Application Server or Servlet Container
            // Try to read sample directory from web.xml parameter
            String sampleDirProperty = application.getConfiguration()
                    .getInitParameters().getProperty("sampleDirectory");
            if (sampleDirProperty != null) {
                file = new File(sampleDirProperty);
                if ((file != null) && (file.canRead())
                        && (file.getAbsolutePath() != null)) {
                    // Success using property
                    return file;
                }
                // Failure using property
                errorMessage += "Failed also to access sample directory ["
                        + sampleDirProperty
                        + "] defined in sampleDirectory property.";
            } else {
                // Failure using application context base dir, no property set
                errorMessage += "Note: You can set this manually in "
                        + "web.xml by defining " + "sampleDirectory property.";
            }
        } else {
            // Success using application context base dir
            return file;
        }
        // Add failure notification as an Panel to main window
        VerticalLayout errorLayout = new VerticalLayout();
        errorLayout.setMargin(true);
        final Panel errorPanel = new Panel("Demo application error",
                errorLayout);
        errorPanel.setStyleName("strong");
        errorPanel.setComponentError(
                new SystemError("Cannot provide sample directory"));
        errorLayout.addComponent(new Label(errorMessage, ContentMode.HTML));
        // Remove all components from applications main window
        uI.removeAllComponents();
        // Add error panel
        uI.addComponent(errorPanel);
        return null;
    }
}


text:
require "spec_helper"

describe Money, "parsing" do

  bar = '{ "priority": 1, "iso_code": "BAR", "iso_numeric": "840", "name": "Dollar with 4 decimal places", "symbol": "$", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "$", "decimal_mark": ".", "thousands_separator": "," }'
  eu4 = '{ "priority": 1, "iso_code": "EU4", "iso_numeric": "841", "name": "Euro with 4 decimal places", "symbol": "€", "subunit": "Cent", "subunit_to_unit": 10000, "symbol_first": true, "html_entity": "€", "decimal_mark": ",", "thousands_separator": "." }'

  describe ".parse" do
    it "parses european-formatted inputs under 10EUR" do
      five_ninety_five = Money.new(595, 'EUR')

      Money.parse('EUR 5,95').should    == five_ninety_five
      #TODO: try and handle these
      #Money.parse('€5,95').should       == five_ninety_five
      #Money.parse('$5.95').should  == five_ninety_five
    end

    it "parses european-formatted inputs with multiple thousands-seperators" do
      Money.parse('EUR 1.234.567,89').should     == Money.new(123456789, 'EUR')
      Money.parse('EUR 1.111.234.567,89').should == Money.new(111123456789, 'EUR')
    end

    describe 'currency assumption' do
      context 'opted in' do
        before do
          Money.assume_from_symbol = true
        end
        it "parses formatted inputs with the currency passed as a symbol" do
          with_default_currency("EUR") do
            Money.parse("$5.95").should == Money.new(595, 'USD')
          end
          Money.parse("€5.95").should == Money.new(595, 'EUR')
          Money.parse(" €5.95 ").should == Money.new(595, 'EUR')
          Money.parse("£9.99").should == Money.new(999, 'GBP')
        end
        it 'should assume default currency if not a recognised symbol' do
          Money.parse("L9.99").should == Money.new(999, 'USD')
        end
       end
      context 'opted out' do
        before do
          Money.assume_from_symbol = false
        end
        it "parses formatted inputs with the currency passed as a symbol but ignores the symbol" do
          Money.parse("$5.95").should == Money.new(595, 'USD')
          Money.parse("€5.95").should == Money.new(595, 'USD')
          Money.parse(" €5.95 ").should == Money.new(595, 'USD')
          Money.parse("£9.99").should == Money.new(999, 'USD')

        end
      end
      it 'should opt out by default' do
        Money.assume_from_symbol.should be_false
      end
    end

    it "parses USD-formatted inputs under $10" do
      five_ninety_five = Money.new(595, 'USD')

      Money.parse(5.95).should          == five_ninety_five
      Money.parse('5.95').should        == five_ninety_five
      Money.parse('$5.95').should       == five_ninety_five
      Money.parse("\n $5.95 \n").should == five_ninety_five
      Money.parse('$ 5.95').should      == five_ninety_five
      Money.parse('$5.95 ea.').should   == five_ninety_five
      Money.parse('$5.95, each').should == five_ninety_five
    end

    it "parses USD-formatted inputs with multiple thousands-seperators" do
      Money.parse('1,234,567.89').should     == Money.new(123456789, 'USD')
      Money.parse('1,111,234,567.89').should == Money.new(111123456789, 'USD')
    end

    it "does not return a price if there is a price range" do
      expect { Money.parse('$5.95-10.95') }.to    raise_error ArgumentError
      expect { Money.parse('$5.95 - 10.95') }.to  raise_error ArgumentError
      expect { Money.parse('$5.95 - $10.95') }.to raise_error ArgumentError
    end

    it "does not return a price for completely invalid input" do
      # TODO: shouldn't these throw an error instead of being considered
      # equal to $0.0?
      empty_price = Money.new(0, 'USD')

      Money.parse(nil).should             == empty_price
      Money.parse('hellothere').should    == empty_price
      Money.parse('').should              == empty_price
    end

    it "handles negative inputs" do
      five_ninety_five = Money.new(595, 'USD')

      Money.parse("$-5.95").should == -five_ninety_five
      Money.parse("-$5.95").should == -five_ninety_five
      Money.parse("$5.95-").should == -five_ninety_five
    end

    it "raises ArgumentError when unable to detect polarity" do
      expect { Money.parse('-$5.95-') }.to raise_error ArgumentError
    end

    it "parses correctly strings with exactly 3 decimal digits" do
      Money.parse("6,534", "EUR").should == Money.new(653, "EUR")
    end

    context "custom currencies with 4 decimal places" do
      before :each do
        Money::Currency.register(JSON.parse(bar, :symbolize_names => true))
        Money::Currency.register(JSON.parse(eu4, :symbolize_names => true))
      end

      # String#to_money(Currency) is equivalent to Money.parse(String, Currency)
      it "parses strings respecting subunit to unit, decimal and thousands separator" do
        "$0.4".to_money("BAR").should == Money.new(4000, "BAR")
        "€0,4".to_money("EU4").should == Money.new(4000, "EU4")

        "$0.04".to_money("BAR").should == Money.new(400, "BAR")
        "€0,04".to_money("EU4").should == Money.new(400, "EU4")

        "$0.004".to_money("BAR").should == Money.new(40, "BAR")
        "€0,004".to_money("EU4").should == Money.new(40, "EU4")

        "$0.0004".to_money("BAR").should == Money.new(4, "BAR")
        "€0,0004".to_money("EU4").should == Money.new(4, "EU4")

        "$0.0024".to_money("BAR").should == Money.new(24, "BAR")
        "€0,0024".to_money("EU4").should == Money.new(24, "EU4")

        "$0.0324".to_money("BAR").should == Money.new(324, "BAR")
        "€0,0324".to_money("EU4").should == Money.new(324, "EU4")

        "$0.5324".to_money("BAR").should == Money.new(5324, "BAR")
        "€0,5324".to_money("EU4").should == Money.new(5324, "EU4")

        "$6.5324".to_money("BAR").should == Money.new(65324, "BAR")
        "€6,5324".to_money("EU4").should == Money.new(65324, "EU4")

        "$86.5324".to_money("BAR").should == Money.new(865324, "BAR")
        "€86,5324".to_money("EU4").should == Money.new(865324, "EU4")

        "$186.5324".to_money("BAR").should == Money.new(1865324, "BAR")
        "€186,5324".to_money("EU4").should == Money.new(1865324, "EU4")

        "$3,331.0034".to_money("BAR").should == Money.new(33310034, "BAR")
        "€3.331,0034".to_money("EU4").should == Money.new(33310034, "EU4")

        "$8,883,331.0034".to_money("BAR").should == Money.new(88833310034, "BAR")
        "€8.883.331,0034".to_money("EU4").should == Money.new(88833310034, "EU4")
      end
    end
  end

  describe ".from_string" do
    it "converts given amount to cents" do
      Money.from_string("1").should == Money.new(1_00)
      Money.from_string("1").should == Money.new(1_00, "USD")
      Money.from_string("1", "EUR").should == Money.new(1_00, "EUR")
    end

    it "respects :subunit_to_unit currency property" do
      Money.from_string("1", "USD").should == Money.new(1_00,  "USD")
      Money.from_string("1", "TND").should == Money.new(1_000, "TND")
      Money.from_string("1", "CLP").should == Money.new(1,     "CLP")
    end

    it "accepts a currency options" do
      m = Money.from_string("1")
      m.currency.should == Money.default_currency

      m = Money.from_string("1", Money::Currency.wrap("EUR"))
      m.currency.should == Money::Currency.wrap("EUR")

      m = Money.from_string("1", "EUR")
      m.currency.should == Money::Currency.wrap("EUR")
    end
  end

  describe ".from_fixnum" do
    it "converts given amount to cents" do
      Money.from_fixnum(1).should == Money.new(1_00)
      Money.from_fixnum(1).should == Money.new(1_00, "USD")
      Money.from_fixnum(1, "EUR").should == Money.new(1_00, "EUR")
    end

    it "should respect :subunit_to_unit currency property" do
      Money.from_fixnum(1, "USD").should == Money.new(1_00,  "USD")
      Money.from_fixnum(1, "TND").should == Money.new(1_000, "TND")
      Money.from_fixnum(1, "CLP").should == Money.new(1,     "CLP")
    end

    it "accepts a currency options" do
      m = Money.from_fixnum(1)
      m.currency.should == Money.default_currency

      m = Money.from_fixnum(1, Money::Currency.wrap("EUR"))
      m.currency.should == Money::Currency.wrap("EUR")

      m = Money.from_fixnum(1, "EUR")
      m.currency.should == Money::Currency.wrap("EUR")
    end
  end

  describe ".from_float" do
    it "converts given amount to cents" do
      Money.from_float(1.2).should == Money.new(1_20)
      Money.from_float(1.2).should == Money.new(1_20, "USD")
      Money.from_float(1.2, "EUR").should == Money.new(1_20, "EUR")
    end

    it "respects :subunit_to_unit currency property" do
      Money.from_float(1.2, "USD").should == Money.new(1_20,  "USD")
      Money.from_float(1.2, "TND").should == Money.new(1_200, "TND")
      Money.from_float(1.2, "CLP").should == Money.new(1,     "CLP")
    end

    it "accepts a currency options" do
      m = Money.from_float(1.2)
      m.currency.should == Money.default_currency

      m = Money.from_float(1.2, Money::Currency.wrap("EUR"))
      m.currency.should == Money::Currency.wrap("EUR")

      m = Money.from_float(1.2, "EUR")
      m.currency.should == Money::Currency.wrap("EUR")
    end
  end

  describe ".from_bigdecimal" do
    it "converts given amount to cents" do
      Money.from_bigdecimal(BigDecimal.new("1")).should == Money.new(1_00)
      Money.from_bigdecimal(BigDecimal.new("1")).should == Money.new(1_00, "USD")
      Money.from_bigdecimal(BigDecimal.new("1"), "EUR").should == Money.new(1_00, "EUR")
    end

    it "respects :subunit_to_unit currency property" do
      Money.from_bigdecimal(BigDecimal.new("1"), "USD").should == Money.new(1_00,  "USD")
      Money.from_bigdecimal(BigDecimal.new("1"), "TND").should == Money.new(1_000, "TND")
      Money.from_bigdecimal(BigDecimal.new("1"), "CLP").should == Money.new(1,     "CLP")
    end

    it "accepts a currency options" do
      m = Money.from_bigdecimal(BigDecimal.new("1"))
      m.currency.should == Money.default_currency

      m = Money.from_bigdecimal(BigDecimal.new("1"), Money::Currency.wrap("EUR"))
      m.currency.should == Money::Currency.wrap("EUR")

      m = Money.from_bigdecimal(BigDecimal.new("1"), "EUR")
      m.currency.should == Money::Currency.wrap("EUR")
    end
  end

  describe ".from_numeric" do
    it "converts given amount to cents" do
      Money.from_numeric(1).should == Money.new(1_00)
      Money.from_numeric(1.0).should == Money.new(1_00)
      Money.from_numeric(BigDecimal.new("1")).should == Money.new(1_00)
    end

    it "raises ArgumentError with unsupported argument" do
      expect { Money.from_numeric("100") }.to raise_error(ArgumentError)
    end

    it "optimizes workload" do
      Money.should_receive(:from_fixnum).with(1, "USD").and_return(Money.new(1_00,  "USD"))
      Money.from_numeric(1, "USD").should == Money.new(1_00,  "USD")
      Money.should_receive(:from_bigdecimal).with(BigDecimal.new("1.0"), "USD").and_return(Money.new(1_00,  "USD"))
      Money.from_numeric(1.0, "USD").should == Money.new(1_00,  "USD")
    end

    it "respects :subunit_to_unit currency property" do
      Money.from_numeric(1, "USD").should == Money.new(1_00,  "USD")
      Money.from_numeric(1, "TND").should == Money.new(1_000, "TND")
      Money.from_numeric(1, "CLP").should == Money.new(1,     "CLP")
    end

    it "accepts a bank option" do
      Money.from_numeric(1).should == Money.new(1_00)
      Money.from_numeric(1).should == Money.new(1_00, "USD")
      Money.from_numeric(1, "EUR").should == Money.new(1_00, "EUR")
    end

    it "accepts a currency options" do
      m = Money.from_numeric(1)
      m.currency.should == Money.default_currency

      m = Money.from_numeric(1, Money::Currency.wrap("EUR"))
      m.currency.should == Money::Currency.wrap("EUR")

      m = Money.from_numeric(1, "EUR")
      m.currency.should == Money::Currency.wrap("EUR")
    end
  end

  describe ".extract_cents" do
    it "correctly treats pipe marks '|' in input (regression test)" do
      Money.extract_cents('100|0').should == Money.extract_cents('100!0')
    end
  end

  context "given the same inputs to .parse and .from_*" do
    it "gives the same results" do
      4.635.to_money.should == "4.635".to_money
    end
  end

end


text:
import routes from './routes';
import UserRegistrationController from './controller/UserRegistrationController';

export default angular
    .module('app.user', ['ui.router'])
    .config(routes)
    .controller('UserRegistrationController', UserRegistrationController)
    .name;


text:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.newWizards">
         <wizard name="Registry Resource" category="org.wso2.developerstudio.eclipse.capp.project/org.wso2.developerstudio.eclipse.repository"
			class="org.wso2.developerstudio.eclipse.artifact.registry.ui.wizard.RegistryResourceCreationWizard"
			wizardManifest="project_wizard.xml"
			id="org.wso2.developerstudio.eclipse.artifact.newregistryresource"
			icon="icons/registry-artifact-16x16.png">
			<description>Registry Resource</description>
		</wizard>
   </extension>
    <extension point="org.eclipse.ui.navigator.navigatorContent">
	   <navigatorContent activeByDefault="true"
			priority="high"
			id="org.eclipse.ui.navigator.resourceContent"
			name="test">
				<commonWizard
					menuGroupId="5org.wso2.developerstudio.eclipse.artifact.newregistryresource"
			  	 	type="new"
					wizardId="org.wso2.developerstudio.eclipse.artifact.newregistryresource">
					<enablement>
						<or>
							<adapt type="org.eclipse.core.resources.IProject"/>
							<adapt type="org.eclipse.core.resources.IFolder"/>
						</or>
					</enablement>
				</commonWizard>
				<triggerPoints>
				           <or>
				              <instanceof
				                    value="org.eclipse.core.resources.IWorkspaceRoot" />
				              <instanceof
				                    value="org.eclipse.core.resources.IProject" />
				              <instanceof
				                     value="org.eclipse.core.resources.IFolder" />
				           </or>
				  </triggerPoints>
		</navigatorContent>
	  </extension>
    <extension
          point="org.wso2.developerstudio.eclipse.project.export.handler">
       <handler
             class="org.wso2.developerstudio.eclipse.artifact.registry.project.export.RegistryArtifactHandler"
             id="org.wso2.developerstudio.eclipse.artifact.registry.project.export.registry.handler"
             type="registry/resource">
       </handler>
    </extension>

    <extension
         point="org.wso2.developerstudio.eclipse.greg.resourceProvider">
      <provider
            class="org.wso2.developerstudio.eclipse.artifact.registry.provider.RegistryResourceProvider"
            id="org.wso2.developerstudio.eclipse.capp.artifact.registry.provider"
            name="Carbon Application Registry Resources">
      </provider>
   </extension>
   <extension point="org.eclipse.ui.popupMenus">
                <objectContribution
                       objectClass="org.eclipse.core.resources.IProject"
                       id="org.wso2.developerstudio.eclipse.artifact.registry.editor.object">
                 <action
                     label="Registry Resources Editor"
                     icon="icons/resource.png"
                   class="org.wso2.developerstudio.eclipse.artifact.registry.ui.actions.ResourceEditorAction"
                        id="org.wso2.developerstudio.eclipse.artifact.registry.ui.actions">
               </action>
               <enablement>
						<adapt type="org.eclipse.core.resources.IProject">
							<test property="org.eclipse.core.resources.projectNature"
								value="org.wso2.developerstudio.eclipse.general.project.nature" />
						</adapt>
				</enablement>
               </objectContribution>
        </extension>
   	   <extension
         point="org.eclipse.ui.editors">
      <editor
            class="org.wso2.developerstudio.eclipse.artifact.registry.editor.ResourceFormEditor"
            id="org.wso2.developerstudio.eclipse.artifact.registry.editor"
            extensions="xml"
            name="Resources Editor">
      </editor>
   </extension>

   	<extension point="org.eclipse.ui.navigator.navigatorContent">
		<navigatorContent
            id="org.wso2.developerstudio.eclipse.artifact.registry.navigator"
            name="Registry resources"
            contentProvider="org.wso2.developerstudio.eclipse.artifact.registry.provider.ResourcesContentProvider"
            labelProvider="org.wso2.developerstudio.eclipse.artifact.registry.provider.ResourcesLabelProvider"
            activeByDefault="true"
            icon="icons/registry_nav.png"
            priority="normal" >
         <triggerPoints>
         	<and>
         	   <instanceof
                        value="org.eclipse.core.resources.IProject">
                  </instanceof>
                  <test
                        property="org.eclipse.core.resources.projectNature"
                        value="org.wso2.developerstudio.eclipse.general.project.nature">
                  </test>
			</and>
         </triggerPoints>
         <actionProvider class="org.wso2.developerstudio.eclipse.artifact.registry.provider.ResourceActionProvider"/>
         <possibleChildren>
            <or>
               <instanceof value="org.wso2.developerstudio.eclipse.artifact.registry.provider.NavigatorNode"/>
            </or>
         </possibleChildren>
      </navigatorContent>
	</extension>

	<extension
			point="org.eclipse.ui.navigator.viewer">
		<viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
			<includes>
				<contentExtension pattern="org.wso2.developerstudio.eclipse.artifact.registry.navigator*"/>
			</includes>
		</viewerContentBinding>
		<viewerContentBinding viewerId="org.eclipse.ui.navigator.PackageExplorer">
			<includes>
				<contentExtension pattern="org.wso2.developerstudio.eclipse.artifact.registry.navigator*"/>
			</includes>
		</viewerContentBinding>
	</extension>
</plugin>


text:
'use strict';

var CustomError  = require('es5-ext/lib/Error/custom')
  , indexOf      = require('es5-ext/lib/Array/prototype/e-index-of')
  , hasListeners = require('event-emitter/lib/has-listeners')

  , apply = Function.prototype.apply;

// Results are saved internally within array matrix:
// [0] -> Result of calling function with no arguments
// [1] -> Matrix that keeps results when function is called with one argument
//        [1][0] -> Array of arguments with which
//                 function have been called
//        [1][1] -> Array of results that matches [1][0] array
// [2] -> Matrix that keeps results when function is called with two arguments
//        [2][0] -> Array of first (of two) arguments with which
//                function have been called
//        [2][1] -> Matrixes that keeps results for two arguments function calls
//                  Each matrix matches first argument found in [2][0]
//                  [2][1][x][0] -> Array of second arguments with which
//                                  function have been called.
//                  [2][1][x][1] -> Array of results that matches [2][1][x][0]
//                                   arguments array
// ...and so on
module.exports = require('./_base')(function (conf, length) {
	var map, map1, map2, get, set, clear, count, fn
	  , hitListeners, initListeners, purgeListeners
	  , cache = conf.cache = {}, argsCache;

	if (length === 0) {
		map = null;
		get = conf.get = function () { return map; };
		set = function () { return ((map = 1)); };
		clear = function () { map = null; };
		conf.clearAll = function () {
			map = null;
			cache = conf.cache = {};
		};
	} else {
		count = 0;
		if (length === 1) {
			map1 = [];
			map2 = [];
			get = conf.get = function (args) {
				var index = indexOf.call(map1, args[0]);
				return (index === -1) ? null : map2[index];
			};
			set = function (args) {
				map1.push(args[0]);
				map2.push(++count);
				return count;
			};
			clear = function (id) {
				var index = indexOf.call(map2, id);
				if (index !== -1) {
					map1.splice(index, 1);
					map2.splice(index, 1);
				}
			};
			conf.clearAll = function () {
				map1 = [];
				map2 = [];
				cache = conf.cache = {};
			};
		} else if (length === false) {
			map = [];
			argsCache = {};
			get = conf.get = function (args) {
				var index = 0, set = map, i, length = args.length;
				if (length === 0) {
					return set[length] || null;
				} else if ((set = set[length])) {
					while (index < (length - 1)) {
						i = indexOf.call(set[0], args[index]);
						if (i === -1) return null;
						set = set[1][i];
						++index;
					}
					i = indexOf.call(set[0], args[index]);
					if (i === -1) return null;
					return set[1][i] || null;
				}
				return null;
			};
			set = function (args) {
				var index = 0, set = map, i, length = args.length;
				if (length === 0) {
					set[length] = ++count;
				} else {
					if (!set[length]) {
						set[length] = [[], []];
					}
					set = set[length];
					while (index < (length - 1)) {
						i = indexOf.call(set[0], args[index]);
						if (i === -1) {
							i = set[0].push(args[index]) - 1;
							set[1].push([[], []]);
						}
						set = set[1][i];
						++index;
					}
					i = indexOf.call(set[0], args[index]);
					if (i === -1) {
						i = set[0].push(args[index]) - 1;
					}
					set[1][i] = ++count;
				}
				argsCache[count] = args;
				return count;
			};
			clear = function (id) {
				var index = 0, set = map, i, args = argsCache[id], lengt


text:
import { WebviewApi } from "vscode-webview";

const vscode = acquireVsCodeApi<string>();

// $ExpectType string | undefined
vscode.getState();


text:
using System.Collections.Generic;
using HarryPotterUnity.Cards.Interfaces;
using HarryPotterUnity.Enums;

namespace HarryPotterUnity.Cards.Potions.Spells
{
    public class FireProtectionPotion : BaseSpell, IDamageSpell
    {
        public int DamageAmount { get; set; }

        protected override void Start()
        {
            base.Start();
            this.DamageAmount = 3;
        }

        protected override void SpellAction(List<BaseCard> targets)
        {
            this.Player.OppositePlayer.TakeDamage(this, this.DamageAmount);

            this.Player.TypeImmunity.Add(Type.Spell);
            this.Player.OnNextTurnStartEvent += () => this.Player.TypeImmunity.Remove(Type.Spell);
        }
    }
}