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

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

    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
    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
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <stdint.h>
    
    #define GEN_NAME(type) struct myvec_ ## type
    
    #define MK_VEC_TYPE(type) GEN_NAME(type) {size_t sz; type arr[];}; 
    
    #define MK_VEC_NEW(type) \
    GEN_NAME(type) *myvec_new_ ## type (size_t num) \
    { \
      struct myvec_ ## type *tmp = malloc(sizeof(type) * num); \
      if (tmp == NULL) \
      { \
        return NULL; \
      } \
      tmp->sz = num; \
      return tmp; \
    }
    
    #define MK_VEC_DELETE(type) \
    void myvec_delete_ ## type (GEN_NAME(type) *v) \
    { \
      free(v); \
    }
    
    
    #define MK_VEC_GET(type) \
    type myvec_get_ ## type (GEN_NAME(type) *v, size_t pos) \
    { \
      if(pos < v->sz) \
      { \
        return v->arr[pos]; \
      } \
      else \
      { \
        exit(-1); \
      } \
    }
    // исключения - говно
    
    #define MK_VEC_SET(type) \
    void myvec_set_ ## type (GEN_NAME(type) *v, size_t pos, type val) \
    { \
      if(pos < v->sz) \
      { \
        v->arr[pos] = val; \
      } \
      else \
      { \
        exit(-1); \
      } \
    }
    
    
    #define MK_VEC_GETSZ(type) \
    size_t myvec_getsz_ ## type (GEN_NAME(type) v) \
    { \
      return v.sz; \
    }
    
    #define MK_SHIT(type) \
    MK_VEC_TYPE(type) \
    MK_VEC_NEW(type) \
    MK_VEC_DELETE(type) \
    MK_VEC_GET(type) \
    MK_VEC_GETSZ(type) \
    MK_VEC_SET(type)
    
    MK_SHIT(int)
    MK_SHIT(float)
    MK_SHIT(double)
    
    #define test(a) _Generic(a, int : 1, GEN_NAME(int) : 2, default : 0)
    
    #define MTD_C(val,mtd) _Generic( val,\
      GEN_NAME(int): myvec_ ## mtd ##_int, \
      GEN_NAME(float): myvec_ ## mtd ##_float, \
      GEN_NAME(double): myvec_ ## mtd ##_double, \
      default: 0) // хуй там!
    
    #define GET(vec,pos) MTD_C(vec,get)(&vec,pos)
    #define SET(vec, pos, val) MTD_C(vec,set)(&vec,pos,val)
    #define GETSZ(vec) MTD_C(vec,getsz)(vec)
      
    int main(void)
    {
      GEN_NAME(int) *vec1 = myvec_new_int(10);
      SET(*vec1, 0, 123);
      size_t size = GETSZ(*vec1);
      printf("vector size is %zu\n", size);
      printf("vector vec1[0] is %d\n", GET(*vec1,0));
      return 0;
    }

    Какое ООП)))

    j123123, 07 Августа 2020

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

    +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
    // Both set_time_limit(...) and  ini_set('max_execution_time',...); won't count the time cost of sleep,
    // file_get_contents,shell_exec,mysql_query etc, so i build this function my_background_exec(),
    // to run static method/function in background/detached process and time is out kill it:
    
    // my_exec.php:
    <?php
    function my_background_exec($function_name, $params, $str_requires, $timeout=600)
             {$map=array('"'=>'\"', '$'=>'\$', '`'=>'\`', '\\'=>'\\\\', '!'=>'\!');
              $str_requires=strtr($str_requires, $map);
              $path_run=dirname($_SERVER['SCRIPT_FILENAME']);
              $my_target_exec="/usr/bin/php -r \"chdir('{$path_run}');{$str_requires} \\\$params=json_decode(file_get_contents('php://stdin'),true);call_user_func_array('{$function_name}', \\\$params);\"";
              $my_target_exec=strtr(strtr($my_target_exec, $map), $map);
              $my_background_exec="(/usr/bin/php -r \"chdir('{$path_run}');{$str_requires} my_timeout_exec(\\\"{$my_target_exec}\\\", file_get_contents('php://stdin'), {$timeout});\" <&3 &) 3<&0";//php by default use "sh", and "sh" don't support "<&0"
              my_timeout_exec($my_background_exec, json_encode($params), 2);
             }
    // ...

    Шедевр (заплюсованный) из https://www.php.net/manual/ru/function.set-time-limit.php.

    gost, 30 Июля 2020

    Комментарии (4)
  4. C# / Говнокод #26822

    −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
    else if (BallToDown(paddle_2, paddle_2_pos, new Rectangle((int)ball_pos.X, (int)ball_pos.Y, ball.Width, ball.Height)))
                {
                    Paddle_s.Play();
                    ballSpeed = new Vector2(9.0f, 4.5f);
                }
                /*Левая Ракетка*/
                //Ограничения по Оси Y
                if (paddle_2_pos.Y < 0)
                    paddle_2_pos.Y = 0;
                else if (paddle_2_pos.Y > Window.ClientBounds.Height - paddle_2.Height)
                    paddle_2_pos.Y = Window.ClientBounds.Height - paddle_2.Height;
                //Управление Ракеткой
                if (Keyboard.GetState().IsKeyDown(Keys.W))
                    paddle_2_pos.Y -= speed;
                else if (Keyboard.GetState().IsKeyDown(Keys.S))
                    paddle_2_pos.Y += speed;
                /*Правая Ракетка*/
                //Ограниччения по Оси Y
                if (paddle_1_pos.Y < 0)
                    paddle_1_pos.Y = 0;
                else if (paddle_1_pos.Y > Window.ClientBounds.Height - paddle_1.Height)
                    paddle_1_pos.Y = Window.ClientBounds.Height - paddle_1.Height;
                //Управление Ракеткой
                if (Keyboard.GetState().IsKeyDown(Keys.Up))
                    paddle_1_pos.Y -= speed;
                else if (Keyboard.GetState().IsKeyDown(Keys.Down))
                    paddle_1_pos.Y += speed;
                base.Update(gameTime);
            }
    
            protected override void Draw(GameTime gameTime)
            {
                GraphicsDevice.Clear(Color.Black);
                spriteBatch.Begin();
                spriteBatch.Draw(paddle_1, paddle_1_pos, Color.White);
                spriteBatch.Draw(paddle_2, paddle_2_pos, Color.White);
                spriteBatch.Draw(ball, ball_pos, Color.White);
                spriteBatch.End();
    
                base.Draw(gameTime);
            }
            public bool BallToUp(Texture2D paddle, Vector2 paddle_pos, Rectangle ballRect)
            {
                /*Создаётся прямоугольник размером 1/3 от всей ракетки*/
                Rectangle paddleRect = new Rectangle((int)paddle_pos.X, (int)paddle_pos.Y, paddle.Width, (int)paddle.Height / 2);
                return ballRect.Intersects(paddleRect);
            }
            public bool BallToDown(Texture2D paddle, Vector2 paddle_pos, Rectangle ballRect)
            {
                /*Создаётся прямоугольник размером 1/3 от всей ракетки*/
                Rectangle paddleRect = new Rectangle((int)paddle_pos.X, (int)paddle_pos.Y + (paddle.Height / 2), paddle.Width, (int)paddle.Height / 2);
                return ballRect.Intersects(paddleRect);
            }
        }
    }

    Недавно начал программировать на C#, Решил написать Пин-Понг на моногейм, Плучилось нечто но работает отлично: отрывок кода сверху

    APV, 28 Июля 2020

    Комментарии (4)
  5. Java / Говнокод #26797

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    List<UserScoreDTO> userScores = users.stream()
                    .map((u) -> ScoreUtils.aggregateUserAndFlagData(u, maxTestScore))
                    .collect(toList());
    
    return userScores.stream();

    Collect to List<UserScoreDTO> then stream the list to Stream<UserScoreDTO>

    johann, 08 Июля 2020

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    # while 1 через for
    
    shits = ['говно']
    
    for shit in shits:
    	print('Говно')
    	shits.append('говно')

    Прост while 1 через for

    lpjakewolfskin, 28 Июня 2020

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    吾有一術。名之曰「斐波那契」。欲行是術。必先得一數。曰「甲」。乃行是術曰。
    	若「甲」等於零者乃得零也
    	若「甲」等於一者乃得一也
    	減「甲」以一。減「甲」以二。名之曰「乙」。曰「丙」。
    	施「斐波那契」於「乙」。名之曰「丁」。
    	施「斐波那契」於「丙」。名之曰「戊」。
    	加「丁」以「戊」。名之曰「己」。
    	乃得「己」。
    是謂「斐波那契」之術也。
    
    施「斐波那契」於十二。書之。

    文言 wenyan-lang
    Числа Фибоначчи.

    https://github.com/wenyan-lang/wenyan

    jojaxon, 01 Июня 2020

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

    +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
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    class Person {
        protected name: string;
        constructor(name: string) { this.name = name; }
    }
    
    class Employee extends Person {
        private department: string;
    
        constructor(name: string, department: string) {
            super(name);
            this.department = department;
        }
    
        public get ElevatorPitch() {
            return `Hello, my name is ${this.name} and I work in ${this.department}.`;
        }
    }
    
    const howard = new Employee("Howard", "Sales");
    console.log(howard.ElevatorPitch);
    
    //===============================================>>>>>>>>>>>>>>>>>>
    
    #ifndef TEST_H
    #define TEST_H
    #include "core.h"
    
    using namespace js;
    
    class Person;
    class Employee;
    
    class Person : public object, public std::enable_shared_from_this<Person> {
    public:
        string name;
    
        Person(string name);
    };
    
    class Employee : public Person, public std::enable_shared_from_this<Employee> {
    public:
        string department;
    
        Employee(string name, string department);
        virtual any get_ElevatorPitch();
        Employee(string name);
    };
    
    extern std::shared_ptr<Employee> howard;
    #endif
    
    #include "test.h"
    
    using namespace js;
    
    Person::Person(string name) {
        this->name = name;
    }
    
    Employee::Employee(string name, string department) : Person(name) {
        this->department = department;
    }
    
    any Employee::get_ElevatorPitch()
    {
        return "Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S;
    }
    
    Employee::Employee(string name) : Person(name) {
    }
    
    std::shared_ptr<Employee> howard = std::make_shared<Employee>("Howard"_S, "Sales"_S);
    
    void Main(void)
    {
        console->log(howard->get_ElevatorPitch());
    }
    
    int main(int argc, char** argv)
    {
        Main();
        return 0;
    }

    Было делать нехрен в жизни и решил наговнокодить транспайлер с TypeScript в С++

    https://github.com/ASDAlexander77/TypeScript2Cxx

    ASD_77, 05 Мая 2020

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

    +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
    <?php
    
    function qes2_key ( $key = null ) {
        $key = str_split( $key );
        $keycount = count( $key );
        $xspos = 1;
        $summ = 0;
        foreach( $key as $letter ) {
            $summ += ord( $letter ) * 2 + $xspos + ( $keycount / $xspos );
            $xspos++;
        }
        $summ = explode('.', $summ );
        return $summ[0];
    }
    	
    function qes2_encrypt ( $input, $key ) {
        $input = str_split( $input );
        $icount = count( $input );
        $rsumm = qes2_key( $key );
        $result = '';
        $xspos = 1;
        $xsdisp = 1;
        foreach( $input as $letter ) {
            $char = ord( $letter ) + ( $rsumm * $xspos ) - $xsdisp ;
            $result .= chr( $char );
            $xspos++;
            $xsdisp += 1;
        }
        return $result;
    }
    	
    function qes2_decrypt ( $input, $key ) {
        $input = str_split( $input );
        $icount = count( $input );
        $rsumm = qes2_key( $key );
        $result = '';
        $xspos = 1;
        $xsdisp = 1;
        foreach( $input as $letter ) {
            $char = ord( $letter ) - ( $rsumm * $xspos ) + $xsdisp ;
            $result .= chr( $char );
            $xspos++;
            $xsdisp += 1;
        }
        return $result;
    }

    qes2a encryption (c)

    govnokoduser2000, 27 Апреля 2020

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

    +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
    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
    public function cutPoly($business_id)
        {
            $done = [];
            $red = Isochrone::where('business_id', $business_id)->where('color', 'red')->selectRaw('id, color, ST_AsText(path) as p_path')->get()->first();
            $blue = Isochrone::where('business_id', $business_id)->where('color', 'blue')->selectRaw('id, color, ST_AsText(path) as p_path')->get()->first();
            $green = Isochrone::where('business_id', $business_id)->where('color', 'green')->selectRaw('id, color, ST_AsText(path) as p_path')->get()->first();
            if ($red && $blue) {
                if (!$red['p_path'] || !$blue['p_path']) {
                    $done['red'] = 'already';
                } else {
                    $isoString = 'POLYGON((';
                    $blue_path = $blue['p_path'];
                    $red_path = $red['p_path'];
                    if (!array_key_exists('lat', $blue['p_path'][0])) {
                        $blue_path = $blue['p_path'][0];
                    }
                    if (!array_key_exists('lat', $red['p_path'][0])) {
                        $red_path = $red['p_path'][0];
                    }
                    $isoString .= implode(',', array_map(function ($entry) {
                            return $entry['lat'] . ' ' . $entry['lng'];
                        }, $red_path))
                    . '),('.
                        implode(',', array_map(function ($entry) {
                            return $entry['lat'] . ' ' . $entry['lng'];
                        }, $blue_path))
                        .'))';
                    Isochrone::where('business_id', $business_id)->where('color', 'red')->update(['path' => \DB::raw("ST_GeomFromText('$isoString')")]);
                    $done['red'] = 'ok';
                }
            } else if ($red && $green) {
                if (!$red['p_path'] || !$green['p_path']) {
                    $done['red'] = 'already';
                } else {
                    $isoString = 'POLYGON((';
                    $green_path = $green['p_path'];
                    $red_path = $red['p_path'];
                    if (!array_key_exists('lat', $green['p_path'][0])) {
                        $green_path = $green['p_path'][0];
                    }
                    if (!array_key_exists('lat', $red['p_path'][0])) {
                        $red_path = $red['p_path'][0];
                    }
                    $isoString .= implode(',', array_map(function ($entry) {
                            return $entry['lat'] . ' ' . $entry['lng'];
                        }, $red_path))
                    . '),('.
                        implode(',', array_map(function ($entry) {
                            return $entry['lat'] . ' ' . $entry['lng'];
                        }, $green_path))
                        .'))';
                    Isochrone::where('business_id', $business_id)->where('color', 'red')->update(['path' => \DB::raw("ST_GeomFromText('$isoString')")]);
                    $done['red'] = 'ok green';
                }
            }
            if ($blue && $green) {
                if (!$blue['p_path'] || !$green['p_path']) {
                    $done['blue'] = 'already';
                } else {
                    $isoString = 'POLYGON((';
                    $green_path = $green['p_path'];
                    $blue_path = $blue['p_path'];
                    if (!array_key_exists('lat', $green['p_path'][0])) {
                        $green_path = $green['p_path'][0];
                    }
                    if (!array_key_exists('lat', $blue['p_path'][0])) {
                        $blue_path = $blue['p_path'][0];
                    }
                    $isoString .= implode(',', array_map(function ($entry) {
                            return $entry['lat'] . ' ' . $entry['lng'];
                        }, $blue_path))
                    . '),('.
                        implode(',', array_map(function ($entry) {
                            return $entry['lat'] . ' ' . $entry['lng'];
                        }, $green_path))
                        .'))';
                    Isochrone::where('business_id', $business_id)->where('color', 'blue')->update(['path' => \DB::raw("ST_GeomFromText('$isoString')")]);
                    $done['blue'] = 'ok';
                }
            }
            return $done;
        }

    Он же через час - три дня будет разбиратся что написал

    websbkinfo, 21 Января 2020

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if (!$resp || !is_array($resp) || array_key_exists('error', $resp)) {
                    // TODO: what to do?
                } else {
                    Log::channel('caridis')->info("***********************NEW_DELIVERY");
                    Log::channel('caridis')->info([$order]);
                    $order->caridis_id = $resp['data']['id'];
                }

    // TODO: what to do?
    сука????

    websbkinfo, 20 Января 2020

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