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

    +144

    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
    // Класс валидации в PrestaShop
    class ValidateCore
    {
    ...
    	public static function isIp2Long($ip)
    	{
    		return preg_match('#^-?[0-9]+$#', (string)$ip);
    	}
    
    	public static function isAnything()
    	{
    		return true;
    	}
    ...

    invision70, 16 Июня 2015

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

    +141

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    string log;
    ...
    try
    {
              Logger.SaveLog(fullPath, log);
    }
    catch (Exception ex)
    {
             Logger.SaveLog(fullPath, ex.ToString());
    }

    Senior developer...

    kiberg, 16 Июня 2015

    Комментарии (0)
  3. Lua / Говнокод #18346

    −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
    local sol_lines = {}
    local i = 1; local j = 0;
    	
    while (i <= solution:len()) do
    	local begin_pos = i
    	while(i <= solution:len() and solution:sub(i, i) ~= '\n') do
    		i = i + 1
    	end
    
    	if i > solution:len() then
    		i = solution:len()
    	end
    
    	local cur_line = solution:sub(begin_pos, i)
    	sol_lines[j] = trim(cur_line)
    	i = i + 1
    	j = j + 1
    end

    Lua
    Как я разбивал строку на отдельные линии. Вместо того, чтобы использовать string.find(s, "\n", i + 1). Так я писал код 0.027397 года назад назад.

    Janycz, 15 Июня 2015

    Комментарии (28)
  4. C# / Говнокод #18344

    +142

    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
    public void AllocateMemory(ref int[] segmentSizeProcess)
            {
                int[] difference;
                int j = 0;
                int tempo = 0;
    
                for (int i = 0; i < segmentSizeProcess.Count(); i++)
                {
                    difference = new int[memory.Count]; // храним разность размера блока памяти и требуемого размера для процесса
                    for (int count = 0; count < memory.Count; count++)
                    {
                        difference[count] = -2; // предварительно инициализируем 
                    }
                    for (int count_memory=0; count_memory<memory.Count();
                        count_memory++)
                    {
                        if (memory[count_memory].size - segmentSizeProcess[i] >= 0) // если равно 0, значит 
                        // сегмент полностью распределён
                        {
                            if (!memory[count_memory].isAllocate)
                            { difference[count_memory] = memory[count_memory].size - segmentSizeProcess[i]; }
                            else
                            { difference[count_memory] = -1; } // если сегмент занят - 
                            // то он недоступен
                        }
                    }
                    tempo = GetMinDifference(ref difference); // получаем индекс минимальной разности
                    // если результат "-", значит секторы заняты, выходим из цикла
                    if (difference[tempo] >= 0)
                    {
                        memory.ElementAt(tempo).isAllocate = true; // процесс занял сегмент
                        if (difference[tempo] > 0) // если остаётся фрагмент памяти
                        {
                            CreateDifferenceSegment(difference[tempo]); // создаем новый сегмент, равный
                            // наименьшей разности памяти сегмента и памяти для процесса
                        }
                            memory[tempo].size = segmentSizeProcess[i]; // распределяем память
                    }
                    else
                    {
                        break;
                    }
                }
            }

    Примерная реализация алгоритма best-fit

    qstd, 15 Июня 2015

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

    +142

    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
    orders_list_app.constant('User', {
        auth : ('False' == 'True') ? true : false,
        contractor : ('' == 'True')  ? true : false,
        user_id : ('False' == 'True') ? None : false
    });
    
    // goes in another place
    
    angular.forEach(rootCategory.categories, function(category_2){
        angular.forEach(category_2.service_orders, function(service_2){
            rootCategory.service_orders.push(service_2);
                angular.forEach(category_2.categories, function(category_3){
                    angular.forEach(category_3.service_orders, function(service_3){
                        rootCategory.service_orders.push(service_3);
                    });
                });
            });
        });
        rootCategory.service_orders.push({name:"Другие услуги" ,text: "", title: "Другие услуги"});
    });

    На одном из отечественном сайте в продакшыне..

    alek0585, 15 Июня 2015

    Комментарии (0)
  6. Java / Говнокод #18342

    +144

    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
    public String tommorowCalendarCountry(String date, String country){
    		String tommorowCountry = null;
    		if(date.equals(getTommorow())){
    			tommorowCountry =  country;
    		}
    		return tommorowCountry;
    	}
    	
    	public String tommorowCalendarIndicator(String date, String indicator){
    		String tommorowIndicator = null;
    		if(date.equals(getTommorow())){
    			tommorowIndicator =  indicator;
    		}
    		return tommorowIndicator;
    	}
    	
    	public String tommorowCalendarImportance(String date, String importance){
    		String tommorowImportance = null;
    		if(date.equals(getTommorow())){
    			tommorowImportance =  importance;
    		}
    		return tommorowImportance;
    	}
    	
    	public String tommorowCalendarForecast(String date, String forecast){
    		String tommorowForecast = null;
    		if(date.equals(getTommorow())){
    			tommorowForecast =  forecast;
    		}
    		return tommorowForecast;
    	}
    	
    	public String tommorowCalendarPrevious(String date, String previous){
    		String tommorowPrevious = null;
    		if(date.equals(getTommorow())){
    			tommorowPrevious =  previous;
    		}
    		return tommorowPrevious;
    	}
    	
    	public String tommorowCalendarActual(String date, String actual){
    		String tommorowActual = null;
    		if(date.equals(getTommorow())){
    			tommorowActual =  actual;
    		}
    		return tommorowActual;
    	}
    	
    	public String tommorowCalendarDescription(String date, String description){
    		String tommorowDescription = null;
    		if(date.equals(getTommorow())){
    			tommorowDescription =  description;
    		}
    		return tommorowDescription;
    	}
    	
    	public String tommorowCalendarPeriod(String date, String period){
    		String tommorowPeriod = null;
    		if(date.equals(getTommorow())){
    			tommorowPeriod =  period;
    		}
    		return tommorowPeriod;
    	}
    	
    	public String tommorowCalendarLocation(String date, String location){
    		String tommorowLocation = null;
    		if(date.equals(getTommorow())){
    			tommorowLocation =  location;
    		}
    		return tommorowLocation;
    	}

    пришло с аутсорса. Такого в проекте очень много)

    slavik, 15 Июня 2015

    Комментарии (6)
  7. Куча / Говнокод #18341

    +142

    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
    'Check that the TGD exists
        If objFSO.FileExists(strTGDFileName) Then
        
            'Get the definition of the tag group
            objTagGroupFile.RetrieveDefinition strTGDFileName, intArrayLength, varSymbols, varSubstitutions, varDescriptions
                    
            'Ensure that the supplied strings match the strings in the tag group
            If (UBound(strSymbols) = UBound(strSubstitutions) And UBound(strSymbols) = UBound(varSymbols) And UBound(strSymbols) = UBound(varSubstitutions)) Or _
            (blIgnoreAdditional And (UBound(strSymbols) = UBound(strSubstitutions) And UBound(strSymbols) < UBound(varSymbols) And UBound(strSymbols) < UBound(varSubstitutions))) Then
                For intLoop = 0 To UBound(strSymbols)
                    If Not (strSymbols(intLoop) = varSymbols(intLoop) And strSubstitutions(intLoop) = varSubstitutions(intLoop)) Then
                        'TDG is out of date; create tag group file
                        CheckTagGroup = IIf(CreateTagGroupFile(strSymbols, strSubstitutions, strDescriptions, strTGDFileName), 1, 0)
                        GoTo Way_Out
                    End If
                Next
            Else
                'TDG is out of date; create tag group file
                CheckTagGroup = IIf(CreateTagGroupFile(strSymbols, strSubstitutions, strDescriptions, strTGDFileName), 1, 0)
                GoTo Way_Out
            End If
        
        Else
            'TGD does not exist so create the file
            CheckTagGroup = IIf(CreateTagGroupFile(strSymbols, strSubstitutions, strDescriptions, strTGDFileName), 1, 0)
            GoTo Way_Out
        End If

    Всё равно получишь шайбу!
    Вот такие умные проверки нашёл перед вызовом одной и той же функции.

    VB6

    Domkrat, 15 Июня 2015

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

    +143

    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
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    //выбираем игру для которой будем выводить таблицу
    		$query="SELECT * FROM a_stavki WHERE igra='$igra0' AND datigr='$datigr0'";
    		$db->setQuery($query);
    		$results0 = $db->loadObjectList();
    		if($userstavka1=="1"){$nam_1=$procent;}
    		if($userstavka1=="2"){$nam_2=$procent;}
    		if($userstavka1=="Х"){$nam_X=$procent;}
    		if($userstavka1=="ТБ"){$nam_TB=$procent;}
    		if($userstavka1=="ТМ"){$nam_TM=$procent;}
    		if($userstavka1=="ТБ2,5"){$nam_TB25=$procent;}
    		if($userstavka1=="ТМ2,5"){$nam_TM25=$procent;}
    		if($userstavka1=="ТБ3,5"){$nam_TB35=$procent;}
    		if($userstavka1=="ТМ3,5"){$nam_TM35=$procent;}
    		if($userstavka1=="ТБ4,5"){$nam_TB45=$procent;}
    		if($userstavka1=="ТМ4,5"){$nam_TM45=$procent;}
    		if($userstavka1=="ТБ5,5"){$nam_TB55=$procent;}
    		if($userstavka1=="ТМ5,5"){$nam_TM55=$procent;}
    		if($userstavka1=="ТБ150,5"){$nam_TB1505=$procent;}
    		if($userstavka1=="ТМ150,5"){$nam_TM1505=$procent;}
    		if($userstavka1=="ТБ160,5"){$nam_TB1605=$procent;}
    		if($userstavka1=="ТМ160,5"){$nam_TM1605=$procent;}
    		if($userstavka1=="1x"){$nam_1x=$procent;}
    		if($userstavka1=="x2"){$nam_x2=$procent;}
    		$stavok=0;
    		 foreach ($results0 as $note0) 
    		 {//бежим циклом по таблице выбирая все ставки конкретной игры
    		 $datigr1=$note0->datigr;
    		 $userstavka1=$note0->userstavka;
    		$query="SELECT *,COUNT('$userstavka1') AS OrderTotal FROM a_stavki WHERE userstavka='$userstavka1' AND igra='$igra0' AND datigr='$datigr0'";
    		$db->setQuery($query);
    		$results = $db->loadObjectList();
    		if($results){
    		 foreach ($results as $note) 
    		 {
    		 $stavok=$note->OrderTotal;
    		 }
    		}
    		 $stavok=($stavok/$allstav)*100;
    		 //$stavok=substr($stavok,0,2);
    		 $procent="<div class='grafcss0'><p class='grafcss' style='width:".$stavok."%'> &nbsp </p></div>";
    		if($nam_1!=''){$rez.="<tr><td>1</td><td>".$nam_1."</td></tr>";}
    		if($nam_2!=''){$rez.="<tr><td>2</td><td>".$nam_2."</td></tr>";}
    		if($nam_X!=''){$rez.="<tr><td>Х</td><td>".$nam_X."</td></tr>";}
    		if($nam_TB!=''){$rez.="<tr><td>ТБ</td><td>".$nam_TB."</td></tr>";}
    		if($nam_TM!=''){$rez.="<tr><td>ТМ</td><td>".$nam_TM."</td></tr>";}
    		if($nam_TB25!=''){$rez.="<tr><td>ТБ2,5</td><td>".$nam_TB25."</td></tr>";}
    		if($nam_TM25!=''){$rez.="<tr><td>ТМ2,5</td><td>".$nam_TM25."</td></tr>";}
    		if($nam_TB35!=''){$rez.="<tr><td>ТБ3,5</td><td>".$nam_TB35."</td></tr>";}
    		if($nam_TM35!=''){$rez.="<tr><td>ТМ3,5</td><td>".$nam_TM35."</td></tr>";}
    		if($nam_TB45!=''){$rez.="<tr><td>ТБ4,5</td><td>".$nam_TB45."</td></tr>";}
    		if($nam_TM45!=''){$rez.="<tr><td>ТМ4,5</td><td>".$nam_TM45."</td></tr>";}
    		if($nam_TB55!=''){$rez.="<tr><td>ТБ5,5</td><td>".$nam_TB55."</td></tr>";}
    		if($nam_TM55!=''){$rez.="<tr><td>ТМ5,5</td><td>".$nam_TM55."</td></tr>";}
    		if($nam_TB1505!=''){$rez.="<tr><td>ТБ150,5</td><td>".$nam_TB1505."</td></tr>";}
    		if($nam_TM1505!=''){$rez.="<tr><td>ТМ150,5</td><td>".$nam_TM1505."</td></tr>";}
    		if($nam_TB1605!=''){$rez.="<tr><td>ТБ160,5</td><td>".$nam_TB1605."</td></tr>";}
    		if($nam_TM1605!=''){$rez.="<tr><td>ТМ160,5</td><td>".$nam_TM1605."</td></tr>";}
    		if($nam_1x!=''){$rez.="<tr><td>1x</td><td>".$nam_1x."</td></tr>";}
    		if($nam_x2!=''){$rez.="<tr><td>x2</td><td>".$nam_x2."</td></tr>";}
    		}//-------end $results0
    
    		$rez="<tr><td style='width:100px;'>ставка</td><td>поставило в %</td></tr>";
    		if($nam_1!=''){$rez.="<tr><td>1</td><td>".$nam_1."</td></tr>";}
    		if($nam_2!=''){$rez.="<tr><td>2</td><td>".$nam_2."</td></tr>";}
    		if($nam_X!=''){$rez.="<tr><td>Х</td><td>".$nam_X."</td></tr>";}
    		if($nam_TB!=''){$rez.="<tr><td>ТБ</td><td>".$nam_TB."</td></tr>";}
    		if($nam_TM!=''){$rez.="<tr><td>ТМ</td><td>".$nam_TM."</td></tr>";}
    		if($nam_TB25!=''){$rez.="<tr><td>ТБ2,5</td><td>".$nam_TB25."</td></tr>";}
    		if($nam_TM25!=''){$rez.="<tr><td>ТМ2,5</td><td>".$nam_TM25."</td></tr>";}
    		if($nam_TB35!=''){$rez.="<tr><td>ТБ3,5</td><td>".$nam_TB35."</td></tr>";}
    		if($nam_TM35!=''){$rez.="<tr><td>ТМ3,5</td><td>".$nam_TM35."</td></tr>";}
    		if($nam_TB45!=''){$rez.="<tr><td>ТБ4,5</td><td>".$nam_TB45."</td></tr>";}
    		if($nam_TM45!=''){$rez.="<tr><td>ТМ4,5</td><td>".$nam_TM45."</td></tr>";}
    		if($nam_TB55!=''){$rez.="<tr><td>ТБ5,5</td><td>".$nam_TB55."</td></tr>";}
    		if($nam_TM55!=''){$rez.="<tr><td>ТМ5,5</td><td>".$nam_TM55."</td></tr>";}
    		if($nam_TB1505!=''){$rez.="<tr><td>ТБ150,5</td><td>".$nam_TB1505."</td></tr>";}
    		if($nam_TM1505!=''){$rez.="<tr><td>ТМ150,5</td><td>".$nam_TM1505."</td></tr>";}
    		if($nam_TB1605!=''){$rez.="<tr><td>ТБ160,5</td><td>".$nam_TB1605."</td></tr>";}
    		if($nam_TM1605!=''){$rez.="<tr><td>ТМ160,5</td><td>".$nam_TM1605."</td></tr>";}
    		if($nam_1x!=''){$rez.="<tr><td>1x</td><td>".$nam_1x."</td></tr>";}
    		if($nam_x2!=''){$rez.="<tr><td>x2</td><td>".$nam_x2."</td></tr>";}
    		$nam_1='';
    		$nam_2='';
    		$nam_X='';
    		$nam_TB='';
    		$nam_TM='';
    		$nam_TB25='';
    		$nam_TM25='';
    		$nam_TB35='';
    		$nam_TM35='';
    		$nam_TB45='';
    		$nam_TM45='';
    		$nam_TB55='';
    		$nam_TM55='';
    		$nam_TB1505='';
    		$nam_TM1505='';
    		$nam_TB1605='';

    Фрилансер и джумла....Вот так мне повезло....

    loikmaksim, 15 Июня 2015

    Комментарии (2)
  9. Куча / Говнокод #18339

    +142

    1. 1
    Куда пропадают кучки? Замечал и ранее, но думал что к этому причастны сами авторы, а сегодня пропал мой через пол-часа после публикации. Кто включил gc?

    FlySnake, 14 Июня 2015

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // Отправная точка новых изысканий
    uint16_t Mask = 0x0000;
    uint8_t i = 0;
    for(i=0; i<255; i++)
    	Mask |= (1 << i);
    
    ResponseBuf = (VirtualMemory & (Mask << RequestedAddr)) >> RequestedAddr;

    Из кода firmware одного девайса.

    Sushev, 14 Июня 2015

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