1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. Java / Говнокод #7950

    +81

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

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

    Комментарии (10)
  8. 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)
  9. 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)
  10. PHP / Говнокод #7947

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    $params['BannerIDS'] = null;
    $params['BannerIDS'] = $banners;
     $t_banners = null;
    unset($t_banners);

    Ну так чтоб наверняка

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

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