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

    +158

    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
    $email = $_POST['email'];
    $pass = $_POST['pass'];
    $name = $_POST['name'];
    $famname = $_POST['famname'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $date = date('Y-m-d [H:i:s]');
    
    if($_GET['reg'] == 'good' && $email!="" && $name!="" && $famname!="" && $pass!="" ) {
         if(!@mysql_connect('localhost', 'root', '')) {
              echo 'ѥ䩱򰠶鿠㱥񻑭塤ﲲ󯭠';
              exit();
         }
         mysql_select_db('efimov');
         $number = 0;
         $query = "select count(uid) as c from users";
         $res = mysql_query($query);
         while($row = mysql_fetch_array($res)) {
              $number = $row['c'] + 1;
         }	
         if(mysql_query("insert into users values ('$number', '$name','$famname','$email','$pass','$ip','$date')")) { 
              echo "$name, hello"; 
         }
    }
    echo '<script type="text/javascript">'.
    'alert("fuuu")'.
    '</script>';

    Регистрация пользователя ;)

    substr, 30 Августа 2011

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

    +162

    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
    /*
    	Функция для парсинга CSV файла. 
    	Автор: Федорченко Антон Александрович ([email protected], http://sites.neeweb.com/antfsite)
    	
    	Возвращает двумерный массив:
    		array(
    			array ( ... )	//Строка 1
    			array ( ... )	//Строка 2
    			...
    			array ( ... )	//Строка n
    			)
    */
    
    function parse_csv($filename, $codepage = 'windows-1251') {
        $csv_lines  = file($filename);
        $skip_char = false;
        $column = '';
        if (is_array($csv_lines)) {
            $cnt = count($csv_lines);
            for($i = 0; $i < $cnt; $i++) {
                $line = trim($csv_lines[$i]);
                $first_char = true;
                $col_num = 0;
                $length = strlen($line);
                for ($b = 0; $b < $length; $b ++) {
                    if ($skip_char != true) {
                        $process = true;
                        if ($first_char == true) {
                            if($line[$b] == '"') {
                                $terminator = '";';
                                $process = false;
                            } else {
                                $terminator = ';';
                            }
                            $first_char = false;
                        }
                        if ($line[$b] == '"') {
                            $next_char = $line[$b + 1];
                            if ($next_char == '"') {
                                $skip_char = true;
                            } elseif ($next_char == ';') {
                                if($terminator == '";') {
                                    $first_char = true;
                                    $process = false;
                                    $skip_char = true;
                                }
                            }
                        }
                        if ($process == true) {
                            if ($line[$b] == ';') {
                                if ($terminator == ';') {
                                    $first_char = true;
                                    $process = false;
                                }
                            }
                        }
                        if ($process == true) $column .= $line[$b];
                        if ($b == ($length - 1)) $first_char = true;
                        if ($first_char == true) {
                            $values[$i][$col_num] = $column;
                            $column = '';
                            $col_num ++;
                        }
                    } else {
                        $skip_char = false;
                    }
                }
            }
        }
        if (strtolower($codepage) != "utf-8") {
            foreach ($values as $lineIndex => $line) {
                foreach ($line as $cellIndex => $cell) $values[$lineIndex][$cellIndex] = iconv($codepage, "UTF-8", $cell);
            }
        }
        return $values;
    }

    Жаль, не пришло в голову запостить сразу - ОНО ещё и неотворматировано было.
    Антон Александрович - мощный дядька =)

    cybervantyz, 30 Августа 2011

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

    +165

    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
    function show_price_list() {
    		$period_1 = $period_2 = $period_3 = $period_4 = $period_5 = $period_6 = "";
    		$query = "
    				SELECT id, price, type
    				FROM price 
    				ORDER BY type, start
    			";
    		$this->registry['sql']->query($query);
    		if ($this->registry['sql']->getNumberRows()>0) {
    			foreach ($this->registry['sql']->getFetchObject() as $oRow) {
    				switch($oRow->type) {
    					case 0: $period_1 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 1: $period_2 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 2: $period_3 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 3: $period_4 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 4: $period_5 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    					case 5: $period_6 .= '<td><input type="text" name="period['.$oRow->id.']" value="'.$oRow->price.'"></td>';
    					break;
    				}
    			}
    		}
    		@$this->registry['template']->set('period_1', $period_1);
    		@$this->registry['template']->set('period_2', $period_2);
    		@$this->registry['template']->set('period_3', $period_3);
    		@$this->registry['template']->set('period_4', $period_4);
    		@$this->registry['template']->set('period_5', $period_5);
    		@$this->registry['template']->set('period_6', $period_6);
    	}

    Модель в шаблоне MVC

    vkontakte, 30 Августа 2011

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

    +161

    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
    function toggleCategory(tableId, imgId) {
    	var display = document.getElementById(tableId).style.display;
    	var classname;
    	if (display == "none") {
    		display = "block";
    		classname = "toggleClosed";
    	} else {
    		display = "none";
    		classname = "toggleOpen";
    	}
    	
    	var img = document.getElementById(imgId);
    	img.className = classname;
    	document.getElementById(tableId).style.display = display;
    }

    И все это c jQuery наборту. Латвийская соц-сеть, чё

    jQuery, 29 Августа 2011

    Комментарии (44)
  5. Python / Говнокод #7691

    −85

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    m = 1
    for i in range(100):
      for j in range(100):
        for k in range(100):
          m *= i*j*k
    #Почему m = 0?

    Ещё один перл автора 7568 и 7545

    Fai, 29 Августа 2011

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

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (strlen($_POST["NEW_PASSWORD"]) <= 0)
    					$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG_FLAG1");
    
    				if (strlen($_POST["NEW_PASSWORD"]) > 0 && strlen($_POST["NEW_PASSWORD_CONFIRM"]) <= 0)
    					$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG_FLAG1");
    
    				if (strlen($_POST["NEW_PASSWORD"]) > 0
    					&& strlen($_POST["NEW_PASSWORD_CONFIRM"]) > 0
    					&& $_POST["NEW_PASSWORD"] != $_POST["NEW_PASSWORD_CONFIRM"])
    					$arResult["ERROR"][] = GetMessage("STOF_ERROR_REG_PASS");

    Взято из Битрикса /bitrix/components/bitrix/sale.order.ajax/component.php

    Потрясающие идентификаторы мессаджей. Ну а то, что прочитать код без слома глаз нельзя отдельная песня.
    В целом там такого внутри много.

    zima, 29 Августа 2011

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

    +165

    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
    class Exception {
      public:
        Exception() { }
        Exception(const char *fmt, ...) {
          va_list  argPtr;
          va_start(argPtr, fmt);
          Str_VSPrintf(desc, sizeof(desc), fmt, argPtr);
          va_end(argPtr);
    
          throw(*this);
        }
    
        char desc[8096];
      };

    http://www.gamedev.ru/code/forum/?id=151712#m6

    >Всё работает иа рад :)

    CPPGovno, 29 Августа 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    //Я думал тоже так сделать, но иногда для параметра нужны дополнительные аргументы. Например есть operator()(float, int preciseness). С запятыми такого не сделаешь. Я это применил в своих массивах. Можно написать так:
    Array<int> arr;
    arr.Init(), 5, 7, 65, 99, 267; //Инициализирует массива числами, перечисленными через запятую
    //Кстати, сделал такое добавление в массив:
    arr.Insert(0), 5, 7, 3; //Добавляет числа вначало массива
    arr.Insert($), 888, 25, 76; //Добавляет в конец
    arr.Insert($/2), 65, 23; //В середину
    //Знак доллара сделал для схожести с языком D. Теперь не надо писать arr.length, можно писать $. Вообще, это должно быть медленнее, но компилятор оптимизирует и по тестам получается так же.
    //P. S. В govnokod.ru не заносить.

    http://www.gamedev.ru/code/forum/?id=148200&page=6#m76

    CPPGovno, 29 Августа 2011

    Комментарии (105)
  9. Си / Говнокод #7687

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    /* My favorite names for boolean values */
    #define  No	0
    #define  Yes	1
    #define  Maybe	2		/* tri-state boolean, actually */

    Исходный код юниксовой утилиты top. Файл boolean.h.

    danilissimus, 29 Августа 2011

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

    +161

    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
    class CmyBuffaer{};
    
    template< typename TYPE > CmyBuffaer& operator,( CmyBuffaer& buffer, typename TYPE arg);
    
    template<> CmyBuffaer& operator,<double>( CmyBuffaer& buffer, double arg)
    {
      printf("%f",arg);
      return buffer;
    }
    template<> CmyBuffaer& operator,<const char*>( CmyBuffaer& buffer, const char* arg)
    {
      printf("%s",arg);
      return buffer;
    }
    template<> CmyBuffaer& operator,<int>( CmyBuffaer& buffer, int arg)
    {
      printf("%i",arg);
      return buffer;
    }
    //...
    CmyBuffaer(),34.5,"+",54,"+\n";

    CPPGovno, 29 Августа 2011

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