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

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

    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
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <locale>
    #include <windows.h>
    #include <conio.h>
    #include <cstdlib>
    
    using namespace std;
    
    struct Book
    {
    string author;
    string name;
    string year;
    };
    
    struct toolstruct
    {
    string filename;
    ifstream file_for_read;
    ofstream file_for_write;
    unsigned int struct_cnt = 0;
    HANDLE stdouthandle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    Book * shelfptr;
    };
    
    enum SSORT_TYPE
    {
    SSORT_INC = 1,
    SSORT_DEC = -1
    };
    
    void Display(toolstruct*);
    void Edit(toolstruct*);
    void Sort(toolstruct*, SSORT_TYPE);
    void Write(toolstruct*);
    
    int main()
    {
    
    setlocale(LC_ALL, "Russian");
    
    toolstruct ftool;
    char buff;
    unsigned int i = 0;
    
    do
    {
    cout<<"Введите имя каталога:"<<endl;
    getline(cin, ftool.filename);
    ftool.file_for_read.open(ftool.filename.c_str(), ios_base::in);
    }while(!ftool.file_for_read.is_open());
    
    
    while(!ftool.file_for_read.eof() && ftool.struct_cnt<20)
       {
       ftool.file_for_read>>buff;
       if(buff=='~'){ftool.struct_cnt++;}
       };
    ftool.shelfptr = new Book[ftool.struct_cnt];
    ftool.file_for_read.clear();
    ftool.file_for_read.seekg(0);
    ftool.shelfptr = new Book[ftool.struct_cnt];
    do
       {
       ftool.file_for_read>>buff;
       if(buff=='~')
          {
          getline(ftool.file_for_read, ftool.shelfptr[i].author);
          getline(ftool.file_for_read, ftool.shelfptr[i].name);
          getline(ftool.file_for_read, ftool.shelfptr[i].year);
          i++;
          }
       }while(!ftool.file_for_read.eof());
    ftool.file_for_read.close();
    Display(&ftool);
    }
    
    void Display(toolstruct* ts)
    {
    //void (*callback_ptr)(toolstruct*) = Display;
    system("cls");
    cout<<"Содержимое файла "<<ts->filename<<":"<<endl
        <<"   Автор            "<<"Название            "<<"Год публикации"<<endl;
    if(ts->struct_cnt != 0)
    {
    for(unsigned short j = 0; j<ts->struct_cnt; j++)
    {
    ts->pos.X = 0;
    ts->pos.Y = j+2;
    SetConsoleCursorPosition(ts->stdouthandle, ts->pos);
    cout<<j+1<<". ";
    if(ts->shelfptr[j].author.length()<=20)
        {cout<<ts->shelfptr[j].author;}
    else{cout<<ts->shelfptr[j].author.substr(0,16)+"...";}
    ts->pos.X = 20;
    SetConsoleCursorPosition(ts->stdouthandle, ts->pos);
    if(ts->shelfptr[j].name.length()<=20)

    Взято из паблика втентакле, где собираются студни со своими неординарными решениями лабораторных. Задача была реализовать чтение-запись структур в файл/из файла, а также сортировку по убыванию/возрастанию одного из полей.

    Fluttie, 10 Мая 2016

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $startDate = $dayCount != 7 ? ($_REQUEST["wDate"] ? $_REQUEST["wDate"] : date($dateFormat)) : ($_REQUEST["wDate"] ?
                    (date('w', strtotime($_REQUEST["wDate"])) == 1 ? $_REQUEST["wDate"] : (date('w',
                        strtotime($_REQUEST["wDate"])) ? date($dateFormat, strtotime($_REQUEST["wDate"]) -
                        (date('w', strtotime($_REQUEST["wDate"])) - 1) * 24 * 60 * 60) : date($dateFormat,
                        strtotime($_REQUEST["wDate"]) - 6 * 24 * 60 * 60))) : ($cDate == "Sun" ? date($dateFormat,
                        strtotime('Mon last week')) : date($dateFormat, strtotime('Mon this week'))));

    Хз что by ©senior shaurma developer

    pahhan, 06 Мая 2016

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

    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
    <?php
    /** тестовая отправка xmlrpc-запроса */
    
    $productId = 665;
    $msisdn = '79210000001';
    $user = 'myuser';
    $pass = 'mypassword';
    $url='http://localhost/';
    
    $request = xmlrpc_encode_request('startService', ['phone' => $msisdn, 'productId' => $productId]);
    
    $header[] = "Content-type: text/xml";
    $header[] = "Content-length: ".strlen($request) . "\r\n";
    $header[] = $request;
    
    echo "Запрос:\r\n";
    print_r($request);
    
    if ($curl = curl_init()) {
    	curl_setopt($curl, CURLOPT_URL, $url);
    	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    	curl_setopt($curl, CURLOPT_HEADER, true);
    	curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    	curl_setopt($curl, CURLOPT_USERPWD, $user . ':' . $pass);
    
    	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    	curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    	curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST' );
    
    	$out = curl_exec($curl);
    }
    $response = xmlrpc_decode($out);

    А мы-то весь день гадем, почему тело запроса на сервер не поступает.

    jonnywalker, 27 Апреля 2016

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

    +1

    1. 1
    https://habrahabr.ru/company/tm/blog/279759/

    На Швабре можно постить гоатсе.

    Vasiliy, 21 Марта 2016

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

    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
    float massiv[2];
    	massiv[0] = 1.05;
    	massiv[1] = 2;
    	float summa;
    	for(int i = 0; i < 2; i++)
    	{
    		summa = summa + massiv[i];
    	}
    	ShowMessage(summa);
    
    
    VS
    
    
    	float massiv[2];
    	massiv[0] = 1.05;
    	massiv[1] = 2;
    	float summa = massiv[0] + massiv[1];
    	ShowMessage(summa);

    Бывают же люди...

    не люблю вообще наговаривать на людей, но тут уж п..здец полный.
    не знаю - не сдержался, а может сегодня звезды не так стали.
    дали мне на сопровождение код, но это еще полбеды...
    вообщем суть вопроса - человеку дали (по всей видимости)
    задачу найти сумму двух чисел. вот что он написал: (см. в коде)

    Это вместо: (см. ниже в коде под надписью VERSUS)

    И так все 100 000 строк кода.
    Как говорится программист от Б-г-а. Под Б-г я имею ввиду Бориса Гребенщикова.
    (Не знаю как кто, а я лично не перевариваю его музыку)

    P.S. Автор сего произведения сейчас работает помощником директора. Чего-то я
    наверное не понимаю в этой жизни.

    P.P.S. Все совпадения с реальными людьми и событиями случайны. Говорю потому
    что страшно - еще уволят.

    expdev, 28 Января 2016

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

    +6

    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
    switch("пряные сухарики"){
    case ".gif":{
    	header('content-type: image/gif');
    	break;
    }
    case ".jpg":{
    	header('content-type: image/jpeg');
    	break;
    }
    case ".jpeg":{
    header('content-type: image/jpeg');
    break;
    }
    case ".bmp":{
    header('content-type: image/bmp');
    break;
    }
    case ".png":{
    header('content-type: image/png');
    break;
    }
    case ".ogg":{
    header('content-type: video/ogg');
    break;
    }
    case ".mp4":{
    header('content-type: video/mp4');
    break;
    }
    }

    d_fomenok, 29 Декабря 2015

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

    +3

    1. 1
    2. 2
    3. 3
    try{
          throw Exception();
    }

    Мне в сонном бреду пришла мысль, а нахера обязательный catch?
    finally везде необязательно.
    try{ //исключения не пройдут
    }
    //вполне по крестоблядски

    3.14159265, 15 Декабря 2015

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

    −4

    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
    try {
        f();
    }
    catch(...) {
        std::cout << "f() throw\n";
    }
    try {
        g();
    }
    catch(...) {
        std::cout << "g() throw\n";
    }
    try {
        k();
    }
    catch(...) {
        std::cout << "k() throw\n";
    }
    // etc ...

    absolut, 11 Декабря 2015

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

    +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
    public class Logger
    	{
    		public static string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.log");
    
    		public static void Write(string message)
    		{
    			using (var sw = File.AppendText(filePath))
    			{
    				sw.WriteLine(DateTime.Now);
    				sw.WriteLine(message);
    				sw.WriteLine();
    				sw.Flush();
    			}
    		}
    
    		public static void Write(Exception exception)
    		{
    			using (var sw = File.AppendText(filePath))
    			{
    				sw.WriteLine(DateTime.Now);
    				sw.WriteLine("ERROR:");
    				sw.WriteLine(exception.Message);
    				sw.WriteLine(exception.StackTrace);
    				sw.WriteLine();
    				sw.Flush();
    			}
    		}
    	}

    Нафига готовые решения? Вот - образец велосипедостроения! (И, тссс! Не вздумайте использовать его в многопоточной среде ;) А именно там он и используется по факту :) )

    PS угадайте какой фортель выкинет сеё чудо при race condition

    leon_mz, 18 Ноября 2015

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

    +14

    1. 1
    2. 2
    3. 3
    public static bool Convert(string fileName, string Namefile) {
    ...
    }

    нет, ну не дебил?

    Lokich, 06 Ноября 2015

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