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

    +159

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("MyClass", "OnAfterIBlockElementUpdateHandler"));
    class MyClass
    {
        // создаем обработчик события "OnAfterIBlockElementUpdate"
        function OnAfterIBlockElementUpdateHandler(&$arFields)
        {
    //привязка элементов (формирование комплектов)
    if(CModule::IncludeModule('iblock')){
    $id=$arFields['ID'];
    $i=0;
    $komplekt=array();
    $elements=array();
    $db_props = CIBlockElement::GetProperty(24, $id, "sort", "asc", Array("CODE"=>"KOMPLEKT"));
    while($ar_props = $db_props->Fetch()){
    $i++;
    $komplekt[$i]=$ar_props["VALUE"];
    }
    for($j=1; $j<=$i; $j++){
    $elements[$komplekt[$j]][0]=$id;
    for($k=1; $k<=$i; $k++){
    if($komplekt[$j]!=$komplekt[$k]){
    $elements[$komplekt[$j]][$k]=$komplekt[$k];
    }
    }
    }
    for($z=1; $z<=$i; $z++){
    CIBlockElement::SetPropertyValueCode($komplekt[$z], "KOMPLEKT", $elements[$komplekt[$z]]);
    }
    }
    //автоматически добавляем скидку в торговом каталоге
    if(CModule::IncludeModule('iblock')&& CModule::IncludeModule('catalog')){
    $discount10=array();
    $discount15=array();
    $discount20=array();
    $dbProductDiscounts = CCatalogDiscount::GetDiscountProductsList(
    array(),
    array(),
    false,
    false,
    array()
    );
    while ($arProductDiscounts = $dbProductDiscounts->Fetch())
    {
    if($arProductDiscounts['DISCOUNT_ID']==5){
    $discount10[]=$arProductDiscounts['PRODUCT_ID'];
    }
    if($arProductDiscounts['DISCOUNT_ID']==6){
    $discount15[]=$arProductDiscounts['PRODUCT_ID'];
    }
    if($arProductDiscounts['DISCOUNT_ID']==7){
    $discount20[]=$arProductDiscounts['PRODUCT_ID'];
    }
    }
    $db_props2 = CIBlockElement::GetProperty(24, $id, "sort", "asc", Array("CODE"=>"SALE"));
    while($ar_props2 = $db_props2->Fetch()){
    
    if(!in_array($id, $discount10) && $ar_props2['VALUE']==66){
    $discount10[]=$id;
    }
    if(in_array($id, $discount10) && $ar_props2['VALUE']==""){
    $num=count($discount10);
    for($i=0; $i<$num; $i++){
    if($discount10[$i]==$id){
    unset($discount10[$i]);
    }
    }
    }
    if(!in_array($id, $discount15) && $ar_props2['VALUE']==67){
    $discount15[]=$id;
    }
    if(in_array($id, $discount15) && $ar_props2['VALUE']==""){
    $num=count($discount15);
    for($i=0; $i<$num; $i++){
    if($discount15[$i]==$id){
    unset($discount15[$i]);
    }
    }
    }
    if(!in_array($id, $discount20) && $ar_props2['VALUE']==68){
    $discount20[]=$id;
    }
    if(in_array($id, $discount20) && $ar_props2['VALUE']==""){
    $num=count($discount20);
    for($i=0; $i<$num; $i++){
    if($discount20[$i]==$id){
    unset($discount20[$i]);
    }
    }
    }
    }
    if($discount10){
    CCatalogDiscount::Update(5, array("ACTIVE"=>"Y", "PRODUCT_IDS"=>$discount10));
    }
    else{
    CCatalogDiscount::Update(5, array("ACTIVE"=>"N"));
    }
    if($discount15){
    CCatalogDiscount::Update(6, array("ACTIVE"=>"Y", "PRODUCT_IDS"=>$discount15));
    }
    else{

    Оригинальное форматирование кода сохранено. Код до 7-ой строчки - копипаста из документации. Жаль все не влезло, шедевр

    inside, 23 Сентября 2011

    Комментарии (15)
  2. Python / Говнокод #7956

    −181

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    def main():
        iface = "eth0:"
        f = open("/proc/net/dev","r")
        lines = f.readlines()
        f.close()
        x = 0
        r = '\s+'+iface+'\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+'
        while x < len(lines):
            result = re.match(r, lines[x])
            print result
            x +=1

    Мсье знает толк в регулярках

    cutwater, 23 Сентября 2011

    Комментарии (10)
  3. Java / Говнокод #7955

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    public List<OrderEntity> getOrders() {
        if (orders == null) {
            orders = new ArrayList<OrderEntity>();
        }
        return orders;
    }

    Потокобезопасность? Не, не слышал.

    roman-kashitsyn, 23 Сентября 2011

    Комментарии (63)
  4. Java / Говнокод #7954

    +85

    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
    nLen = m_aRealTexts[index].m_txtString.length();
    for (int iyhx = 0; iyhx < nLen; iyhx++) {
    	cLetter = m_aRealTexts[index].m_txtString.charAt(iyhx);
    	CTxtCharStyle pCharNode = new CTxtCharStyle(cLetter);
    	pCharNode.SetTxtFontFace(m_nFontFace);
    	m_aRealTexts[index].m_txtChars.add(pCharNode);
    }
    
    ...
    
    
    public void SetTxtFontFace(byte nType)
    {
    	String sLine, sTemp;
    	int nMark;
    	float xValue, yValue;		//笔画点位的临时坐标
    	byte bIsBigChar = 0;		//1表示ANSI字体UserArial_ansi.uft,2表示Unicode字体UserArial_unicode.uft,3表示宋体hztxt1.shx
    	m_cStroke.clear();			//清空笔画路径链表
    	
    	if(nType == 1)
    	{
    		if((int)m_cChar<0x7F || ((int)m_cChar>=0x2160&&(int)m_cChar<=0x2169))
    		{
    			//按Unicode编码顺序处理字符查找指定字库文件,避免读取不必要的字库文件
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/UserArial_ansi.uft");
    			
    			...
    			
    			fInFile.close();
    		}
    		else if((int)m_cChar>=0x007F && (int)m_cChar<0x2FFF)
    		{
    			//字符在UserArial_ansi.uft中未找到,看是否在UserArial_unicode.uft中
    			int nGetByte;
    			sLine = new String("");
    			sTemp = new String("");
    			//float xValue, yValue;
    			byte[] CharUnicode = new byte[2];			//一次读取两个字节,为一个字符
    			byte[] cBytes = new byte[2];
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/UserArial_unicode.uft");
    			while((nGetByte = fInFile.read(cBytes, 0, 2)) > 0)
    			{
    				...
    			}
    			fInFile.close();
    		}
    		else if((int)m_cChar>=0x3000)
    		{
    			//字符在西文字库UserArial.uft中未找到,是大字体,则在宋体文件hztxt1.shx中查找
    			m_cWidth = 112.0f;	//对于宋体,左下角点为坐标原点,包围盒长宽皆为127,调整量为(127-112)/2=5
    			m_cHeight = 112.0f;
    			byte nMoveDown = 5;
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/hztxt1.shx");
    			
    			...
    			
    			fInFile.close();
    		}
    		else if(bIsBigChar == 0)
    		{
    			//仍然没有找到字符字体,则按空格处理
    			m_cWidth = 12.0f;
    			m_cHeight = 16.0f;
    			m_cStroke.clear();
    		}
    	}
    	else if(nType == 2)
    	{
    		try
    		{
    			
    			InputStream fInFile = this.getClass().getResourceAsStream("/TagResources/hztxt1.shx");
    			
    			...
    			
    			fInFile.close();
    			
    		}
    		catch(IOException e)
    		{
    			//异常处理
    			e.printStackTrace();
    		}
    	}
    }

    Ещё один отжиг господ китайцев.

    Магические числа вместо энумов и закрытие файлов вне finally - это ещё полбеды. Больше всего умиляет, что при каждой отрисовке отдельно для каждой буквы файл шрифта открывается и сканируется по новой. Неудивительно, что отрисовка так тормозит. Буду переписывать это дело - загружать глифы из файла один раз и затем дёргать их из кэша.

    lucidfox, 23 Сентября 2011

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

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    $arr = array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
    
    function EtpGetEtpRoleCheckboxes($checked = array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
    {
    	$roles = EtpGetEtpRoleArray();
    	foreach($roles as $key => $role)
    	  $checkboxes .= "<input type=checkbox value='1' name='etp_roles[".$key."]' ".($checked[($key)] > 0 ? 'checked' : '')."> ".$role."<br />";
      return substr($checkboxes,0,-6);
    }

    с array_fill программист был не знаком. И так по всему скрипту. Это к первой строчке.

    В функции меня удивило задание имен <input>'ам и value="1".

    windrun, 23 Сентября 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public function record_db_tool($string) {
    	$string = (string)$string;
    	$string = intval($string);
    	return $string;
    }

    Видимо это проще, нежели скажем просто «intval(...);»

    nethak, 23 Сентября 2011

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    # Защищаемся от XSS (Для начала хоть как то...)
    public function cleener_xss($string) {
    	$string = @preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $string);
    	$string = @preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $string);
    	return $string;
    }

    nethak, 23 Сентября 2011

    Комментарии (18)
  8. Java / Говнокод #7950

    +81

    1. 1
    item.getName().equals("")==false

    Art, 23 Сентября 2011

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

    +167

    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 click() {
    if (event.button==2) {
    // Чтобы отключить левую кнопку поставьте цифру 1
    // Чтобы отключить третию кнопку поставьте цифру 3
    alert('Кнопка мышки отключена'); 
    } }
    // Здесь введите свою надпись
    function press(){
    alert('Клавиатура отключина');
    }
    // Здесь введите свою надпись
    document.onmousedown=click;
    document.onkeydown=press;
    // -->

    для полноты ощущений рекомендуется посетить источник http://www.taxi-svt.ru/

    gorky, 23 Сентября 2011

    Комментарии (21)
  10. Java / Говнокод #7948

    +78

    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
    PreparedStatement statement = createStatement();
    
    for (Value value: values) {
    
    	if (statement == null) {
    		statement = createStatement();
    	}
    
    	try {
    		if (statement.isClosed()) {
    			statement = createStatement();
    		}
    	} catch (Exception e) {
    		logger.error("...", e);
    	}
    
    	// ...
    }

    "бог любит троицу"

    user654321, 23 Сентября 2011

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