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

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

    +38

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $t='array(';
    	foreach ($info as $k=>$v){
    		$t.='"'.$k.'"=>"'.mysql_escape_string(htmlspecialchars($v)).'"';
    		if ($i<($cnt-1)) $t.=',';
    		$i++;
    	}
    	$t.=')';
    	if ($labelingid) sql ("UPDATE labeling SET info='$t' WHERE id='$labelingid'");

    Хрясь!

    brainstorm, 08 Февраля 2012

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

    +38

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Drupal.parseJson = function (data) {
      if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
        return { status: 0, data: data.length ? data : Drupal.t('Unspecified error') };
      }
      return eval('(' + data + ');');
    };

    no comments. и как я понимаю нормальные люди делают eval завернутый в try

    brainstorm, 30 Апреля 2011

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

    +38

    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
    void PduBuffer::putLen_BER(size_t len)
    {
    	if(len <= 0x00ffff)
    	{
    		if(len <= 0x007f)
    		{
    			check_room(1);
    			*position++ = (uint1)len;
    		}
    		else if(len <= 0x00ff)
    		{
    			check_room(2);
    			*position++ = 0x81;
    			*position++ = (uint1)len;
    		}
    		else // 0x00ff < len <= 0x00ffff
    		{
    			check_room(3);
    			*position++ = 0x82;
    			*position++ = (uint1)(len >> 8);
    			*position++ = (uint1)len;
    		}
    	}
    	else //len > 0x00ffff
    	{
    		if(len <= 0x00ffffff)
    		{
    			check_room(4);
    			*position++ = 0x83;
    			*position++ = (uint1)(len >> 16);
    			*position++ = (uint1)(len >> 8);
    			*position++ = (uint1)len;
    		}
    		else if(len <= 0xffffffff)
    		{
    			check_room(5);
    			*position++ = 0x84;
    			*position++ = (uint1)(len >> 24);
    			*position++ = (uint1)(len >> 16);
    			*position++ = (uint1)(len >> 8);
    			*position++ = (uint1)len;
    		}
    		else
    			THROW_INTERNAL("BER length out of range [0, 2^32)");
    	}
    	frame_start = NULL;
    }

    Добавление байтов длины TLV-объекта в буфер.

    guest, 20 Мая 2009

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

    +37.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
    <?php
    if (!$ncat) {
        $sql="select * from articles_cat where status=1  order by  `name` ASC limit 0,1";
        $res = m_qr($sql);
        if (m_rows($res)) {
            while ($row = m_arr2($res)) {
                $ncat=$row[id];
                ... 10 строк кода ...
            }
        }
    } else {
        $sql="select * from articles_cat where id='$ncat'";
        $res = m_qr($sql);
        if (m_rows($res)) {
            while ($row = m_arr2($res)) {
                $ncat=$row[id];
                ... те же 10 строк кода ...
            }
        }
    }

    Найди десять отличий...

    guest, 26 Декабря 2008

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

    +37.7

    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
    <div id="navLine">
            <? if(isset($title5)) { ?>
              <a href="index.php">Главная</a>&nbsp;&raquo; 
              <a href="index.php?page=<?=$link?>"><?=htmlspecialchars($title)?></a> &nbsp;&raquo;
              <a href="index.php?page=<?=$link2?>"><?=htmlspecialchars($title2)?></a> &nbsp;&raquo;
              <a href="index.php?page=<?=$link3?>#"><?=htmlspecialchars($title3)?></a> &nbsp;&raquo; 
              <a href="index.php?page=<?=$link4?>"><?=htmlspecialchars($title4)?></a>
            <? } elseif(isset($title4)) { ?>
              <a href="index.php">Главная</a>&nbsp;&raquo; 
              <a href="index.php?page=<?=$link?>"><?=htmlspecialchars($title)?></a>&nbsp;&raquo; 
              <a href="index.php?page=<?=$link2?>"><?=htmlspecialchars($title2)?></a>&nbsp;&raquo; 
              <a href="index.php?page=<?=$link3?>"><?=htmlspecialchars($title3)?></a>
            <? } elseif(isset($title3)) { ?>
              <a href="index.php">Главная</a>&nbsp;&raquo;
              <a href="index.php?page=<?=$link?>"><?=htmlspecialchars($title)?></a>&nbsp;&raquo; 
              <a href="index.php?page=<?=$link2?>"><?=htmlspecialchars($title2)?></a>
            <? } elseif(isset($title2)) { ?>
              <a href="index.php">Главная</a>&nbsp;&raquo; 
              <a href="index.php?page=<?=$link?>"><?=htmlspecialchars($title)?></a>
            <? } else { ?>
              <a href="index.php">Главная</a>
            <? } ?>
      </div>

    guest, 19 Декабря 2008

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

    +37.1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function check_email($address)
    {
    	$regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';
    	if (preg_match($regex, $address)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }

    Функция для проверки e-mail'а
    Очень скромный РегЕксп

    (с) n3m0

    guest, 12 Января 2009

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

    +37

    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
    int hamming(int i, int j, vector<state>& net) //returns Hamming distance between i and j nodes
    {
    	int res = 0;
    	if (net[i].nodes[0] != net[j].nodes[0])
    	{
    		res++;
    	}
    	if (net[i].nodes[1] != net[j].nodes[1])
    	{
    		res++;
    	}
    	if (net[i].nodes[2] != net[j].nodes[2])
    	{
    		res++;
    	}
    	if (net[i].nodes[3] != net[j].nodes[3])
    	{
    		res++;
    	}
    	if (net[i].nodes[4] != net[j].nodes[4])
    	{
    		res++;
    	}
    	if (net[i].nodes[5] != net[j].nodes[5])
    	{
    		res++;
    	}
    	if (net[i].nodes[6] != net[j].nodes[6])
    	{
    		res++;
    	}
    	if (net[i].nodes[7] != net[j].nodes[7])
    	{
    		res++;
    	}
    	if (net[i].nodes[8] != net[j].nodes[8])
    	{
    		res++;
    	}
    	if (net[i].nodes[9] != net[j].nodes[9])
    	{
    		res++;
    	}
    	if (net[i].nodes[10] != net[j].nodes[10])
    	{
    		res++;
    	}
    	if (net[i].nodes[11] != net[j].nodes[11])
    	{
    		res++;
    	}
    	if (net[i].nodes[12] != net[j].nodes[12])
    	{
    		res++;
    	}
    	return res;
    }

    Человеку срочно нужно узнать про существование циклов.

    galarr, 08 Марта 2014

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

    +37

    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
    long* Service::qByteToLongArray(QByteArray qba, long r)
    {
        long* larr = new long[r];
    
        char *carr;
        carr = (char*)larr;
    
        int len = r * sizeof(long);//length in bytes
    
        for(int i=0; i < len; i++)
            carr[i] = qba.at(i);
    
        return larr;
    }
    
    QByteArray Service::longToQByteArray(long **larr2, long r, long c)
    {
        QByteArray qba;// = new QByteArray();
    
        char **carr2;
        carr2 = (char**)larr2;
    
        int rlen = c * sizeof(long);//length of row in bytes
    
        for(int i=0; i < r; i++){
            qba.append(carr2[i], rlen);//add next row of matrix to the QByteArray
        }
    
        return qba;
    }

    Нашли это, только когда собрали под x64.

    Abbath, 25 Февраля 2014

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

    +37

    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
    <?php
    session_start();
    if(!empty($_SESSION['UserLogin']) or !empty($_SESSION['UserId']))
    {
      header('Location: user');
    }
    if(isset($_POST['UserName'])) 
    { 
      $UserName = $_POST['UserName']; 
      if($UserName == '') 
      {
       unset($UserName);
      } 
    }
    if(isset($_POST['UserEmail'])) 
    { 
      $UserEmail = $_POST['UserEmail']; 
      if($UserEmail == '') 
      {
       unset($UserEmail);
      } 
    } 
    if(isset($_POST['UserLogin'])) 
    { 
      $UserLogin = $_POST['UserLogin']; 
      if($UserLogin == '') 
      {
       unset($UserLogin);
      } 
    }
    if(isset($_POST['UserPassword'])) 
    { 
      $UserPassword = $_POST['UserPassword']; 
      if($UserPassword == '') 
      {
       unset($UserPassword);
      } 
    }
    if (empty($UserName) or empty($UserEmail) or empty($UserLogin) or empty($UserPassword))
    {
     header('Location: registration?error_code=1');
    }
    else
    {
      include("application/db.config.php");
      $UserLogin = stripslashes($UserLogin);
      $UserLogin = htmlspecialchars($UserLogin);
      $UserLogin = trim($UserLogin);
      $UserPassword = stripslashes($UserPassword);
      $UserPassword = htmlspecialchars($UserPassword);
      $UserPassword = trim($UserPassword);
      $SelectQuery = mysql_query("SELECT id FROM Users WHERE UserLogin ='$UserLogin'", $db);
      $QueryResult = mysql_fetch_array($SelectQuery);
      if(!empty($QueryResult['id']))
      {
        header('Location: registration?error_code=2');
      }
      else
      {
        $InsertQuery = mysql_query("INSERT INTO Users(UserName, UserSName, UserLogin, UserPassword, UserEmail, 
        UserPhone, UserStatus) VALUES('$UserName', 'Фамилия не указана', '$UserLogin', '$UserPassword', '$UserEmail', 'Телефон не указан', 'Статус не указан')");
        if($InsertQuery == true)
        {
          header("Location: action_status?reg_code=good&UserLogin=$UserLogin&UserPassword=$UserPassword");
        }
        else
        {
          header('Location: registration?error_code=3'); 
        }
      }
      
    }
    ?>

    Извержение.

    Govnisti_Diavol, 04 Декабря 2012

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

    +37

    1. 1
    2. 2
    if (isset($_GET['oneway']))
                $_SESSION['oneway'] = intval($_GET['oneway']) == 1 ? 1 : 0;

    Уточню : надо именно int, а не bool для API сервиса.
    На ум приходят 2 других более красивых способа нормализации. Может и ещё что-то есть.

    kryoz, 21 Ноября 2012

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