1. C++ / Говнокод #14270

    +9

    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
    /** фрагмент 0 */ 
    buff[symbols]=0;
    printf ("%s\n",buff);	 
    
    if (strcmp (buff,"Yes!") != 0)
        exit (1);
    
    strcpy (buff,"");	  
    sprintf (buff,"%s","File_size?");
    printf ("%s\n",buff);
    
    /** фрагмент 1 */ 
    Par2 = 0;
    		  if (number_packet < 10)
    			  Par2 = 1;
    		  else
    			  if (number_packet < 100)
    			    Par2 = 2;
    			  else
    				  if (number_packet < 1000)
    			        Par2 = 3;
    				  else
    					  if (number_packet < 10000)
    			             Par2 = 4;
    					  else
    						  if (number_packet < 100000)
    			                 Par2 = 5;
    						  else
    							  if (number_packet < 1000000)
    			                     Par2 = 6;
    							  else
    								  if (number_packet < 10000000)
    			                        Par2 = 7;
    		  Par2++;

    2 фрагмента лабораторной работы

    dannikonov, 24 Декабря 2013

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

    +15

    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
    static std::vector<std::string> listSubstring(std::string stringData, std::string separator)
    {
    	std::vector<std::string> result;
    	std::size_t found = stringData.find(separator);
    	if (found==std::string::npos)
    	{
    		result.push_back(stringData);
    		return result;
    	}
    	result.push_back(stringData.substr(0,found));
    	std::vector<std::string> ko=listSubstring(found+separator.length(),separator);
    	for (std::vector<std::string>::iterator i = ko.begin(); i != ko.end(); ++i)
    		{result.push_back(*i);}
    	return result;
    
    }

    laMer007, 24 Декабря 2013

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

    +159

    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
    var a, vr, curq;
    function bgbuild(num1){document.write("<head><title>Річне тематичне оцінювання з астрономії</title><meta http-equiv=\"Content-Type\" content=\"text/html\" charset=unicode\"></head><body bgcolor=#8080ff><img src='library/bgrnd.jpg' height=100% width=100% style='z-index:",num1,";position:absolute;top:0;left:0;right:0;bottom:0'>")};
    function fio(){document.write("<form><input type=\"text\" name=\"pib\" style='z-index:4;position:relative;top:0;left:0;font:normal 15px Lucida Console;'>")};
    function capt(qustn){document.write("<div style='z-index:3;text-align:justify;position:absolute;top:30;left:30;font:normal 30px System;color:black'>",qustn,"</div>")};
    function fld(){document.write("<textarea name=answ rows=30 cols=90 style='z-index:4;position:absolute;top:160;left:30;font:normal 15px Lucida Console;'></textarea>")};
    function kg(qst){document.write("<input style=\"z-index:6;position:absolute;top:0;right:0\" type=\"button\" value=\"Наступне питання\" onclick=\"return q",qst,"()\">")};
    function registr(){document.write("<input type=\"button\" onclick=\"return crfol()\" value=\"Реєстрація\"></form>")};
    function cnctscr(){document.write("<script lang=\"Javascript\" src=\"library/cobuild.js\"></script>");};
    function svr(vr){var fs, b;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    b = fs.OpenTextFile("C:\\variant.tmp", 2, true, true);
    b.write(vr);
    b.close();
    };
    function gvr(){var fs, b;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    b = fs.OpenTextFile("C:\\variant.tmp", 1, true, true);
    vr = b.readall();
    b.close();
    };
    function start(){
    bgbuild(0);
    document.write("<div style='z-index:1;position:absolute;top:30;left:30;right:30;font:normal 25px System;color:black;text-align:justify'>Ви маєте можливість пройти річне тематичне оцінювання з астрономії. Буде запропоновано 6 варіантів по 15 питань різної складності кожний. Ваші відповіді перевіряє вчитель, але приблизно оцінити себе Ви можете самі, ознайомившись після проходження опитування із правильною відповіддю і оцінивши вірність своєї відповіді. Не намагайтесь втрутитись у хід опитування і підкорегувати свої відповіді, адже це може скінчитися порушенням ходу програми, яке призведе до її неповного проходження, а в результаті - нижчої оцінки. Файл із Вашою відповіддю збережеться у спеціальному місці.<br>Для початку введіть своє прізвище та ім'я (не використовуйте ніяких спецсимволів!):<br>");
    fio();
    registr();
    document.write("<br>Оберіть варіант:<br><table><tr><td><form><input type='button' value='1' onclick='svr(1);return q1()'></td><td><input type='button' onclick='svr(2);return q1()' value='2'></td><td><input type='button' onclick='svr(3);return q1()' value='3'></td><td><input type='button' onclick='svr(4);return q1()' value='4'></td><td><input type='button' onclick='svr(5);return q1()' value='5'></td><td><input type='button' onclick='svr(6);return q1()' value='6'></td></form></div>");};
    function crfol(){var fs, n, b;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    n = document.all.pib.value;
    if(n==""){er()};
    nm = "answ/"+n+".dat";
    a = fs.OpenTextFile(nm, 2, true, true);
    a.writeline("Це не підробка, це справжній файл із відповідями!\rУчень: "+n+"\rВаріант: ");
    a.close();
    b = fs.OpenTextFile("C:\\username.tmp", 2, true, true);
    b.write(n);
    b.close();
    }
    function crf(dt){var fs, n, b, nm;
    fs = new ActiveXObject("Scripting.FileSystemObject");
    b = fs.OpenTextFile("C:\\username.tmp", 1, true, true);
    n = b.readall();
    b.close();
    nm = "answ/"+n+".dat";
    a = fs.OpenTextFile(nm, 8, true, true);
    a.writeline(dt);
    a.close();
    }
    function er(){alert("Ану не балуйся! Думаєш, ти розумніше за комп'ютер?!");window.close();}
    function q1(){
    try{
    gvr();
    crf(vr);
    bgbuild(0);
    cnctscr();
    };catch(e){er()};
    if (vr=="1"){curq = "1.1.1. Що вивчає астрономія?"};
    if (vr=="2"){curq = "1.1.2. Що означає слово \"астрономія\"?"};
    if (vr=="3"){curq = "1.1.9. Що таке астрологія?"};
    if (vr=="4"){curq = "1.1.12. Назвіть прізвища відомих вам астрономів минулих часів."};
    if (vr=="5"){curq = "1.1.13. Назвіть небесні тіла, що утворюють Сонячну систему."};
    if (vr=="6"){curq = "2.1.1. Що означає слово \"космос\"?"};
    capt(curq);
    crf(curq);
    fld();
    
    kg(2);
    }
    
    start();

    Короче, первый мой более-менее крупный высер на JS. Писал HTA-приложение для школы (тестирование по астрономии). Интернета у меня тогда ещё не было, компилятор чего-либо нормального взять, соответственно, было негде, поэтому писал на чём можно. JS (точнее, JScript) изучал по справке MSE7 (недо-IDE, которая поставляется с M$Office). Результат немного предсказуем, многие части кода - модифицированные примеры тамошние. Вбрасываю основную либу (там ещё дополнительная, с вхардкоженными вопросами и несколькими функциями, и HTA-оболочка). Остальное будет по просьбам:3

    //Я в этот код даже не заглядываю, боюсь суицидальных приступов от осознания того, что я это написал *HEADBANG*

    MiniRoboDancer, 24 Декабря 2013

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

    +11

    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
    /// Represents the model of a Writer document.
    class SW_DLLPUBLIC SwDoc :
        public IInterface,
        public IDocumentSettingAccess,
        public IDocumentDeviceAccess,
        public IDocumentRedlineAccess,
        public IDocumentLinksAdministration,
        public IDocumentFieldsAccess,
        public IDocumentContentOperations,
        public IDocumentStylePoolAccess,
        public IDocumentLineNumberAccess,
        public IDocumentStatistics,
        public IDocumentState,
        public IDocumentDrawModelAccess,
        public IDocumentLayoutAccess,
        public IDocumentTimerAccess,
        public IDocumentChartDataProviderAccess,
        public IDocumentListItems,
        public IDocumentOutlineNodes,
        public IDocumentListsAccess,
        public IDocumentExternalData
    {
    ...

    Вот это монстрище!

    http://opengrok.libreoffice.org/xref/core/sw/inc/doc.hxx

    Sauron, 23 Декабря 2013

    Комментарии (215)
  5. Си / Говнокод #14266

    +136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int file_exist (char *filename)
    {
        char s[200];
        sprintf(s, "test -e %s", filename);
        if (system(s) == 0){
            return 1;
        }else{
            return 0;
        }
    }

    http://stackoverflow.com/questions/3828192/checking-if-a-directory-exists-in-unix-system-call

    rat4, 23 Декабря 2013

    Комментарии (295)
  6. ActionScript / Говнокод #14265

    −118

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static function cancel (tween : T) : void {
        delete _dict[tween];
    }
    
    public function cancel () : void {
        delete _dict[this];
    }

    Пыщ пыщ, я развлекаюсь

    kyzi007, 23 Декабря 2013

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

    +155

    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
    //users.php
    
    public function search_()
        {
    // --- Поиск по пользователям
          $sql_search = mysql_query($this->sql);
          $folder = $this->folder;
          if (mysql_num_rows($sql_search)>0)
          {
            $row_search = mysql_fetch_assoc($sql_search);
            do
            {
              $user_id = $row_search["id"];
              $sql = mysql_query("SELECT SOCIAL_fotos.picture_mini FROM SOCIAL_fotos WHERE fotoalbum_id = '0' and user_id = '$user_id' LIMIT 1");
              if (mysql_num_rows($sql)>0)
              {
                $row_sql = mysql_fetch_assoc($sql);
                $picture_mini = $row_sql["picture_mini"];
              }
              else
                $picture_mini = "picture/empty_mini.jpg";
              printf("<p><a href=\"%s\" target=\"_blank\"><img src=\"$folder/%s\">%s</a><br>%s", $row_search["alias"], $picture_mini, $row_search["lfm"], $row_search["city"]);
            }
            while($row_search = mysql_fetch_assoc($sql_search));
          }
        }
    //funct_prover.php
    
    
    function prover($con)
      {
        $element = array("'");
        $con = str_replace($element, ";appost;", $con);
        return htmlspecialchars(trim($con));
      }
    
    
    //conf_connect.php
    
    $server_con = 'localhost'; // Адрес сервера mysql
      $username_con = ''; // Имя пользователя
      $password_con = ''; // Пароль
      $dbname_con = 'socialdb';
    
      $url = $_SERVER["HTTP_HOST"];
      $site1 = 'panzins.ru';
      $site2 = 'www.panzins.ru';
      if ($url != $site1 and $url != 'localhost' and $url != $site2)
      exit();
      $url_path = $_SERVER["REQUEST_URI"];
      if ($url == $site2)
      {
        header("Location: http://panzins.ru$url_path");
        exit();
      }
    
      mysql_connect($server_con, $username_con, $password_con) or die("No connection");
      mysql_query('SET NAMES utf8') or die("Set names error");
      mysql_select_db($dbname_con) or die("No database");
      header('Content-Type:text/html; charset=utf-8');
      $table_log = "SOCIAL_log";
      $table_alias = "SOCIAL_alias";
      $table_user = "SOCIAL_user";
    
    // И еще много няшек

    MVC, PDO, Framework, для лохов ибо там избыточный код. Написать свою соц сеть за 30 дней легко. Знакомьтесь, Сергей Панзин, скромный адепт Жопова. http://rutracker.org/forum/viewtopic.php?t=4619804

    Сам шидевр. http://panzins.ru/

    Keeper, 23 Декабря 2013

    Комментарии (53)
  8. Си / Говнокод #14263

    +135

    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
    Структура для хранения данных:
    typedef struct rs_script_t {
        int status; // on/off
        int next_stage;
        int next_time;
    } rs_script_t;
    
    Макросы:
    
    #define SEQ(scr1,t)    \
        const int scr_zero = __COUNTER__;   \
        rs_script_t *scr = scr1; \
        if ( (scr->status) && (t > scr->next_time) ) {  \
            switch(scr->next_stage) {    \
        
    #define END_SEQ } };             
    
    
    #define SEQ_FIRST \
            case 0: \
                    scr->next_stage = scr_zero;
                    
    
    #define SEQ_DT(dt) \
                    scr->next_stage = __COUNTER__ + 1;   \
                    scr->next_time += dt;  \
                    break;  \
                case __COUNTER__:   \
                
    #define SEQ_DT_TAGGED(dt,tag) \
                    scr->next_stage = __COUNTER__ + 1; \
                    scr->next_time += dt;    \
                    break; \
                case __COUNTER__:    \
                case (100000+tag):   \
    
    #define SEQ_LAST_DEFAULT    \
                    scr->status = 0; \
                    break;  \
                    \
                default:    \
                    DEBUG10f(":: ERROR, unknown stage position: %d \n", scr->next_stage);    \
                    break;
    
    #define SEQ_GOTO(dt,tag) \
                    scr->next_stage = 100000+tag; \
                    scr->next_time += dt; \
                    break;
                    
    #define SEQ_GOTO_INSTANT(tag) \
                    scr->next_stage = 100000+tag; \
                    break;
    
    Пользоваться примерно так:
    void process() { // вызывать каждый кадр
    
        SEQ(&scrtest, rs_app.app_time)
                
            SEQ_FIRST
                printf("Ноль\n");
                
            SEQ_DT(1000)
                printf("Один\n");
                
            SEQ_DT(1000)
                printf("Два\n");
                
            SEQ_DT_TAGGED(1000, 555)
                printf("Три (метка №555) \n");
                
            SEQ_DT(1000)
                printf("Четыре\n");
                
            SEQ_DT(1000)
                printf("Пять\n");
                
            SEQ_DT(1000)
                printf("Шесть, повторяем с метки №555, если нажат Шифт\n");
                if (rs_keyboard_is_key_down(RS_KEY_SHIFT_L)) {
                    SEQ_GOTO(1000, 555);
                };
                printf("Завершаем. \n");
                
            SEQ_LAST_DEFAULT     
            
        END_SEQ;
    
    };

    Страдания по yield

    TarasB, 23 Декабря 2013

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

    +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
    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
    #include <iostream>
    #include <conio.h>
    #include <clocale>
    using namespace std;
    int files; int disc_D(); int disc_E(); int disc_C();
    int resursefunction()
    {char s;
      cout << "Выберите диск" << endl;
      cout <<"1-D:\\" << endl;
      cout <<"2-C:\\" << endl;
      cout <<"3-E:\\" << endl;
      cout <<"0 - рабочий стол" << endl;
      cin >> s;
      if(s == '1') return disc_D();
      if(s == '2') return disc_C();
      if(s == '3') return disc_E();
      if(s == '0') return main();
      _getch();}
    int main()
    { char vibor;
      setlocale( LC_ALL, "Russian" );
      cout << "\t\t\t\tРабочий стол" << endl;
      cout << "\n\n";
      cout << "1-Управление ресурсами" << endl;
      cout << "2-Программы" << endl;
      cout << "3-Игры" << endl;
      cout << "4-Выход из системы" << endl;
      cin >> vibor;
      if(vibor == '1') resursefunction();
      _getch();
      return main();}
    int disc_D()
    { int res, a;
      char vv;
      cout << "D:\\" << endl;
      cout << "На диске" << endl;
      cout << "5 - папок" << endl;
      cout << files << " - файлов" << endl;
      cout << "1 - создать файл" << endl;
      cout << "2 - удалить файл" << endl;
      cout << "0 - назад" << endl;
      cin >> vv;
      if(vv == '1')
      {cout << "Введите сколько создать файлов"; cin >> a; res = files + a;
       res = files + a;}
      if(vv == '2')
      {cout << "Введите сколько удалить файлов"; cin >> a; res = files - a;
       res = files - a;}
      if(vv == '0') return resursefunction();
      files = res;
      return disc_D();}
    int disc_E()
    {
      int res, a;
      char vv;
      cout << "E:\\" << endl;
      cout << "На диске" << endl;
      cout << "7 - папок" << endl;
      cout << files << " - файлов" << endl;
      cout << "1 - создать файл" << endl;
      cout << "2 - удалить файл" << endl;
      cout << "0 - назад" << endl;
      cin >> vv;
      if(vv = '1')
      {cout << "Введите сколько создать файлов"; cin >> a; res = files + a;
       res = files + a;}
      if(vv == '2')
      {cout << "Введите сколько удалить файлов"; cin >> a; res = files - a;
       res = files - a;}
      if(vv == '0') return resursefunction();
      files = res;
      return disc_E();}
    int disc_C()
    {int res, a;
      char vv;
      cout << "C:\\" << endl;
      cout << "На диске" << endl;
      cout << "5 - папок" << endl;
      cout << files << " - файлов" << endl;
      cout << "1 - создать файл" << endl;
      cout << "2 - удалить файл" << endl;
      cout << "0 - назад" << endl;
      cin >> vv;
      if(vv = '1')
      {cout << "Введите сколько создать файлов"; cin >> a; res = files + a;
       res = files + a;}
      if(vv == '2')
      { cout << "Введите сколько удалить файлов"; cin >> a; res = files - a;
       res = files - a; }
      if(vv == '0') return resursefunction();
      files = res;
      return disc_C();}

    Еще нашел на форумах. К сожалению форматирование пришлось убить, иначе оно не помещалось целиком

    pelmenka, 23 Декабря 2013

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

    +13

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if (axis[0] == vector[0] && axis[1] == vector[1] && axis[2] == vector[2])
       {
          this->anglex = 0.0f;
       }
       else if (vector[1] >= 0.0f)
       {
          this->anglex = 360.0f*(GLfloat)acos(VectorMathf::dotProductf(axis, vector))/(2.0f*PIf);
       }
       else
       {
          this->anglex = -360.0f*(GLfloat)acos(VectorMathf::dotProductf(axis, vector))/(2.0f*PIf);
       }

    Часть либы ES3D (http://sourceforge.net/projects/es3d/).
    Кто не понял в чем прикол - все переменные имеют тип float.

    Pythoner, 23 Декабря 2013

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