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

    +163

    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
    Example #3 preg_replace_callback() using recursive structure to handle encapsulated BB code
    <?php
    $input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
    
    function parseTagsRecursive($input)
    {
    
        $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
    
        if (is_array($input)) {
            $input = '<div style="margin-left: 10px">'.$input[1].'</div>';
        }
    
        return preg_replace_callback($regex, 'parseTagsRecursive', $input);
    }
    
    $output = parseTagsRecursive($input);
    
    echo $output;
    ?>

    Не знаю, баян или нет. Поиском не смог найти preg_replace_callback на этом сайте.
    В таком недлинном коде есть очень аппетитное дерьмецо (кроме языка). Если в качестве $input взять строку подлиннее, то интерпретатор, как Чак Норрис, сосчитает до бесконечности. Исправляется добавлением одного символа к коду.

    inkanus-gray, 03 Июля 2011

    Комментарии (2)
  2. PHP / Говнокод #7138

    +164

    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
    //Пришел  
    $in_h = "10"; 
    //Ушел 
    $exit_h = "19"; 
    //Для определения, ушел после полуночи или до 
    $metka = date(a); 
    if ($metka == "pm") { 
    echo ("24" - $in_h)-("24" - $exit_h);  
    } 
    else if ($metka == "am") 
    { 
    echo "am"; 
    echo "24" - $in_h + $exit_h;

    вычисление времени, проведенного на работе..

    AlexT, 03 Июля 2011

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

    +79

    1. 1
    2. 2
    boolean direct = !Boolean.FALSE.equals(directParam);
        boolean demoAgency = !direct;

    yvu, 03 Июля 2011

    Комментарии (45)
  4. PHP / Говнокод #7136

    +150

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function rustrtolower($s)
    	{
    		$from = array("А","Б","В","Г","Д","Е","Ё","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я","A","B","C","D","E","F","G","H","I","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","J");
    		$to =   array("а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я","a","b","c","d","e","f","g","h","i","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","j");
    		return str_replace($from, $to, $s);
    	}

    Мартин, 02 Июля 2011

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

    +151

    1. 1
    var GetUrl = /\[(.*)\]/g.exec("$SECTION_NAME$")[1].replace(/\-/i, '~').replace(/\-/i, '~');

    фу ;(

    substr, 02 Июля 2011

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

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if($inc == true){
         $counter_val = $cat[$this->FileCounterKey] + 1;
    }else{
         $counter_val = $cat[$this->FileCounterKey] - 1;
    }

    Класс деревьев в одной русской CMS. Метод пересчитывает кол-во файлов в категории после добавления/удаления.

    Мартин, 02 Июля 2011

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

    +75

    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
    <% ServicePackage servicePackage = null; %>
    	<% char fi [] = {'g', 'v', 'p'}; %>
    	<% int  ni [] = {3, 7, 11}; %>
    	
    	<% for(int i = 0; i < fi.length; i++)
    		 for(int j = 1; j <= ni[i]; j++)
    		 	{
    		 		String id = "", name = null, brief = null, price = null;
    		 		id += (char)fi[i];
    		 		if (j >= 10) 
    		 			id += (char)('0' + j / 10);
    		 		id += (char)('0' + j % 10);
    		 		
    		 		servicePackage = AllServicePackages.map.get(id);
    		 		if (servicePackage != null)
    		 		{
    		 			name = servicePackage.getName();
    		 			brief = servicePackage.getBrief();
    		 			price = servicePackage.getPrise();
    		 		}
    		 		%>
    		 <%	} %>

    Автору хотелось перебрать все эл-ты map'а.

    qweqweqwe, 02 Июля 2011

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

    −120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if( (ori == UIInterfaceOrientationLandscapeLeft) || (ori == UIInterfaceOrientationLandscapeRight))
    {
        // Some code
    }
    else if(ori==UIInterfaceOrientationPortrait || ori==UIInterfaceOrientationPortraitUpsideDown)
    {
        // Some other code
    }
    else {
        // God mode on!
    }

    Реальный проект после индусов... Что движет этими людьми я не понимаю...

    makadaw, 02 Июля 2011

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

    +166

    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
    // say this is some existing structure. And we want to use
    // a list. We can tell it that the next pointer
    // is apple::next.
    struct apple {
        int data;
        apple * next;
    };
    
    // simple example of a minimal intrusive list. Could specify the
    // member pointer as template argument too, if we wanted:
    // template<typename E, E *E::*next_ptr>
    template<typename E>
    struct List {
        List(E *E::*next_ptr):head(0), next_ptr(next_ptr) { }
    
        void add(E &e) {
            // access its next pointer by the member pointer
            e.*next_ptr = head;
            head = &e;
        }
    
        E * head;
        E *E::*next_ptr;
    };
    
    int main() {
        List<apple> lst(&apple::next);
    
        apple a;
        lst.add(a);
    }

    c++ страшный язык :) (часть вторая)

    C++: Pointer to class data member: http://stackoverflow.com/questions/670734/c-pointer-to-class-data-member

    Такие конструкции "E *E::*next_ptr;" без подготовки не осилить.

    Aleskey, 02 Июля 2011

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // Обработка запроса
    for ($i = 1; $i<=300000; $i++)
    {
    $marat=$marat+10;
    }

    Эмуляция паузы при генерировании РНР-скриптом ответа для Flash-ки (сайт - онлайн казино)

    dekameron, 01 Июля 2011

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