1. Си / Говнокод #2128

    +139.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (errno==EINTR) while (errno==EINTR)
         {
                fseek(fr,loffset,SEEK_SET);
                fgets(line_buffer,len,fr);
    }

    sacc - система биллинга для squid

    Одной проверки на ошибку - видимо, недостаточно

    fiss, 11 Ноября 2009

    Комментарии (13)
  2. C# / Говнокод #2127

    +131.2

    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
    public static DataTable DeserilazeDataTable(string schema, string data)
            {
                DataTable tbl = new DataTable();
                if (!string.IsNullOrEmpty(schema))
                    using (Stream stream = new MemoryStream())
                    {
                        byte[] bufer = GetBytes(schema);
    
                        stream.Write(bufer, 0, bufer.Length);
                        stream.Position = 0;
                        tbl.ReadXmlSchema(stream);
                    }
    
                if (!string.IsNullOrEmpty(data))
                    using (Stream stream = new MemoryStream())
                    {
                        byte[] bufer = GetBytes(data);
    
                        stream.Write(bufer, 0, bufer.Length);
                        stream.Position = 0;
                        tbl.ReadXml(stream);
                    }
    
                return tbl;
            }
    
     public static byte[] GetBytes(string str)
            {
                if (string.IsNullOrEmpty(str))
                    return new byte[0];
    
                char[] ch = str.ToCharArray();
                byte[] bufer = new byte[ch.Length];
                for (int i = 0; i < ch.Length; i++)
                    bufer[i] = (byte)ch[i];
    
                return bufer;
            }
    //также имеются методы для сериализации, работающие также
    public static string SerilazeDataTable(DataTable table)
    public static string SerilazeDataTableShame(DataTable table)
    public static string GetString(byte[] bufer)

    Вот такой десериализатор таблицы в Xml нашел в проэкте.

    sven47, 11 Ноября 2009

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

    +74.6

    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
    Object[] obj = nci.getFromTNVEDALL(id);
    if (obj[0] != null && obj[1] != null && !obj[0].equals(new BigDecimal(0))) {
    	if (obj[2] != null && obj[3] != null && !obj[2].equals(new BigDecimal(0))) {
    		if (obj[4] != null && obj[6] != null && !obj[4].equals(new BigDecimal(0))) {
    			// Проверка1
    			Object[] resProverka = proverka1(obj, numGoods, numRow, paymentDate, dutyRow, АКЦИЗ);
    			str = (String) resProverka[0];
    			date = (Date) resProverka[1];
    		} else {
    			// Проверка2
    			Object[] resProverka = proverka2(obj, numGoods, numRow, paymentDate, dutyRow, АКЦИЗ);
    			str = (String) resProverka[0];
    			date = (Date) resProverka[1];
    		}
    	} else {
    		// Проверка3
    		Object[] resProverka = proverka3(obj, numGoods, numRow, paymentDate, dutyRow, АКЦИЗ);
    		str = (String) resProverka[0];
    		date = (Date) resProverka[1];
    	}
    	if (obj[8] != null) {
    		if (gtdFields.getPreferencii(numGoods) == null ||
    				!((String) obj[8]).toUpperCase().equals(gtdFields.getPreferencii(numGoods).substring(2, 3))) {
    			str =
    					"|Для товара №" + (numGoods + 1) + " при применении ставки акциза " + obj[0] +
    							nci.getEdIzm((String) obj[1]) +
    							" в третьей позиции гр.36 ГТД необходимо указать преференцию '" + obj[8] + "'\n";
    		}
    	}
    	gtdFields.setCurrencyUseDate(numGoods, date, numRow);
    }

    ctepx, 11 Ноября 2009

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

    +86.5

    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
    /**
     * константы платежей
     *
     * @author eav
     */
    public interface PaymentsConstants {
    	// какие-то цифры %)
    	static final String _25 = "25";
    	static final String _21 = "21";
    	static final String _27 = "27";
    	static final String _26 = "26";
    	static final String _93 = "93";
    	static final String _78 = "78";
    	static final String _80 = "80";
    	static final String _98 = "98";
    	static final String _81 = "81";
    	static final String _13 = "13";
    	static final String _12 = "12";
    	static final String _95 = "95";
    	static final String _20 = "20";
    	static final String _23 = "23";
    	static final String _53 = "53";
    	static final String _112 = "112";
    
    	static final String _270900 = "270900";
    	static final String _2710 = "2710";
    	static final String _2711210000 = "2711210000";
    	static final String _4907001010 = "4907001010";
    	static final String _4820409000 = "4820409000";
    	static final String _4907009000 = "4907009000";
    
    	// страны
    	static final String TM = "TM";
    	static final String AM = "AM";
    	static final String TJ = "TJ";
    	static final String UZ = "UZ";
    	static final String KG = "KG";
    	static final String AZ = "AZ";
    	static final String GE = "GE";
    	static final String UA = "UA";
    	static final String MD = "MD";
    	static final String BY = "BY";
    	static final String KZ = "KZ";
    
    	static final String ВРЕМ = "Врем";
    	static final String КОМП = "Комп";
    	static final String ДЕМП = "Демп";
    	static final String АКЦИЗ = "Акциз";
    
    	static final String УН = "УН";
    	static final String ИП = "ИП";
    
    	// импорт/экспорт
    	static final String ЭК = "ЭК";
    	static final String ИМ = "ИМ";
    }

    Тихий ужас...

    ctepx, 11 Ноября 2009

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

    +164.6

    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
    function Parser($html,$safelevel=1,$censored=false,$typo=true,$crop=0)
    {
    /* v2
        # 17/10/01
        
        html        обезапасиваемая строка
        safelevel   указывает разрешенные теги:       0 = все разрешены
                                                      1 = B,I,U,FONT,P,DIV,CENTER,IMG,A,SPAN,TABLE,TD,TR,INPUT,FORM,TEXTAREA,SCRIPT
                                                      2 = B,I,U,FONT,P,DIV,CENTER,IMG,A,SPAN,TABLE,TD,TR
                                                      3 = B,I,U,FONT,P,DIV,CENTER,IMG,A,SPAN
                                                      4 = B,I,U,FONT,CENTER,IMG,A
                                                      5 = B,I,U,IMG,A
                                                      6 = B,I,U,IMG
                                                      7 = B,I,U,A
                                                      8 = IMG,A
                                                      9 = B,I,A
                                                     10 = I,A
                                                     11 = A
                                                     12 = никакие
                                               "STRING" = указать самому (в формате <a><b><c>)
        censored    пропускать-ли через цензор
        typo        пропускать-ли через сраный типограф
    */  
    
        # обезопасиваем
        switch ($safelevel)
        {
            case 0: $return =       $html; break;
            case 1: $return =       strip_tags($html,"<b><i><u><font><p><div><center><img><a><span><table><td><tr><input><form><textarea><script>"); break;
            case 2: $return =       strip_tags($html,"<b><i><u><font><p><div><center><img><a><span><table><td><tr>"); break;
            case 3: $return =       strip_tags($html,"<b><i><u><font><p><div><center><img><a><span>"); break;
            case 4: $return =       strip_tags($html,"<b><i><u><font><center><img><a>"); break;
            case 5: $return =       strip_tags($html,"<b><i><u><img><a>"); break;
            case 6: $return =       strip_tags($html,"<b><i><u><img>"); break;
            case 7: $return =       strip_tags($html,"<b><i><u><a>"); break;
            case 8: $return =       strip_tags($html,"<img><a>"); break;
            case 9: $return =       strip_tags($html,"<b><i><a>"); break;
            case 10: $return =      strip_tags($html,"<i><a>"); break;
            case 11: $return =      strip_tags($html,"<a>"); break;
            case 12: $return =      strip_tags($html); break;
            default: $return=addslashes($return); break;
        }
        
        
        
        # если censored=true, то цензорим все, сносим хуи и пёзды.
         # upd: к сожалению, цензор, спизженый где-то в сети, оказался корявым и мы временно будем читать мат.
        if ($censored==false)
        {
            $return=str_replace("!!!!!!!!!!","! я идиот, убейте меня кто нибудь !",$return);
            $return=str_replace("))))))))))","! я идиот, убейте меня кто нибудь !",$return);
        }
        
        # если typo=true то обрабатываем сраным типографом
        if ($typo==true)
        {
            $typog = new Typographus();
            $return = $typog->process($return);
        }
    
         if ($crop!=0)
         {
              $return = CropString($crop,$return);
         }
    
        return $return;
    }

    getrix, 11 Ноября 2009

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

    +68.4

    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
    char rc;
    ...
    bool ResourceManager()
    {
    	static TResourceRC r;
    	...
    	delete r;
    	...
    	r=new TResourceRC(rc);
    	...
    	return true;
    	assert(false);
    };
    ...

    От предков проект достался. Я думал, чего он переодически необьяснимо глючит...
    ResourceManager() - вызываеться регулярно в цикле.

    Говногость, 11 Ноября 2009

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

    +73.7

    1. 1
    2. 2
    3. 3
    #include <math.h>
     ...
    result = (thisCos ? cos : sin)(3.140);

    Знакомый программист прислал из своего проекта.

    Говногость, 10 Ноября 2009

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

    +146.3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    <?if (count($arResult["ERRORS"])):?>
    	<?=ShowError(implode("<br />", $arResult["ERRORS"]))?>
    <?endif?>
    
    <?if (strlen($arResult["MESSAGE"]) > 0):?>
    	<?=ShowNote($arResult["MESSAGE"])?>
    <?endif?>

    уже глаза разрывает от этого классного форматирования

    y6uTbIu_CMEXOM, 10 Ноября 2009

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

    +95.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    static bool EqStr(string s)
    {
                Regex r = new Regex(@"STRING");
                Match m = r.Match(s);
                if (m.Success == true) return true;
                else return false;
    }

    Изощренный способ сравнивать строки :)

    psina-from-ua, 10 Ноября 2009

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

    +136

    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
    public string generateEMail()
    		{
    			string res;
    			int i = PersonName.IndexOf(" ");
    			char[] str1 = new char[i];
    			PersonName.CopyTo(0, str1, 0, i);
    			string str11 = new string(str1);
    			char[] str2 = new char[PersonName.Length - i - 1];
    			PersonName.CopyTo(i + 1, str2, 0, PersonName.Length - i - 1);
    			string str22 = new string(str2);
    			res = str11.ToString() + "." + str22.ToString();
    			if (res.Length > 20)
    			{
    				str1 = new char[20];
    				res.CopyTo(0, str1, 0, 20);
    				res = new string(str1);
    			}
    			res += "@domain.ua";
    			return res;
    		}

    Вот вам шаблон для получения емейла из имени и фамилии сотрудника.

    Woonder, 10 Ноября 2009

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