1. Лучший говнокод

    В номинации:
    За время:
  2. Java / Говнокод #25882

    +1

    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
    public class Main {
        public static void main(String[] args) {
            ThreeD[] f = {new ThreeD(5, 9, 7), new FourD(1,3,8,5)};
            Coords<ThreeD> c = new Coords<>(f);
            showXYZ(c);
            FiveD[] x = new FiveD[] {new FiveD(11,22,3,4, 123)};
            Coords<FiveD> b = new Coords<>(x);
            showAll(b);
            FiveD[] z = new FiveD[] {new FiveD(1,2,1,6,5)};
            Coords<FiveD> zz = new Coords<>(z);
        }
        private static void showXY(Coords<? super FourD> c) {
            for(int i = 0; i < c.coords.length; i++) {
                System.out.println(c.coords[i].x +" "+ c.coords[i].y+" ");
            }
        }
    
        private static void showXYZ(Coords<? extends ThreeD> c) {
            for(int i = 0; i < c.coords.length; i++) {
                System.out.println(c.coords[i].x +" "+ c.coords[i].y+" "+c.coords[i].z+" ");
            }
        }
        private static void showAll(Coords<? extends FiveD> c) {
            for(int i = 0; i < c.coords.length; i++) {
                System.out.println(c.coords[i].x +" "+ c.coords[i].y+" "+c.coords[i].z+" "+c.coords[i].t+" "+c.coords[i].m);
            }
        }
    }
    
    class Coords<T extends TwoD> {
        T[] coords;
        Coords(T[] o) {
            coords = o;
        }
    }
    
    class TwoD {
        int x,y;
        TwoD(int a, int b) {
            x = a;
            y = b;
        }
    }
    class ThreeD extends TwoD {
        int z;
        ThreeD(int a, int b, int c) {
            super(a, b);
            z = c;
        }
    }
    class FourD extends ThreeD {
        int t;
        FourD(int a, int b, int c, int d) {
            super(a, b, c);
            t = d;
        }
    }
    class FiveD extends FourD {
        int m;
        FiveD(int a, int b, int c, int d, int e) {
            super(a, b, c, d);
            m = e;
        }
    }

    говнецо или нет

    codershitter, 29 Сентября 2019

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

    0

    1. 1
    2. 2
    https://habr.com/ru/post/449368/
    Ко-ко-ко-ко-ко-кой багор )))

    KJlueHTcKuu_nemyx, 25 Апреля 2019

    Комментарии (56)
  4. PHP / Говнокод #25553

    −1

    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
    <?php $connection = mysqli_connect ('localhost','root','','userlistdb'); 
           
    
    
    // Проверка, если это общий клиент
    if (!empty($_SERVER['HTTP_CLIENT_IP'])){
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    //Is it a proxy address
    }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }else{
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    // Значение $ ip в этот момент будет выглядеть примерно так: "192.0.34.166"
    $ip = ip2long($ip);
    // Теперь $ ip будет выглядеть примерно так: 1073732954
    
    
    $sql = "INSERT INTO user(ip) VALUES('$ip')";
    $dbQuery = mysql_query($sql,$dbLink);
    
    
    
        $stmt = $dbh->prepare("INSERT INTO usertbl(ip) VALUES(ip)");
        $stmt->bindParam(1, $ip);
    
        $stmt->execute();
    ?>
    выдаёт ошибку:
    Примечание : Не определено переменная: DBLink в C: \ XAMPP \ HTDOCS \ офсетные \ testip.php на линии 21 
    
    Внимание : mysql_query () ожидает параметр 2 , чтобы быть ресурсом, приведены в нуль C: \ XAMPP \ HTDOCS \ кормили \ testip.php на строка 21 
    
    Примечание : неопределенная переменная: dbh в C: \ xampp \ htdocs \ fed \ testip.php в строке 25 
    
    Фатальная ошибка : вызов функции-члена prepare () для null в C: \ xampp \ htdocs \ fed \ testip.php на линии 25
    
    $dbQuery = mysql_query($sql,$dbLink);
    
    $stmt = $dbh->prepare("INSERT INTO usertbl(ip) VALUES(ip)");

    Кто знает как записать IP из формы и сохранить в базу даных MySQL

    arts, 18 Апреля 2019

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

    +3

    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
    // A sample standard C++20 program that prints
    // the first N Pythagorean triples.
    #include <iostream>
    #include <optional>
    #include <ranges>   // New header!
     
    using namespace std;
     
    // maybe_view defines a view over zero or one
    // objects.
    template<Semiregular T>
    struct maybe_view : view_interface<maybe_view<T>> {
      maybe_view() = default;
      maybe_view(T t) : data_(std::move(t)) {
      }
      T const *begin() const noexcept {
        return data_ ? &*data_ : nullptr;
      }
      T const *end() const noexcept {
        return data_ ? &*data_ + 1 : nullptr;
      }
    private:
      optional<T> data_{};
    };
     
    // "for_each" creates a new view by applying a
    // transformation to each element in an input
    // range, and flattening the resulting range of
    // ranges.
    // (This uses one syntax for constrained lambdas
    // in C++20.)
    inline constexpr auto for_each =
      []<Range R,
         Iterator I = iterator_t<R>,
         IndirectUnaryInvocable<I> Fun>(R&& r, Fun fun)
            requires Range<indirect_result_t<Fun, I>> {
          return std::forward<R>(r)
            | view::transform(std::move(fun))
            | view::join;
      };
     
    // "yield_if" takes a bool and a value and
    // returns a view of zero or one elements.
    inline constexpr auto yield_if =
      []<Semiregular T>(bool b, T x) {
        return b ? maybe_view{std::move(x)}
                 : maybe_view<T>{};
      };
     
    int main() {
      // Define an infinite range of all the
      // Pythagorean triples:
      using view::iota;
      auto triples =
        for_each(iota(1), [](int z) {
          return for_each(iota(1, z+1), [=](int x) {
            return for_each(iota(x, z+1), [=](int y) {
              return yield_if(x*x + y*y == z*z,
                make_tuple(x, y, z));
            });
          });
        });
     
        // Display the first 10 triples
        for(auto triple : triples | view::take(10)) {
          cout << '('
               << get<0>(triple) << ','
               << get<1>(triple) << ','
               << get<2>(triple) << ')' << '\n';
      }
    }

    «C++20»: ещё больше модерна! Ещё больше шаблонов! Ещё больше ебанутых конструкций! Ещё больше блядского цирка!
    s: http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/

    gost, 30 Декабря 2018

    Комментарии (56)
  6. Си / Говнокод #24739

    +2

    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
    if (!(fs_info->workers && fs_info->delalloc_workers &&
      fs_info->submit_workers && fs_info->flush_workers &&
      fs_info->endio_workers && fs_info->endio_meta_workers &&
      fs_info->endio_meta_write_workers &&
      fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
      fs_info->endio_freespace_worker && fs_info->rmw_workers &&
      fs_info->caching_workers && fs_info->readahead_workers &&
      fs_info->fixup_workers && fs_info->delayed_workers &&  // <===
      fs_info->fixup_workers && fs_info->extent_workers &&   // <===
      fs_info->qgroup_rescan_workers)) {
        err = -ENOMEM;
        goto fail_sb_buffer;
    }

    https://bugzilla.kernel.org/show_bug.cgi?id=82021

    Глаз-алмаз!

    wvxvw, 10 Сентября 2018

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

    0

    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
    switch ($city) {
    			case $city == 'Москва':
    				$tel['work'] = '+7 (495) www-ww-22';
    				$tel['entire'] = '8 (800) xxx-xx-49';
    				break;
    			case $city == 'Нижний-Новгород':
    				$tel['work'] = '+7 (495) zzz-zz-02';
    				$tel['entire'] = '8 (800) zzz-zz-02';
    				break;
    			case $city == 'Ростов-на-Дону':
    				$tel['work'] = '+7 (495) zzz-zz-03';
    				$tel['entire'] = '8 (800) zzz-zz-03';
    				break;
    			case $city == 'Казань':
    				$tel['work'] = '+7 (495) zzz-zz-04';
    				$tel['entire'] = '8 (800) zzz-zz-04';
    				break;
    			case $city == 'Тюмень':
    				$tel['work'] = '+7 (495) zzz-zz-05';
    				$tel['entire'] = '8 (800) zzz-zz-05';
    				break;

    Мало того, что странное использование case, так это ещё повторяется для 28 городов.
    Одинаковые части номеров заменил на zzz-zz

    Int, 06 Февраля 2018

    Комментарии (56)
  8. Assembler / Говнокод #20423

    −715

    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
    return instruction emitted twice with branch target inbetween
    
    function
    
    unsigned int fact( unsigned int n) { return n < 1 ? 1 : n*fact(n-1); }
    
    produces
    
    fact:
    .LFB0:
            .cfi_startproc
            testl   %edi, %edi
            movl    $1, %eax
            je      .L4
            .p2align 4,,10
            .p2align 3
    .L3:
            imull   %edi, %eax
            subl    $1, %edi
            jne     .L3
            rep ret # <-- this instruction can be removed
    .L4:
            rep ret
            .cfi_endproc
    .LFE0:
            .size   fact, .-fact
            .section        .text.unlikely

    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71923 даже факториал не могут скомпилировать нормально

    j123123, 25 Июля 2016

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

    0

    1. 1
    2. 2
    3. 3
    if (strpos($route, ':') !== false) {
                    $route = str_replace(':any', '([^/]+)', str_replace(':num', '([0-9]+)', str_replace(':all', '(.+)', $route)));
                }

    Очередная обезьяна села высерать свои мысли на PHP ... Уже много говорили тут о mpak и его "cms", вот вам еще одно "чудо": https://github.com/wolfcms/wolfcms

    zenn1989, 24 Июня 2016

    Комментарии (56)
  10. PHP / Говнокод #19817

    0

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    public function actionView($id = null) {
    
            $user = Yii::$app->user->identity;
            $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : $id;
    
    
            $new_model = 0;
            if (empty($id)) {
                $draft_model = Applicant::find()->where(['draft' => 1, 'created_by' => $user->id])->one();
                if (empty($draft_model)) {
                    $draft_model = new Applicant();
                    $new_model = 1;
                    $draft_model->draft = 1;
                    $draft_model->save();
                }
                if (!empty($draft_model->id)) {
                    $id = $draft_model->id;
                }
            }
            $model = $this->findModel($id);
            $allow_sections = [];
            if (empty($model->draft)) {
                $updateRequest = \app\models\UserRequest::find()->where(['user_id' => $user->id, 'object_id' => $id, 'status' => 2])->one();
                if (!empty($updateRequest)) {
                    $allow_sections = explode(";", $updateRequest->additional_info);
                }
            }
    
            if (isset($_GET['done']) && $_GET['done'] == 1) {
                $result['success'] = false;
    
                $userRequest = \app\models\UserRequest::find()->where(['user_id' => $user->id, 'object_id' => $id, 'status' => 2])->one();
                if (!empty($userRequest)) {
                    $userRequest->status = 3;
                    if ($userRequest->save()) {
                        $result['success'] = true;
                    } else {
                        $error = \yii\widgets\ActiveForm::validate($userRequest);
                        if ($error != '[]') {
                            $result['msg'] = $error;
                        }
                    }
                }
    
                echo(json_encode($result));
                exit;
            } elseif (isset($_FILES['files']['name'][0]) && isset($_FILES['files']['type'][0]) && isset($_FILES['files']['tmp_name'][0]) && isset($_FILES['files']['size'][0])) {
                $result['success'] = false;
    
                $filename = strtotime("now") . "_" . $_FILES['files']['name'][0];
                $size = $_FILES['files']['size'][0];
    
                $uploaddir = realpath('../web') . '/images/applicant/';
                if (!file_exists($uploaddir)) {
                    mkdir($uploaddir);
                }
                $uploadfile = $uploaddir . basename($filename);
                $path_image = '/images/applicant/' . basename($filename);
                if (move_uploaded_file($_FILES['files']['tmp_name'][0], $uploadfile)) {
    
                    if (!empty($model->photo_id)) {
                        $photo_model = \app\models\File::findOne($model->photo_id);
                    }
    
                    if (empty($photo_model->id)) {
                        $photo_model = new \app\models\File();
                    }
    
                    $photo_model->original = $filename;
                    $photo_model->name = $filename;
                    $photo_model->size = $size;
                    $photo_model->mime = $_FILES['files']['type'][0];
                    $photo_model->hash = $photo_model->generateHash();
    
                    if ($photo_model->save()) {
                        $model->photo_id = $photo_model->id;
                        if ($model->save()) {
                            $result['img'] = $filename;
                            $result['success'] = true;
                        }
                    }
                    $image = new Image();
                    $image->load($uploadfile);
                    if($image->getWidth()>640){
                        $image->resizeToWidth(640);
                        $image->save($uploadfile);
                    }
                }
    
                echo(json_encode($result));
                exit;
            } elseif (isset($_REQUEST['name'])) {
                $result['success'] = false;
    
                $model_attributes = $model->getAttributes();
                $model_attributes['education'] = '';
                unset($model_attributes['id']);
                if ($_REQUEST['name'] == 'address_properties') {
                    $values = json_decode($_REQUEST['value'], true);
                    $names_values = ['address_region', 'address_city', 'address_street', 'address_house'];

    yii 2

    print_r_var_dump, 14 Апреля 2016

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

    +2

    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
    /***
    *assert.h - define the assert macro
    *
    *       Copyright (c) Microsoft Corporation. All rights reserved.
    *
    *Purpose:
    *       Defines the assert(exp) macro.
    *       [ANSI/System V]
    *
    *       [Public]
    *
    ****/
    
    
    /*
    #include <crtdefs.h>
    
    #undef  assert
    
    #ifdef  NDEBUG
    
    #define assert(_Expression)     ((void)0)
    
    #else
    
    #ifdef  __cplusplus
    extern "C" {
    #endif
    
    _CRTIMP void __cdecl _wassert(_In_z_ const wchar_t * _Message, _In_z_ const wchar_t *_File, _In_ unsigned _Line);
    
    #ifdef  __cplusplus
    }
    #endif
    
    #define assert(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )
    
    #endif   */
    
    #pragma once
    #ifdef NDEBUG
    #define assert(expr)
    #else
    inline void CheckExpression_(bool expr)
    {
    	if (!expr)
    	{
    		expr=true; // put breakpoint here, happy user;
    		CheckExpression_(expr);
    	}
    }
    
    inline void CheckExpression_(void* expr)
    {
    	if (!expr)
    	{
    		expr=(void*)(1); // put breakpoint here, happy user;
    		CheckExpression_(expr);
    	}
    }
    
    #define assert(expr) CheckExpression_(expr);
    #endif

    Сука я не знаю, почему в студии-2008 родной ассерт показывает не ту строку, на которой он произошёл и в стеке вызовов хуйня какая-то, и как подключить DebugBreak я тоже не знаю, потому что в windef.h куча хуеты, выдающей 100500 ошибок компиляции. Чтобы хоть как-то можно было жить, пришлось сделать так.

    TarasB, 13 Января 2016

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