1. Python / Говнокод #7701

    −91

    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
    def delta( listToDelta ):
      result = []
      lastItem = listToDelta[0]
      for i, item in enumerate(listToDelta):
        if i == 0:
          result.append(item)
        else:
          result.append(item-lastItem)
        lastItem = item
      return result
    
    l = [2, 4, 6, 9, 7]
    print(l)
    l = delta(l)
    print(l)

    Всеми любимый Дениска (автор некоторых прошлых ГК на питоне) пошёл на поправку и написал не такое вонючее говно.
    Комментировать код до сих пор отказывается, но зато стал выбирать имена для переменных получше.

    Fai, 30 Августа 2011

    Комментарии (31)
  2. JavaScript / Говнокод #7700

    +169

    1. 1
    if (!document.getElementById) return;

    Официальный сайт города Сочи

    Connor, 30 Августа 2011

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

    +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
    public function get($module, $fields, $options=null) {
            $results = $this->get_with_related($module, array($module => $fields), $options);
            $records = array();
            if ($records) {
                foreach ($results['entry_list'] as $entry) {
                    $record = array();
                    foreach ($entry['name_value_list'] as $field) {
                        $record[$field['name']] = $field['value'];
                    }
                    $records[] = $record;
                }
            }
            return $records;
        }

    SugarCRM REST API Class https://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class/blob/master/sugar_rest.php

    stark, 30 Августа 2011

    Комментарии (5)
  4. Pascal / Говнокод #7698

    +105

    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
    procedure TForm2.FormCreate(Sender: TObject);
    begin
      SpeedButton1.Left := Form2.ClientWidth div 2 - SpeedButton1.Width;
      SpeedButton1.Top := Form2.ClientHeight div 2 - SpeedButton1.Height;
     
      SpeedButton2.Left := Form2.ClientWidth div 2;
      SpeedButton2.Top := Form2.ClientHeight div 2 - SpeedButton2.Height;
     
      SpeedButton3.Left := Form2.ClientWidth div 2 - SpeedButton3.Width;
      SpeedButton3.Top := Form2.ClientHeight div 2;
     
      SpeedButton4.Left := Form2.ClientWidth div 2;
      SpeedButton4.Top := Form2.ClientHeight div 2;
    end;

    Fai, 30 Августа 2011

    Комментарии (13)
  5. JavaScript / Говнокод #7697

    +168

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    var command = 'var p = new Object();';
             command +='p.adId = "' + params.adId + '";';
             command +='p.campaignId = "' + params.campaignId + '";';
             command +='p.parentPositionId="' + params.parentPositionId + '";';
             command +='p.childPositionIds = "' + params.childPositionIds + '";';
             command +='oneAdSkyscraperLoaded(p);';
      setTimeout(command, 0);

    Латвийский eval

    jQuery, 30 Августа 2011

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

    +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
    /**
     * форматирование даты - преобразует дату в формат ДД-ММ-ГГГГ
     *
     * @param unknown_type $inDate - дата
     * @return unknown
     */
    public static function getDateFormatted($inDate, $forView = false, $inTime = '') {
    	//2011-05-03 20:27:26
    	
    	$a_tmp = explode(' ', $inDate);
    	if ($forView) {
    		$time = substr($a_tmp[1], 0, 5);
    		if ($a_tmp[0] == date('Y-m-d')) {
    			if ($time == '') {
    				$time = substr($inTime, 11, 5);
    				if ($time == '') {
    					$time = $inTime;
    				}
    			}
    			if ($time != '') {
    				return 'Сегодня, ' . $time;
    			}
    		}
    
    		$a_tmp = explode('-', $a_tmp[0]);
    
    		return $a_tmp[2] . '-' . $a_tmp[1] . '-' . $a_tmp[0];
    	}
    
    	$inDate = substr($inDate, 0 , 10);
    	$inDate = str_replace(' ', '', $inDate);
    	$inDate = str_replace('.', '-', $inDate);
    
    	$a_tmp = explode('-', $inDate);
    	if (strlen($a_tmp[0]) == 4) {
    		$inDate = str_pad($a_tmp[2], 2, '0', STR_PAD_LEFT) . '-' . $a_tmp[1] . '-' . $a_tmp[0];
    	}
    	return $inDate;
    }

    Sers, 30 Августа 2011

    Комментарии (6)
  7. 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)
  8. 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)
  9. 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)
  10. 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)