1. PHP / Говнокод #17788

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for ($i=1;$i<=10;$i++) { 
    		  if(isset(${"imagenum".$i})) {
                         ....
                     }
    }

    И такое бывало

    sikamikanico, 15 Марта 2015

    Комментарии (3)
  2. Си / Говнокод #17787

    +136

    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
    printf("Enter item code: ");                                        //Prompts user
    scanf ("%14s", codenew1);                                           //Read user input
    len = strlen(codenew1);                                             //Read each character into variable len
    
    while (len != strspn(codenew1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
    {
        printf ("Name contains non-alphabet characters. Try again!: "); //Prompts user to try again
        scanf ("%14s", codenew1);                                       //Reads user input
        len = strlen(codenew1);                                         //Read each character into variable len
    }                                                                   //Endwhile
    strncpy(codenew, codenew1,2);                                       //Copy the first two characters from the variable codenew1
    codenew[2] = 0;                                                     //Store first two characters into variavle codenew
    
    for ( j = 0; j < num_items; j++)                                    //Loop for num_items times
    {                                                                   //Beginning of for loop
        if (strcmp(array[j].code1, codenew) == 0)                       //If codenew is found in file
        {                                                               //Beginning of if statement
            price[i] = item_qty[i] * array[j].price1;                   //Calculating the price of an item
            printf("Price : %d", price[i]);                             //Prints price
            printf("\nEnter '%s' to confirm: ", array[j].itemname1);    //Confirming the item
            scanf("%19s", item_name1[i]);
            while (strcmp(item_name1[i], array[j].itemname1 )!=0)       //Looping until both item names are the same
            {                                                           //Begin while loop
                printf("Item name is not %s ,Try Again!: ", array[j].itemname1);    //Prompt user to try again
                scanf ("%19s", item_name1[i]);                              //Reads item name into an array
                len = strlen(item_name1[i]);                                //Reads each character into variable len
            }                                                               //End while loop
            len = strlen(item_name1[i]);                                    //Read each character into variable len
            while (len != strspn(item_name1[i], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))    //While len contains non alphabetic characters
            {                                                                       //Beginning while
                printf ("Name contains non-alphabet characters. Try again!: ");     //Prompts user to try again
                scanf ("%19s", item_name1[i]);                                      //Read user input
                len = strlen(item_name1[i]);                                        //Read each character into variable len
            }                                                                       //End while
            strncpy(item_name[i], item_name1[i], 20);                               //Copy the first two characters from the variable codenew1
            item_name[i][20] = 0;                                                   //Store first 20 characters in variable item_name[i]
            total_price+= price[i];                                     //Calculate total price
            break;                                                      //Terminates loop
        }                                                               //End of if statement
        else 
            if (strcmp(array[j].code1, codenew) != 0)                       //If codenew is found in file
            {
                printf("Invalid input! Try again.");
                goto Here;
            }
    }                                                           //End of for loop

    Бесценные комментарии!
    http://stackoverflow.com/questions/29045067/error-check-files

    myaut, 14 Марта 2015

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

    +54

    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
    #include <iostream>
    using namespace std;
    
    struct Foo
    {
    	int i[0];
    };
    
    int main() {
    	// your code goes here
    	Foo f1;
    	Foo f2[5];
    	cout << sizeof(f1) << endl;
    	cout << sizeof(f2) << endl;
    	return 0;
    }

    http://rextester.com/NAA5246
    http://rextester.com/GKLFG82436
    http://rextester.com/SSZ22454
    http://rextester.com/ZEY11320

    DlangGovno, 14 Марта 2015

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

    +156

    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
    <?php
    function rus_date($time_stamp){
            $date_time = date( "Y-m-d H:i:s",time() - 3600);
            $time_s = strtotime($date_time);
            $date_segodna = date( "Ymd",time() - 3600);
            
            $date_kisa = date( "Ymd",time() - 86400);
            
            $data_one_year = date( "Ymd",time() - 31536000);
            
            $date = date("Y-n-d H:i:s", $time_stamp);
            
            $date_segodna_items = date("Ymd", $time_stamp);
            
            $raznost = strtotime($date_time) - strtotime($date);
            
            $explode_two = explode(' ',$date);
            
            $explode = explode('-',$explode_two[0]);
            
            $explode_good = explode(':',$explode_two[1]);
            
            $month = array('янв','фев','март','апр','май','июнь','июль','авг','сен','окт','нояб','дек');
            
            $num = (int)$explode[1];
            $num = $num - 1;
            $mes = $month[$num];
            
            
            if($date_segodna == $date_segodna_items){
                if($date_segodna == date( "Ymd",$time_stamp)){
                    return 'Сегодня в '.$explode_good[0].':'.$explode_good[1];
                }
                else{
                    return 'Вчера в '.$explode_good[0].':'.$explode_good[1];
                }
            }
            elseif($date_kisa == $date_segodna_items){
                return 'Вчера в '.$explode_good[0].':'.$explode_good[1];
            }
            elseif($raznost >= 31536000){
                return $explode[2].' '.$mes.' '.$explode[0].' в '.$explode_good[0].':'.$explode_good[1];
            }
            elseif($raznost <= 31536000){
                return $explode[2].' '.$mes.' в '.$explode_good[0].':'.$explode_good[1];
            }
            else{
                return $explode[2].' '.$mes.' '.$explode[0].' в '.$explode_good[0].':'.$explode_good[1];
            }
        }
    rus_date(Если временая метка ровна 0) // вернет    ( 01 янв 1970 в 04:00 )
    rus_date(Сегодняшняя метка) // вернет     ( Сегодня в 04:00 )
    rus_date(Если временая метка из прошлого и прошлому больше 24 часов но меньше 48ч) // вернет     ( Вчера в 04:00 )
    rus_date(Если больше 2 дней ) // вернет такую дату     ( 04 дек в 04:00 )

    Форматирование времени просто подставить временную метку в функцию
    Го посмеемся вместе?

    gam0ra, 13 Марта 2015

    Комментарии (17)
  5. PHP / Говнокод #17784

    +156

    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
    <?php
    
    error_reporting(E_ALL);
    require_once('project.php');
    $loader = new Twig_Loader_Filesystem('templates');
    $twig = new Twig_Environment($loader,
        array(
            'cache' => 'compilation_cache',
            'debug' => true
        )
    );
    $twig->addExtension(new Twig_Extension_Debug());
    $data='';
    $data .= summ('summa','zvit');
    $payments =getPayments();//tableM(getPayments());
    
    
    if (array_key_exists('go', $_REQUEST))
        {
        $go=$_REQUEST['go'];
        }
        else
        {
        $go='';
        }
    switch ($go) {
        case '':
            echo $twig->render('index.html',array('payments' => $payments)); ); //
            break;
        case 'addData':
            $form = showForm();
            echo "$form";
            break;
        case 'add':
            $data=$_POST['data'];
            $summa=$_POST['summa'];
            addDate($data,$summa);
            redirect('index.php');
            break;
        case 'delete':
            $id = $_GET['id'];
            delete($id);
            redirect('index.php');
            break;
    }

    vityapro, 13 Марта 2015

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

    +156

    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
    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body background="money.jpg">
    <h1 align="center">Звіт по витратах</h1>
    
    <table align="center">';
    {% for item in payments['list'] %}
        <tr><td>{{ item['data']}}</td>
            <td>{{item['summa']}}</td>
            <td>{{item['id']}}</td>
            <td><button  onclick="window.location.href=index.php/?id={{item['id']}}&go=delete"><img src="del.gif" alt="Del"style="vertical-align: middle">  </button></td></tr>
    {% endfor %}
    
    </table>
    </br></br></br>
    <table align="center"><tr><td><button   onclick="window.location.href='index.php?go=addData'">
        <img src="add.png" alt="Add" style="vertical-align: middle">Додати новий запис </button></td></tr></table>
    </body>
    </html>

    vityapro, 13 Марта 2015

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

    +130

    1. 1
    List(1,2,3) + "X" == "List(1, 2, 3)X"

    Скала

    laMer007, 13 Марта 2015

    Комментарии (45)
  8. PHP / Говнокод #17781

    +154

    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
    <?php
    // define variables and set to empty values
    $fNameErr = $lNameErr = $passErr = $pconfErr = $bDayErr = $genderErr = $ageErr = $progErr = $emailErr = $websiteErr = "";
    $fname = $lname = $password = $passconfirm = $day = $month = $year = $email = $gender = $age = $plang = $email = $website = "";
    $validate = TRUE;
    
    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
      $fname = test_input($_POST["fname"]);
      $lname = test_input($_POST["lname"]);
      $password = test_input($_POST["password"]);
      $passconfirm = test_input($_POST["passconfirm"]);
      $day = test_input($_POST["day1"]);
      $month = test_input($_POST["month1"]);
      $year = test_input($_POST["year1"]);
      $email = test_input($_POST["email"]);
      $website = test_input($_POST["website"]);
    }
     
    function test_input($data)
    {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
    }
     
    if(!$_POST)
    {
      $validate = FALSE;
    }
     
     
    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
     
     
     
      //validation of forename
      if(!empty($_POST["fname"]))
      {
        if (!preg_match("/^[a-zA-Z '-]*$/", $fname))
        {
          $fNameErr = "Only letters, - , ' and whitespaces are allowed";
          $fname = "";
          $validate = FALSE;
        }
        else
        {
          $fname = test_input($_POST["fname"]);
        }
      }
      else
      {
        $fNameErr = "Forename is required";
        $validate = FALSE;
      }
     
      //validation of surname
      if (!empty($_POST["lname"]))
      {
        if (!preg_match("/^[a-zA-Z '-]*$/", $lname))
        {
          $lNameErr = "Only letters, - , ' and whitespaces are allowed";
          $lname = "";
          $validate = FALSE;
        }
        else
        {
          $lname = test_input($_POST['lname']);
        }
      }
      else
      {
        $lNameErr = "Last name is required";
        $validate = FALSE;
      }

    Только начал кодить на пхп, интересно мнение более опытных товарищей - можно ли подобное отнести к говнокоду/ быдлокоду?) просто были уже подобные комментарии относительно этого кода

    ragie, 13 Марта 2015

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

    +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
    /**
     * Дублирование пароля в поле CONFIRM_PASSWORD.
     */
    function removeConfirmPasswordField()
    {
        $arFields  = filter_input(INPUT_POST, 'REGISTER', FILTER_DEFAULT , FILTER_REQUIRE_ARRAY);
        if($arFields)
        {
            $arKeys = array_keys($arFields);
            $arNeedKeys = array('PASSWORD', 'CONFIRM_PASSWORD');
            if(count(array_intersect($arKeys, $arNeedKeys)) === count($arNeedKeys))
            {
                $_POST['REGISTER']['CONFIRM_PASSWORD'] = $_POST['REGISTER']['PASSWORD'];
                $_REQUEST['REGISTER']['CONFIRM_PASSWORD'] = $_REQUEST['REGISTER']['PASSWORD'];
            }
        }
    }
    
    AddEventHandler('main', 'OnBeforeProlog', 'removeConfirmPasswordField');

    Вот таким способом я дублирую значение поля ввода пароля в поле для его подтверждения...

    littlefuntik, 13 Марта 2015

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

    +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
    /**
         * Checks if the same user added to more than one role
         * @private
         */
        _checkUsersConficts: function() {
            var adminUsers = this._usersGrids[TI.constants.RoleLevels.ADMIN].getStore().getRange().map(function(rec) {
                return rec.get(this.COLUMN_EMAIL);
            }, this);
    
            var editorUsers = this._usersGrids[TI.constants.RoleLevels.EDITOR].getStore().getRange().map(function(rec) {
                return rec.get(this.COLUMN_EMAIL);
            }, this);
    
            var readerUsers = this._usersGrids[TI.constants.RoleLevels.READER].getStore().getRange().map(function(rec) {
                return rec.get(this.COLUMN_EMAIL);
            }, this);
    
            //let's use dumb approach. probably later will have time for some more sophisticated algorithm ¯\_(ツ)_/¯
    
            var conflictAdminEditor = adminUsers.intersect(editorUsers);
            var conflictAdminReader = adminUsers.intersect(readerUsers);
            var conflictEditorReader = editorUsers.intersect(readerUsers);
    
            return conflictAdminEditor
                .concat(conflictAdminReader)
                .concat(conflictEditorReader)
                .unique();
        }

    Да чо там, больше ролей не добавлялось уже очень давно и не предполагается.

    bakagaijin, 13 Марта 2015

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