1. Java / Говнокод #18099

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    @ResponseBody
    public String paymentFeedback(@RequestBody MultiValueMap<String, String> requestParameters, @RequestBody String requestBody) {
        boolean isValidRequest = myService.hasRequestValidSHASign(requestParameters);
        if (isValidRequest) {
            String voucherNumber = findParameter(requestParameters, ORDERID_PARAMETER);
            if (!StringUtils.isEmpty(voucherNumber)) {
                Order order = orderService.getOrderByVoucherNumber(voucherNumber);
                if (order != null) {
                    String status = findParameter(requestParameters, STATUS_PARAMETER);
                    if (ACCEPT_STATUS_VALUES.contains(status)) {
                        updateOrderWithPaymentStatus(order, Status.PAID, requestParameters);
                        orderService.sendEmail(order);
                        orderService.sell(order);
                    } else if (CANCELLED_STATUS_VALUE.equals(status)) {
                        updateOrderWithPaymentStatus(order, Status.CANCELLED, requestParameters);
                    } else if (DECLINE_STATUS_VALUES.contains(status)) {
                        updateOrderWithPaymentStatus(order, Status.DECLINED, requestParameters);
                    } else if (EXCEPTION_STATUS_VALUES.contains(status)) {
                        updateOrderWithPaymentStatus(order, Status.EXCEPTION, requestParameters);
                    } else {
                        logger.warn("Order ID={} got strange status: {}. Ignoring that feedback...", voucherNumber, status);
                    }
                } else {
                    throw new IllegalArgumentException("Can't find voucher with orderID from feedback: " + voucherNumber);
                }
            } else {
                throw new IllegalArgumentException("Received feedback with missing orderID: " + requestBody);
            }
        } else {
            throw new IllegalArgumentException("Received feedback with invalid SHA sign: " + requestBody);
        }
        
        return "";
    }

    pingw33n, 30 Апреля 2015

    Комментарии (1)
  2. C# / Говнокод #18098

    +147

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    public static void Unsubscribe
    <
    	T1,		T2,		T3,		T4,
    	T5,		T6,		T7,		T8,
    	T9,		T10,		T11,		T12,
    	T13,		T14,		T15,		T16
    >
    (
    	TKey eventKey,
    	Action
    	<
    		T1,		T2,		T3,		T4,
    		T5,		T6,		T7,		T8,
    		T9,		T10,		T11,		T12,
    		T13,		T14,		T15,		T16
    	> handler
    )
    { handlers[eventKey] -= handler; }

    Боль.

    pushistayapodmyshka, 30 Апреля 2015

    Комментарии (278)
  3. JavaScript / Говнокод #18097

    +144

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    function Calculation(a, b, op){
        if (typeof a == "number" && typeof (b) == "number"){
            var result;
            +a; +b;
            if (op == "+")  { result = a+b; alert(result);
            } else if (op == "-") { result = a-b; alert(result);
            } else if (op == "*"){ result = a*b; alert(result);
            } else if (op == "/"){
                if (b!=0){ 
                    result = a/b; alert(result);
                } else {
                    alert("Can`t divide on zero!");
                }
            }
        } else if (a instanceof Array && b instanceof Array) {
            var result = [];
            if ( a.length >= b.length ){
                length = a.length;
                for (var i=0; i < length; i++){
                    a[i] = parseFloat(a[i]);
                    b[i] = parseFloat(b[i]);
                    if (i < b.length-1){
                        if (op == "+"){ result[i] = a[i]+b[i];
                        } else if (op == "-"){ result[i] = a[i]-b[i];
                        } else if (op == "*"){ result[i] = a[i]*b[i];
                        } else if (op == "/"){
                            if (b[i]!=0){
                                result[i] = a[i]/b[i];
                            } else {
                                alert("Can`t divide on zero!");
                            }
                        }
                    } else {
                        result[i] = a[i];
                    }
                } 
                alert(result.join("  |  "));
            } else {
                length = b.length;
                for (var i=0; i < length; i++){
                    +a[i]; +b[i];
                    if (i < a.length-1){
                        switch (op){
                            case "+":
                                result[i] = a[i]+b[i];
                                break;
                            case "-":
                                result[i] = a[i]+b[i];
                                break;
                            case "*":
                                result[i] = a[i]+b[i];
                                break;
                            case "/":
                                if (b[i]!=0){
                                    result[i] = a[i]/b[i];
                                } else {
                                    alert("Can`t divide on zero!");
                                }
                                break;
                        }
                    } else {
                        result[i] = a[i];
                    }
                } 
                alert(result.join("  |  "));
            }
        } else if (a instanceof Object && b instanceof Object) {
            var tempObject = {};
                switch (op){
                    case "+":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "-":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "*":
                        tempObject.resultA = a.a+b.a;
                        tempObject.resultB = a.b+b.b;
                        break;
                    case "/":
                        if (b.b !=0 || b.a != 0){
                            tempObject.resultA = a.a+b.a;
                            tempObject.resultB = a.b+b.b;
                        } else {
                            alert("Can`t divide on zero!");
                        }
                        break;
                }
                
                alert(tempObject.resultA + " " + tempObject.resultB);
        }
    }

    Вот такой вот калькулятор!

    alexhelkar, 30 Апреля 2015

    Комментарии (10)
  4. Python / Говнокод #18096

    −118

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    def get_a():
        print("Hello goblin")
        return get_a
    
    get_a()()()()()()()()()()()()()

    Осталось понять зачем

    greenx, 30 Апреля 2015

    Комментарии (284)
  5. PHP / Говнокод #18095

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if(!$this->_login()){
                
                sleep(mt_rand(60, 90));
                $this->_reLogin();
                return;
    }

    Такое чудо мне передали от другой команды разработчиков

    Granes, 30 Апреля 2015

    Комментарии (1)
  6. JavaScript / Говнокод #18094

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var returnValue = false;
    
    bool result = doSomething();
    if (!result)
    {
    return returnValue;
    }
    
    returnValue = true;
    return returnValue;

    kuznetps, 30 Апреля 2015

    Комментарии (23)
  7. PHP / Говнокод #18093

    +132

    1. 1
    2. 2
    $result = mysql_query("INSERT INTO `selled` (`user`, `ip`, `date`, `name`, `mail`, `company`, `phone`, `phone2`, `sum`, `country`, `state`, `town`, `indexcountry`, `allcountry`, `payment`, `dost`) VALUES 
    	('".mysql_real_escape_string($_COOKIE['user'])."', '$_SERVER[REMOTE_ADDR]', NOW(), '".mysql_real_escape_string($_POST['name'])."', '".mysql_real_escape_string($_POST['mail'])."', '".mysql_real_escape_string($_POST['company'])."', '".mysql_real_escape_string($_POST['phone'])."', '".mysql_real_escape_string($_POST['phone2'])."', '".mysql_real_escape_string($_GET['sum'])."', '".mysql_real_escape_string($_POST['country'])."', '".mysql_real_escape_string($_POST['state'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['indexcountry'])."', '".mysql_real_escape_string($_POST['allcountry'])."', '".mysql_real_escape_string($_POST['paymethod'])."', '".mysql_real_escape_string($_POST['dost'])."')");

    Добавление товара

    ponchic, 30 Апреля 2015

    Комментарии (2)
  8. Java / Говнокод #18092

    +143

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    public void init() throws Exception {
    
            initGps103Server("gps103");
            initTk103Server("tk103");
            initGl100Server("gl100");
            initGl200Server("gl200");
            initT55Server("t55");
            initXexunServer("xexun");
            initTotemServer("totem");
            initEnforaServer("enfora");
            initMeiligaoServer("meiligao");
            initMaxonServer("maxon");
            initSuntechServer("suntech");
            initProgressServer("progress");
            initH02Server("h02");
            initJt600Server("jt600");
            initEv603Server("ev603");
            initV680Server("v680");
            initPt502Server("pt502");
            initTr20Server("tr20");
            initNavisServer("navis");
            initMeitrackServer("meitrack");
            initSkypatrolServer("skypatrol");
            initGt02Server("gt02");
            initGt06Server("gt06");
            initMegastekServer("megastek");
            initNavigilServer("navigil");
            initGpsGateServer("gpsgate");
            initTeltonikaServer("teltonika");
            initMta6Server("mta6");
            initMta6CanServer("mta6can");
            initTlt2hServer("tlt2h");
            initSyrusServer("syrus");
            initWondexServer("wondex");
            initCellocatorServer("cellocator");
            initGalileoServer("galileo");
            initYwtServer("ywt");
            initTk102Server("tk102");
            initIntellitracServer("intellitrac");
            initXt7Server("xt7");
            initWialonServer("wialon");
            initCarscopServer("carscop");
            initApelServer("apel");
            initManPowerServer("manpower");
            initGlobalSatServer("globalsat");
            initAtrackServer("atrack");
            initPt3000Server("pt3000");
            initRuptelaServer("ruptela");
            initTopflytechServer("topflytech");
            initLaipacServer("laipac");
            initAplicomServer("aplicom");
            initGotopServer("gotop");
            initSanavServer("sanav");
            initGatorServer("gator");
            initNoranServer("noran");
            initM2mServer("m2m");
            initOsmAndServer("osmand");
            initEasyTrackServer("easytrack");
            initTaipServer("taip");
            initKhdServer("khd");
            initPiligrimServer("piligrim");
            initStl060Server("stl060");
            initCarTrackServer("cartrack");
            initMiniFinderServer("minifinder");
            initHaicomServer("haicom");
            initEelinkServer("eelink");
            initBoxServer("box");
            initFreedomServer("freedom");
            initTelikServer("telik");
            initTrackboxServer("trackbox");
            initVisiontekServer("visiontek");
            initOrionServer("orion");
            initRitiServer("riti");
            initUlbotechServer("ulbotech");
            initTramigoServer("tramigo");
            initTr900Server("tr900");
            initArdi01Server("ardi01");
            initXt013Server("xt013");
            initAutoFonServer("autofon");
            initGoSafeServer("gosafe");
            initAutoFon45Server("autofon45");
            initBceServer("bce");
            initXirgoServer("xirgo");
            initCalAmpServer("calamp");
            initMtxServer("mtx");
            initTytanServer("tytan");
            initAvl301Server("avl301");
    
            initProtocolDetector();
        }

    Один я тут вижу говно? Внутри еще интереснее, особенно доставил метод start():
    https://github.com/tananaev/traccar/blob/master/src/org/traccar/ServerManager.java

    sakkath, 30 Апреля 2015

    Комментарии (3)
  9. Си / Говнокод #18091

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    fstat(fd, &s);
    count = s.st_size % sizeof(uint32_t) == 0 ? s.st_size : s.st_size + (sizeof(uint32_t) - s.st_size % sizeof(uint32_t));
    buf = malloc(count);
    /* etc */

    Собственно, round up to nearest 32-bit word. Нет ли метода покрасивше?

    codemonkey, 30 Апреля 2015

    Комментарии (0)
  10. C++ / Говнокод #18090

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    #ifndef FILTER_H
    #define FILTER_H
    
    #include <cassert>
    #include <vector>
    #include <algorithm>
    
    template<typename T>
    class filter_container;
    namespace detail {
    	template<typename Iter, typename Pred>
    	class filter {
    	public:
    		filter(Iter begin, Iter end, Pred pred) :_begin(begin), _end(end), _pred(pred) { }
    		filter(const filter & f) : _begin(f._begin), _end(f._end), _pred(f._pred) { }
    		filter & operator = (const filter & f) {
    			if(this != &f) {
    				_begin = f._begin;
    				_end = f._end;
    				_pred = f._pred;
    			}
    			return *this;
    		}
    		~filter() { }
    
    		class const_iterator {
    		public:
    			typedef typename Iter::reference reference;
    			typedef typename Iter::pointer pointer;
    			const_iterator(Iter iter, const filter & cont) :_iter(iter), _cont(&cont) { advance_until_pred(); }
    			const_iterator(const const_iterator & i) :_iter(i._iter), _cont(i._cont) { }
    			const_iterator & operator = (const const_iterator & i) {
    				if(this != &i) {
    					_iter = i._iter;
    					_cont = i._cont
    				}
    				return *this;
    			}
    			~const_iterator() { }
    			const_iterator & operator++() { advance_until_pred(); return *this; }
    			const_iterator operator++(int) {
    				const_iterator ret = *this;
    				advance_until_pred();
    				return ret;
    			}
    			const reference operator*() const { return *_iter; }
    			const pointer operator->() const { return &*_iter; }
    			bool operator == (const const_iterator & i) const {
    				assert(_cont == i._cont);
    				return _iter == i._iter;
    			}
    			bool operator != (const const_iterator & i) const { return !(*this == i); }
    		protected:
    			Iter _iter;
    			const filter * _cont;
    		private:
    			void advance_until_pred() {
    				if(_iter != _cont->_end) {
    					std::advance(_iter, 1);
    				}
    				_iter = std::find_if(_iter, _cont->_end, _cont->_pred);
    			}
    		private:
    			const_iterator();
    		};
    
    		class iterator : public const_iterator {
    		public:
    			iterator(Iter iter, const filter & cont) :const_iterator(iter, cont) { }
    			iterator(const iterator & i) :const_iterator(i) { }
    			iterator & operator = (const iterator & i) { const_iterator::operator=(i); return *this; }
    			~iterator() { }
    			reference operator*() { return *_iter; }
    			pointer operator->() { return &*_iter;  }
    		private:
    			iterator();
    		};
    
    		iterator begin() { return iterator(_begin, *this); }
    		iterator end() { return iterator(_end, *this); }
    		const_iterator cbegin() const { return const_iterator(_begin, *this); }
    		const_iterator cend() const { return const_iterator(_end, *this); }
    	private:
    		Iter _begin, _end;
    		Pred _pred;
    	private:
    		filter();
    	}; 
    }
    
    template<typename Iter, typename Pred> 
    detail::filter<Iter, Pred> filter(Iter begin, Iter end, Pred pred) {
    	return detail::filter<Iter, Pred>(begin, end, pred);
    }
    
    #endif // FILTER_H

    Тривиальная крестовщина, ничего выдающегося. Внезапно подумалось, что подобный контейнер был бы довольно удобен.
    Мне просто любопытно, насколько быстро этот пост будет слит автоминусаторами :)

    Xom94ok, 29 Апреля 2015

    Комментарии (14)