- 1
self.slides = self.tour_data.slides = ...Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 49
−112
self.slides = self.tour_data.slides = ...
+155
js меня восхищает, реально. это язык, где проблемы с замыканием можно решить, добавив ещё одно замыкание. прикинем, например
var object = ...;
doShit(function /* async callback */ () { object.doOtherShit(); });
пока вроде как всё зашибись. но вдруг понадобилось написать цикл:
for (var i....) {
  var object = array[i];
  doShit(function /* this now fails hard */ () { object.doOtherShit(); });
}
что же делац? правильно, врапим всё в ещё одну функцию:
for (var i....) {
  (function(object){
    doShit(function /* oh, it's okay again */ () { object.doOtherShit(); });
  })(array[i]);
}
−103
public static var ssa:uint = 161;
...
Globals.ssa = (Globals.ssa + ++VSIZE);
sd = new ByteArray();
ba.readBytes(sd);
ba.position = 0;
ba.length = 0;
do
{
	Globals.ssa = sCompress;
	Globals.ssa = ((Globals.ssa * V[0]) & 4194303);
	...из того же источника
−102
x = 1;
					x = (x >> 11);
					x = (x + 1);
					x = (x >> 9);
					x = (x + 1);
					x = (x >> 7);
					x = (x + 1);
					x = (x >> 5);
					x = (x + 1);
					x = (x >> 3);
					x = (x + 1);
					x = (x >> 10);
					x = (x + 1);
					x = (x >> 8);
					x = (x + 1);
					x = (x >> 6);
					x = (x + 1);
					x = (x >> 4);
					x = (x + 1);
					x = (x >> 2);
					x = (x + 1);
					if (x == 1)
					{
						ge.ha = true;
					};из недр не менее изощрённого распковщика обфусцированного xml
−129
private function onError(e:IOErrorEvent):void {
		(e.target as EventDispatcher).removeEventListener(IOErrorEvent.IO_ERROR, onError);какого, спрашивается, хуя e.target типа Object а не EventDispatcher ?
+68
public static AstRoot parse (String code) {
        CompilerEnvirons env = new CompilerEnvirons();
        env.setRecoverFromErrors(true);
        env.setGenerateDebugInfo(true);
        env.setRecordingComments(true);
        // try to ignore errors - does not seem to work
        env.setIdeMode(true);
        IRFactory factory = new IRFactory(env);
        AstRoot root = factory.parse(code, null, 0);
        // work around rhino bug 800616 (not fixed in neither rhino nor closure)
        root.visit(new NodeVisitor() {
            @Override
            public boolean visit(AstNode node) {
                if (node instanceof NumberLiteral) {
                    NumberLiteral num = (NumberLiteral)node;
                    int from = num.getAbsolutePosition();
                    int to = from + num.getLength() + 2;
                    if (to < code.length()) {
                        String hex = "0x" + num.toSource();
                        if (code.substring(from, to).equals(hex)) {
                            // reset node value and length
                            num.setValue(hex); num.setLength(hex.length());
                        }
                    }
                    return false;
                }
                return true;
            }
        });
        // work around rhino SwitchStatement.toSource() bug with empty switches
        // https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ast/SwitchStatement.java#L96
        // https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ast/SwitchStatement.java#L107-L109
        // https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ast/SwitchStatement.java#L158
        root.visit(new NodeVisitor() {
            @Override
            public boolean visit(AstNode node) {
                if (node instanceof SwitchStatement) {
                    SwitchStatement ss = (SwitchStatement)node;
                    if (ss.getCases().isEmpty()) {
                        // need to add at least one node to make ss.cases non-null
                        ArrayList<SwitchCase> cases = new ArrayList<>();
                        cases.add(new SwitchCase());
                        ss.setCases(cases);
                        // set this back to empty list
                        cases.clear();
                        ss.setCases(cases);
                    }
                    return false;
                }
                return true;
            }
        });
        return root;
    }И ещё немножко трудовыебуднев пользователей рино: правда клёво взять и распарсить джаваскрипт одним простым методом? Авотхуй.
+70
public static void replaceChild (AstNode parent, AstNode child, AstNode newChild) {
        try {
            parent.replaceChild(child, newChild)
        } catch (NullPointerException e1) {
            // this is one of those shitty nodes with default children handling broken
            try {
                // maybe it was assignment
                Assignment ass = (Assignment)parent
                if (ass.left == child) {
                    ass.left = newChild
                } else {
                    ass.right = newChild
                }
            } catch (Throwable e2) {
                // not assignment :S
                try {
                    // maybe it's (...)
                    ParenthesizedExpression pae = (ParenthesizedExpression)parent
                    pae.expression = newChild
                } catch (Throwable e3) {
                    // not (...) either :S
                    try {
                        // Function call?
                        FunctionCall fuc = (FunctionCall)parent
                        for (int i = 0; i < fuc.arguments.size(); i++) {
                            if (fuc.arguments.get(i) == child) {
                                fuc.arguments.set(i, newChild)
                                break;
                            }
                        }
                    } catch (Throwable e4) {
                        try {
                            // Expression statement?
                            ExpressionStatement est = (ExpressionStatement)parent
                            est.expression = newChild
                        } catch (Throwable e5) {
                            try {
                                // var foo = bar?
                                VariableInitializer vin = (VariableInitializer)parent
                                if (vin.initializer == child) {
                                    vin.initializer = newChild
                                } else {
                                    // should not happen in our useage
                                    vin.target = newChild
                                }
                            } catch (Throwable e6) {
                                try {
                                    // what if?
                                    IfStatement ifs = (IfStatement)parent
                                    if (ifs.condition == child) {
                                        ifs.condition = newChild
                                    } else if (ifs.thenPart == child) {
                                        ifs.thenPart = newChild
                                    } else {
                                        ifs.elsePart = newChild
                                    }
                                } catch (Throwable e7) {
                                    try {
                                        // while loop?
                                        WhileLoop whl = (WhileLoop)parent
                                        if (whl.condition == child) {
                                            whl.condition = newChild
                                        } else {
                                            whl.body = newChild
                                        }
                                    } catch (Throwable e8) {
                                        try {
                                            // Infix expression?
                                            InfixExpression iex = (InfixExpression)parent
                                            if (iex.left == child) {
                                                iex.left = newChild
                                            } else {
                                                iex.right = newChild
                                            }
                                        } catch (Throwable e9) {
                                            try {
                                                // do loop?
                                                DoLoop dol = (DoLoop)parent
                                                if (dol.condition == child) {
                                                    dol.condition = newChild
                                                } else {
                                                    dol.body = newChild
                                                }
                                            } catch (Throwable e10) {
                                                try {
                                                    // for loop?
                                                    ForLoop fol = (ForLoop)parent
                                                    if (fol.condition == child) {
                                                        fol.condition = newChild
                                                    } else if (fol.initializer == child) {
                                                        fol.initializer = newChild
                                                    } else if (fol.increment == child) {
                                                        fol.increment = newChild
                                                    } else {
                                                        fol.body = newChild
                                                    }
                                                } catch (Throwable e11) {
                                                    try {
                                                        ConditionalExpression cex = (ConditionalExpression)parent
                                                        if (cex.testExpression == child) {
            Есть такой жавоскриптопарсер рино. И есть в нём замечательный метод replaceChild, который заменяет в AstNode одного ребёнка другим. Вот только в большей части наследников AstNode он сломан нах.
(пс нету ; ибо груви)
        
+155
/**
 * Checks if a setting is enabled
 *
 * @api public
 */
Manager.prototype.enabled = function (key) {
  return !!this.settings[key];
};
/**
 * Checks if a setting is disabled
 *
 * @api public
 */
Manager.prototype.disabled = function (key) {
  return !this.settings[key];
};https://github.com/LearnBoost/socket.io/blob/develop/lib/manager.js
−120
private function uncaughtError (e:UncaughtErrorEvent):void {
			// be a good girl and swallow
			e.stopImmediatePropagation ();
		}написал какую-то хуету и сижу, радуюсь как маленький. да, я хочу поговорить об этом.
−89
if ("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def") {
                options.ad_started();
                var fn:Function = function ():void {
                    options.ad_finished();
                };
                setTimeout(fn, 100);
                return;
            }сегодня в выпуске - как задизаблить мойшеадс лёгким движением руки в любой флешке, скомпиленной со стандартной либой