1. Лучший говнокод

    В номинации:
    За время:
  2. Куча / Говнокод #11731

    +117

    1. 1
    main = print x where x = x + 0

    http://ideone.com/9caQE

    result: Runtime error     time: 0.01s    memory: 3536 kB     signal: -1 
    input: no
    output: no
    stderr:
    prog: <<loop>>

    LispGovno, 09 Сентября 2012

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

    +62

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $user = User::model()->findByAttributes(array("email" => $this->username, "is_deleted"=>0));
    
    if (!$user)
    {
        $user = User::model()->findByAttributes(array("email" => $this->username, "is_deleted"=>0));
    }

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

    dizballanze, 07 Сентября 2012

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

    +31

    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
    #include <iostream>
    #include <tr1/functional>
    
    using namespace std::tr1::placeholders;
    
    struct I
    {
      int i;
    };
    
    struct S
    {
      int i;
      I ii;
    };
    
    int main()
    {
      std::tr1::function<I& (S&)> pi = std::tr1::bind(&S::ii, _1);
      std::tr1::function<std::tr1::reference_wrapper<I> (S&)> pri = std::tr1::bind(static_cast<std::tr1::reference_wrapper<I> (*)(I&)>(&std::tr1::ref<I>), std::tr1::bind(pi, _1));
      std::tr1::function<int& (S&)> psi = std::tr1::bind(&I::i, std::tr1::bind(&std::tr1::reference_wrapper<I>::get, std::tr1::bind(pri, _1)));
      S s = {1, {2}};
      std::cout << psi(s) << std::endl;
      psi(s) = 3;
      std::cout << psi(s) << std::endl;
      return 0;
    }

    Нашёл на RSDN, в теме о том, как получить указатель на член члена.

    suc-daniil, 28 Августа 2012

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

    +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
    @Override
    public boolean onTouchEvent(MotionEvent e) {
    	x=(int)e.getX(); y=(int)e.getY();
    	/* ... */
    	synchronized(this) {
    		try {this.wait(1000);}
    		catch (InterruptedException ex) {}
    	}
    	return true;
    }
    
    /* Gets (screen/pixel) x,y coordinates of last touch event*/
    public boolean GetCoordinates(MutablePoint coordinates) {
    	if (x==-1) return false;
    	coordinates.init(x,y);
    	return true;
    }

    https://github.com/acl33/AndroidDasher/blob/master/src/dasher/android/DasherCanvas.java

    rat4, 20 Августа 2012

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

    +60

    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
    list($width, $height, $type, $attr) = getimagesize($file1);
         
    if($width == $height)
    {    
        set_time_limit(270);
        if(filesize($file1) > 102400)  return array(false, "Размер больше 100Кб!");
        if($type == 1)      {$file2 = $file1.'.gif'; $out = $tizer_id.'.gif'; $type = 'gif'; $ext = 'gif';}
        elseif($type == 2)  {$file2 = $file1.'.jpg'; $out = $tizer_id.'.jpg'; $type = 'jpg'; $ext = 'jpg';}
        elseif($type == 3)  {$file2 = $file1.'.png'; $out = $tizer_id.'.png'; $type = 'png'; $ext = 'png';}
        else return array(false, "Это не картинка!");
        /* ... */
    }
    // no square
    else
    {
        return array(array('img',false, "Изображение не квадратное!"));
    }

    Зачем жить, если no square

    roman-kashitsyn, 19 Августа 2012

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

    +52

    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
    <?
    ....
    //башкортостан
    $city_select_arr = "<OPTGROUP LABEL=\"Республика Башкортостан\">";
    foreach($city_select_data as $k=>$v) {
    {
    $global_city = ($_GET['city'] == '' ? $_POST['city_select']: $_GET['city']);
    $city_select_arr .= "<option value=\"".$v."".( $v == $global_city ? " selected" : "" ) . "\">".$v."</option>";
    }
    }
    $city_select_arr .= "</OPTGROUP>";
    //пермский край
    $city_select_arr .= "<OPTGROUP LABEL=\"Пермский край\">";
    foreach($city_select2_data as $k=>$v) {
    {
    $global_city = ($_GET['city'] == '' ? $_POST['city_select']: $_GET['city']);
    $city_select_arr .= "<option value=\"".$v."".( $v == $global_city ? "" : "" ) . "\">".$v."</option>";
    }
    }
    $city_select_arr .= "</OPTGROUP>";
    
    .... и так еще циклов 10-15

    обратите внимание на переменную $global_city - ей в каждой итерации каждого цикла присваивают условное значение, которое в пределах этого файла точно не меняется :)
    ну и сам набор циклов можно было бы конечно систематизировать.

    scorcher, 19 Августа 2012

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

    +56

    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
    public function analyse($args) {
        $i = -1;
        $length = 0;
        $pictures = array();
    
        foreach ($args as $string) {
            switch (trim($string)) {
                case '{':
                    $i++;
                    $pictures[$i] = new element();
                    $length++;
                    break;
                case '}':
                   break;
               default:
                    if (preg_match('/^ {0,}([A-Za-z]{1,})\s{0,}:\s{0,}\'([\S\s]{0,})\';/iu', $string, $matches)) {
                        $pictures[$i]->setProperty($matches[1], $matches[2]);
                    }
                    break;
            }
        }
        return new container($pictures, $length);
    }

    Рукопашный парсинг Json-подобного синтаксиса.

    vistefan, 15 Августа 2012

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

    +55

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    // Проверяем корректность имени
        if(!preg_match("/^(([A-z\s]+)|([АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя\s]+))$/i", $_POST['name']))
            { $error .= ' - Вы ввели некорректное имя.<br>'; $count_error++; }
            
            // Проверяем корректность поля страны
        if(!preg_match("/^(([A-z\s]+)|([АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя\s]+))$/i", $_POST['country']))
            { $error .= ' - Вы ввели некорректное название страны.<br>'; $count_error++; }
    
            // Проверяем корректность поля города
        if(!empty($_POST['city']) && !preg_match("/^(([A-z\s]+)|([АаБбВвГгДдЕеЁёЖжЗзИиЙйКкЛлМмНнОоПпРрСсТтУуФфХхЦцЧчШшЩщЪъЫыЬьЭэЮюЯя\s]+))$/i", $_POST['city']))
            { $error .= ' - Вы ввели некорректное название города.<br>'; $count_error++; }

    Давно таких регулярок не видел :)

    duxabilii, 15 Августа 2012

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

    +28

    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
    byte* GetBuffer0(bool free = false)
    {
    	static std::auto_ptr<byte> transferBuffer;
    
    	if (free)
    	{
    		delete [] transferBuffer.release();
    	}
    	else
    	{
    		if (!transferBuffer.get())
    		{
    			transferBuffer.reset(new byte[BUFFER_SIZE]);
    		}
    	}
    	return transferBuffer.get();
    }
    
    byte* GetBuffer1(bool free = false)
    {
    	static std::auto_ptr<byte> transferBuffer;
    
    	if (free)
    	{
    		delete [] transferBuffer.release();
    	}
    	else
    	{
    		if (!transferBuffer.get())
    		{
    			transferBuffer.reset(new byte[BUFFER_SIZE]);
    		}
    	}
    	return transferBuffer.get();
    }

    legacy-дебри

    ni3_inv, 14 Августа 2012

    Комментарии (8)
  11. Assembler / Говнокод #11531

    +138

    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
    .text:00018584                 EXPORT get_msg_sequence
    .text:00018584 get_msg_sequence                        ; CODE XREF: IPC_send_singleIPC+6p
    .text:00018584                                         ; __IPC_send_singleIPC+6p
    .text:00018584                 LDR             R0, =0x7800C
    .text:00018586                 PUSH            {R4,LR}
    .text:00018588                 ADD             R0, PC
    .text:0001858A                 LDR             R0, [R0]
    .text:0001858C                 LDRB            R3, [R0]
    .text:0001858E                 CBZ             R3, loc_185A2
    .text:00018590                 LDR             R1, =(aRil - 0x1859C)
    .text:00018592                 MOVS            R0, #6
    .text:00018594                 LDR             R2, =(aS_0 - 0x1859E)
    .text:00018596                 LDR             R3, =(aGet_msg_sequen - 0x185A0)
    .text:00018598                 ADD             R1, PC  ; "RIL"
    .text:0001859A                 ADD             R2, PC  ; "%s()"
    .text:0001859C                 ADD             R3, PC  ; "get_msg_sequence"
    .text:0001859E                 BLX             __android_log_print
    .text:000185A2
    .text:000185A2 loc_185A2                               ; CODE XREF: get_msg_sequence+Aj
    .text:000185A2                 LDR             R3, =(unk_98E7E - 0x185A8)
    .text:000185A4                 ADD             R3, PC
    .text:000185A6                 LDRB            R2, [R3]
    .text:000185A8                 CMP             R2, #0xFD
    .text:000185AA                 BLS             loc_185B0
    .text:000185AC                 MOVS            R2, #0
    .text:000185AE                 B               loc_185B2
    .text:000185B0 ; ---------------------------------------------------------------------------
    .text:000185B0
    .text:000185B0 loc_185B0                               ; CODE XREF: get_msg_sequence+26j
    .text:000185B0                 ADDS            R2, #1
    .text:000185B2
    .text:000185B2 loc_185B2                               ; CODE XREF: get_msg_sequence+2Aj
    .text:000185B2                 LDR             R1, =(unk_98E7E - 0x185BA)
    .text:000185B4                 STRB            R2, [R3]
    .text:000185B6                 ADD             R1, PC
    .text:000185B8                 LDRB            R0, [R1]
    .text:000185BA                 POP             {R4,PC}
    .text:000185BA ; End of function get_msg_sequence

    Потрясающе эффективный выхлоп GCC. Компилировалось, вероятно, все-таки с включенной оптимизацией.

    Например, последовательность LDR R1/ADD R1,PC/LDRB R0, [R1] в конце вообще лишняя: достаточно было использовать R0 вместо R2.

    Grindars, 04 Августа 2012

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