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

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $src = fopen("0.txt", 'r');
    while(!feof($src))
    {
            $line[] = fgets($src);
            $line++;
    }

    Интересно чему в конце будет равно $line? :)

    Xander_Bass, 17 Декабря 2010

    Комментарии (47)
  3. Си / Говнокод #4713

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /*----------------------------------------------------------------------------*/
    double XzMinSec( double XBOCT, unsigned int OKP){ /*Gr(Ch).dG(dC)->Gr(Ch)MS.dS*/
    signed int  min,  xz = XBOCT; XBOCT-=xz; min=60*XBOCT;  XBOCT=(XBOCT*60-min)*60;
    if (XBOCT>=59.5) { unsigned char teg[32]; double n =  pow(10,OKP) * (XBOCT-min);
    signed int z=n;n-=z; if(n>=0.5||n<=-0.5){ signed int x,y=0; sprintf(teg,"%d",z);
    while(teg[y]!='\0') y++;  z=1; for( x=0; x<OKP; x++ )  if ( teg[--y]!='9' ) z=0;
    if(z==1) if(abs(min)==59) if(min<0) XBOCT=-4100; else XBOCT=4100; else if(min<0)
    XBOCT=-100; else XBOCT=100; }}     return  xz * 10000  +  min * 100  +  XBOCT; }
    /*----------------------------------------------------------------------------*/

    гм... работает...

    BeardRED, 22 Ноября 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    switch ($mode) {
                default:
                <не интересный код пропущен>
                break;
    }

    Догайтесь с какого это проекта?

    Я бы не запостил, если бы не увидел на хабре сообщение от некоторого striker_vlad:
    "буду рад, если найдете там что-то, что можно будет напостить на сам сайт ;)"

    Oleg_quadro, 13 Ноября 2010

    Комментарии (47)
  5. bash / Говнокод #3601

    −132

    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
    #!/bin/sh
    
    # ...
    
    # translate args from unix path to windows, if possible (eterbug #4933)
    args_to_winpath()
    {
        for i in "$@" ; do
            local TP="$i"
            local TR=${i/\~/$HOME}
            if [ -r "$TR" ] ; then
                WP=$(winepath -w "$TR" 2>/dev/null)
                [ -z "$WP" ] || TP="$WP"
            fi
            echo "$TP"
        done
    }
    
    # ...
    
    run_wine $(args_to_winpath "$@")

    Это WINE@Etersoft. Люди пытались преобразовать системные пути в командной строке во внутренние вайновские. В результате из C:\Program Files больше ничего не запускается.

    raorn, 30 Июня 2010

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    //reversed for sorting
        inline bool operator< (const Weight & other) const {
            return (GetValue() > other.GetValue());
        };

    ton4eg, 25 Июня 2010

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    bool GenerateException(int Code)
    {
       assert(false);
       return false;            //WTF???       Нужно перерефакторить.
    };

    Ещё одно проектное решение...

    Говногость, 13 Июня 2010

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    object FirstElement = null;
    foreach(var item in SomeCollection)
       {
           FirstElement = item;
           break;
       }

    Ось так от береться перший елемент з колекції :)

    O_O, 26 Мая 2010

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

    +24.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    session_start();
    if ($_SESSION['ok'] !== 1){
    echo "Сделали , блок сесиией";
    $_SESSION['ok'] = '1';
     } else {
    echo "Блок!";
    }

    Mr_Smile: сматрите ) в первый раз на странице должна быть надпись "Сделали блок сессией"
    Mr_Smile: при последующих обновлениях надпись должн абыть "Блок"
    Mr_Smile: а сколько ни обновляй все кажет "Сделали блок сессией"
    Mr_Smile: я ахутнГ?

    http://www.govnokod.com/171

    guest, 29 Ноября 2008

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

    0

    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
    public class Solution 
    {
        public string RemoveStars(string s) 
        {
            char[] str = new char[s.Length];
            int l = 0;
            
            for(int i = 0; i < s.Length; ++i)
                if(s[i] == '*')
                    --l;
                else
                    str[l++] = s[i];
            
            return new string(str, 0, l);
        }
    }

    решил выйти из выгорания изучением новой технологии. литкод оказался прикольной штукой..

    kcalbCube, 23 Октября 2022

    Комментарии (46)
  11. C++ / Говнокод #27483

    +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
    #include <unistd.h>
    #include <stdio.h>
    #include <limits.h>
    
    template<size_t Size> struct static_string {char data[Size];};
    template<size_t ... Indexes>struct index_sequence {};
    template<size_t Size, size_t ... Indexes>
    constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const static_string<Size>& str,index_sequence<Indexes ...>) {return {str.data[Indexes] ..., '\0'};}
    constexpr static_string<1> make_static_string() {return {'\0'};}
    template<size_t Size, size_t ... Indexes>
    struct make_index_sequence : make_index_sequence<Size - 1, Size - 1, Indexes ...> {};
    template<size_t Size>
    constexpr static_string<Size> make_static_string(const char (& str)[Size]) {return make_static_string(str, make_index_sequence<Size - 1>{});}
    template<size_t ... Indexes>
    struct make_index_sequence<0, Indexes ...> : index_sequence<Indexes ...> {};
    template<size_t Size, size_t ... Indexes>
    constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const char (& str)[Size],index_sequence<Indexes ...>) {return {str[Indexes] ..., '\0'};}
    template<size_t Size>
    constexpr size_t static_string_find(const static_string<Size>& str, char ch, size_t from, size_t nth) {return Size < 2 || from >= Size - 1 ? UINT_MAX :str.data[from] != ch ? static_string_find(str, ch, from + 1, nth) :nth > 0 ? static_string_find(str, ch, from + 1, nth - 1) : from;}
    template<size_t Size>
    constexpr size_t static_string_find_0(const static_string<Size>& str, char ch, size_t from, size_t nth) {return Size < 2 || from >= Size - 1 ? 0 : str.data[from] != ch ? static_string_find_0(str, ch, from + 1, nth) :nth > 0 ? static_string_find(str, ch, from + 1, nth - 1) : from;}
    template<size_t Size1, size_t ... Indexes1, size_t Size2, size_t ... Indexes2>
    constexpr static_string<Size1 + Size2 - 1> static_string_concat_2(const static_string<Size1>& str1, index_sequence<Indexes1 ...>,const static_string<Size2>& str2, index_sequence<Indexes2 ...>) {return {str1.data[Indexes1] ..., str2.data[Indexes2] ..., '\0'};}
    template<size_t Size1, size_t Size2>
    constexpr static_string<Size1 + Size2 - 1> static_string_concat_2(const static_string<Size1>& str1, const static_string<Size2>& str2) {return static_string_concat_2(str1, make_index_sequence<Size1 - 1>{},str2, make_index_sequence<Size2 - 1>{});}
    template<size_t Begin, size_t End, size_t ... Indexes>
    struct make_index_subsequence : make_index_subsequence<Begin, End - 1, End - 1, Indexes ...> {};
    template<size_t Pos, size_t ... Indexes>
    struct make_index_subsequence<Pos, Pos, Indexes ...> : index_sequence<Indexes ...> {};
    template<size_t Begin, size_t End, size_t Size>
    constexpr static_string<End - Begin + 1> static_string_substring(const static_string<Size>& str) {return make_static_string(str, make_index_subsequence<Begin, End>{});}
    template<size_t Begin, size_t Size>
    constexpr static_string<Size - Begin> static_string_suffix(const static_string<Size>& str) {return static_string_substring<Begin, Size - 1>(str);}
    #define remove_underscore(arg) ([] () __attribute__((always_inline)) {constexpr auto a = static_string_find(make_static_string(arg),'_',0,0) == UINT_MAX? make_static_string(arg):static_string_concat_2(static_string_concat_2(static_string_substring<0,static_string_find_0(make_static_string(arg),'_',0,0)>(make_static_string(arg)),static_string_suffix<static_string_find_0(make_static_string(arg),'_',0,0)+1>(make_static_string(arg))),make_static_string("\0"));return a;}().data)
    
    int main()
    {
        puts(remove_underscore("_testtest"));
        puts(remove_underscore("test_test"));
        puts(remove_underscore("testtest_"));
    }

    Убогий constexpr в c++11

    mittorn, 25 Июня 2021

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