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

    +85

    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
    public final class Equality {
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eq(@Nullable O o, @Nullable O a) {
            return Objects.equals(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a) {
            return eq(o, a);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b) {
            return eq(o, a) || eq(o, b);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c) {
            return eqAny(o, a, b) || eq(o, c);
        }
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d) {
            return eqAny(o, a, b, c) || eq(o, d);
        }
    
    
        /**
         * @param o an object
         * @param a an object to be compared with {@code o} for equality
         * @param b an object to be compared with {@code o} for equality
         * @param c an object to be compared with {@code o} for equality
         * @param d an object to be compared with {@code o} for equality
         * @param e an object to be compared with {@code o} for equality
         * @return true if the any arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d, @Nullable O e) {
            return eqAny(o, a, b, c, d) || eq(o, e);
        }
        
        /**
         * @param o an object
         * @param a an array of objects to be compared
         * @return true if any the arguments are equal to each other and false otherwise
         */
        public static <O> boolean eqAny(@Nullable O o, O... a) {
            for(O e: a)
                if(eq(o, e))
                    return true;
            return false;
        }
    }

    Мой любимый класс.
    Когда на душе становится тяжело, я всегда открываю этот класс, и признаки депрессии улетучиваются.
    И да, комментарии врут, и да, там еще столько же методов eqAll(...)

    stasmarkin, 05 Марта 2015

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

    +62

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    void f(bool *ok = 0)
    {
        //тут возникла ошибка
        if (ok)
            *ok = false;
        return;
    }
    
    //далее в коде
    bool ok = false;
    f(&ok);

    не, ну заебок, чо

    blackhearted, 05 Марта 2015

    Комментарии (85)
  3. C++ / Говнокод #17730

    +51

    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
    #if defined(alignas) /* check C++ keywords */ \ 
    || defined(alignof) \ 
    || defined(asm) \ 
    || defined(auto) \ 
    || defined(bool) \ 
    
    <...snip...>
    
    || defined(virtual) \ 
    || defined(void) \ 
    || defined(volatile) \ 
    || defined(wchar_t) \ 
    || defined(while) 
    #error keyword defined before including C++ standard header 
    #endif /* defined... */

    Из заголовочных файлов VS 2012.

    http://www.viva64.com/en/b/0146/

    someone, 05 Марта 2015

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

    −113

    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
    user8@linux ~ $ python
    Python 2.7.5 (default, Feb 10 2014, 02:34:23) 
    [GCC 4.7.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import math
    >>> 1-3*(math.exp(1)-2)/math.exp(1)
    0.207276647028654
    >>> 1-4*(1-3*(math.exp(1)-2)/math.exp(1))
    0.17089341188538398
    >>> 1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))
    0.14553294057308008
    >>> 1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))
    0.1268023565615195
    >>> 1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))))
    0.11238350406936348
    >>> 1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))))
    0.10093196744509214
    >>> 1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))))))
    0.09161229299417073
    >>> 1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))))))
    0.0838770700582927
    >>> 1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))))))))
    0.07735222935878028
    >>> 1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))))))))
    0.07177324769463667
    >>> 1-13*(1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))))))))))
    0.06694777996972334
    >>> 1-14*(1-13*(1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))))))))))
    0.06273108042387321
    >>> 1-15*(1-14*(1-13*(1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))))))))))))
    0.059033793641901866
    >>> 1-16*(1-15*(1-14*(1-13*(1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))))))))))))
    0.05545930172957014
    >>> 1-17*(1-16*(1-15*(1-14*(1-13*(1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1)))))))))))))))
    0.05719187059730757
    >>> 1-18*(1-17*(1-16*(1-15*(1-14*(1-13*(1-12*(1-11*(1-10*(1-9*(1-8*(1-7*(1 - 6*(1 - 5*(1-4*(1-3*(math.exp(1)-2)/math.exp(1))))))))))))))))
    -0.029453670751536265

    Дано рекуррентное соотношение: x 1 = 1 e , x k = 1 − kx k−1 , k = 2, 3, 4, . . .
    Напишите программу, которая вычисляет первые 15 чисел с точностью float и выводит их на экран

    xXx_KaKaXa2002_xXx, 05 Марта 2015

    Комментарии (7)
  5. VisualBasic / Говнокод #17728

    −121

    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
    If ((ind_imit_gun = 0) And _
                ((input_B_LA2 And shop) = shop) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And lonely) = lonely) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 0) And _
                ((input_B_LA2 And shop) = shop) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And mashin) = mashin) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 1) And _
                ((input_B_LA2 And shop) = shop) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And lonely) = lonely) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 2) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And lonely) = lonely) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 2) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And mashin) = mashin) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 3) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And mashin) = mashin) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 4) And _
                ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And lonely) = lonely) And _
                (input_A_LA48 And choice_k) = choice_k) _
                Or ((ind_imit_gun = 6) And _
               ((input_B_LA2 And loading) = loading) And _
                ((input_B_LA2 And lonely) = lonely) And _
                (input_A_LA48 And choice_k) = choice_k) Then

    Вот такая страшная проверка нужных битов битовыми масками используется в одном военном ПО xD
    И на мой взгляд тут есть ошибки,но почему то работает.

    Ramirag, 05 Марта 2015

    Комментарии (19)
  6. PHP / Говнокод #17727

    +157

    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
    <?php
    class smth {
        protected static $MARK_UNDEFINED = 'Undefined';
        protected static $MARK_F  = 'ECTS-F';
        protected static $MARK_FX = 'ECTS-FX';
        protected static $MARK_E  = 'ECTS-E';
        protected static $MARK_D  = 'ECTS-D';
        protected static $MARK_C  = 'ECTS-C';
        protected static $MARK_B  = 'ECTS-B';
        protected static $MARK_A  = 'ECTS-A';
    
        protected function getECTSMark($rate, $current, $examRate)
        {
            $color = self::$MARK_UNDEFINED;
            if ($current > 0) {
                $percent = $rate / $current;
                if ($examRate !== NULL AND $examRate < 22)
                    $color = self::$MARK_FX;
                elseif ($percent < 0.31)
                    $color = self::$MARK_F;
                elseif ($percent < 0.60)
                    $color = self::$MARK_FX;
                elseif ($percent < 0.65)
                    $color = self::$MARK_E;
                elseif ($percent < 0.71)
                    $color = self::$MARK_D;
                elseif ($percent < 0.85)
                    $color = self::$MARK_C;
                elseif ($percent < 0.95)
                    $color = self::$MARK_B;
                else
                    $color = self::$MARK_A;
            }
            return $color;
        }
    }

    Сижу и думаю, как это вообще можно как-то.. отговнокодить? О_о

    xamgore, 05 Марта 2015

    Комментарии (20)
  7. Куча / Говнокод #17726

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    ###
    CoffeeScript
    Give a fuck
    ###
    while fuck isnt given
    	do give_a_fuck until orgasm

    mikamika83, 04 Марта 2015

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

    +51

    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
    #include <ppl.h>
    #include <windows.h>
    #include <ppltasks.h>
    #include <iostream>
    #include <vector>
    
    using namespace Concurrency;
    using namespace std;
    
    CRITICAL_SECTION cs6;
    
    int main(int argc, char* argv[])
    {
    	size_t concurentThreadsSupported = std::thread::hardware_concurrency();
    	cout << concurentThreadsSupported << endl;
    	//deadlock hazard increased with concurentThreadsSupported decreasing
    
    	size_t taskAmountForWasteVirtualCores = concurentThreadsSupported - 1;//must be equal to (virtual processor thread amount from Concurrency::IResourceManager) - 1
    	vector<task<void>> t;
    	for (size_t i = 0; i<taskAmountForWasteVirtualCores; ++i)
    		t.push_back(create_task([]{
    			Sleep(INFINITE);//some very long IO operation or deadlocked by EnterCriticalSection or sql transaction or other
    		}));
    	Sleep(1000);
        cout << "another way:" << endl;
        InitializeCriticalSection(&cs6);
        auto locker = create_task([]{
            cout << "locker" << endl;
            EnterCriticalSection(&cs6);//same as begin sql transaction
            cout << "locker entered cs 6" << endl;
            Concurrency::wait(500);//Deadlock by any concurrency context switching directly or indirectly by std or MFC (events, mutex, etc)
            cout << "locker played" << endl;
            LeaveCriticalSection(&cs6);//same as end sql transaction
            cout << "~locker ok" << endl;
        });
        auto locked = create_task([]{
            cout << "locked" << endl;
            EnterCriticalSection(&cs6);//same as begin sql transaction
            cout << "locked entered cs 6" << endl;
            Concurrency::wait(500);
            cout << "locked played" << endl;
            LeaveCriticalSection(&cs6);//same as end sql transaction
            cout << "~locked ok" << endl;
        });
    	Sleep(1000);
    	cout << "FAIL" << endl;
    	return 0;
    }

    Нашел дидлок)
    http://rextester.com/KHC72232
    http://rextester.com/EMG65441

    laMer007, 04 Марта 2015

    Комментарии (11)
  9. PHP / Говнокод #17724

    +170

    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
    public function action_ajaxlogin()
    	{
    		// Если запрос поступил не через AJAX, то шлем нахуй
    		if ( ! $this->request->is_ajax())
    		{
    			throw new HTTP_Exception_404(NULL);
    		}
    
    		// Вырубаем авто-рендер, ибо это хуев аякс запрос
    		$this->auto_render = false;
    
    		// Собираем информацию и пользователе в ёбанный массив
    		$user_data = $this->request->post('user_data');
    
    		// Если пользователь авторизирован, то заебато, и возвращаем статус 200!
    		if (Auth::instance()->login($user_data['username'], $user_data['password'], (bool) isset($user_data['remember_me'])))
    			return $this->response->status(200);
    
    		// Если нет, то "Вася, все хуйня! Давай по новой!"
    		return $this->response->status(400);
    	}
    
    	public function action_logout()
    	{
    		// Если запрос поступил не через AJAX, то шлем нахуй
    		if ( ! $this->request->is_ajax())
    		{
    			throw new HTTP_Exception_404(NULL);
    		}
    
    		// Вырубаем сучий авто-рендер, нахуй, в пизду блядь
    		$this->auto_render = false;
    
    		// Выходим из аккаунта, если вышли, то ахуенно, 200-ый статус)
    		if (Auth::instance()->logout())
    			return $this->response->status(200);
    
    		// Если все хуйня, то "Вася, давай по новой!"
    		return $this->response->status(400);
    	}

    Kohana фреймворк, и таких комментариев по проекту тьма :)

    proweber1, 03 Марта 2015

    Комментарии (130)
  10. JavaScript / Говнокод #17723

    +155

    1. 1
    logs.splice.apply(logs, [j, 1].concat(line.split("\n")));

    strax, 03 Марта 2015

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