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

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    private void tbMain_PreviewTextInput(object sender, TextCompositionEventArgs e)
    {
    	TextBox thisTextBox = (sender as TextBox);
    	e.Handled = (!(Char.IsDigit(e.Text, 0) && !((thisTextBox.Text.IndexOf("-") == 0) && thisTextBox.SelectionStart == 0))) &&
    		((e.Text.Substring(0, 1) != "-") || (thisTextBox.Text.IndexOf("-") == 0) || thisTextBox.SelectionStart != 0) &&
    		((e.Text.Substring(0, 1) != ".") || (thisTextBox.Text.IndexOf(".") != -1) || (thisTextBox.SelectionStart == 0) || (!Char.IsDigit(thisTextBox.Text.Substring(thisTextBox.SelectionStart - 1, 1), 0)) || ((thisTextBox.Text.IndexOf(",") != -1))) &&
    		((e.Text.Substring(0, 1) != ",") || (thisTextBox.Text.IndexOf(",") != -1) || (thisTextBox.SelectionStart == 0) || (!Char.IsDigit(thisTextBox.Text.Substring(thisTextBox.SelectionStart - 1, 1), 0)) || ((thisTextBox.Text.IndexOf(".") != -1)));
    	
    }

    yamamoto, 13 Апреля 2015

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

    +135

    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
    #include "mono-math.h"
    
    #ifndef HAVE_SIGNBIT
    
    int
    mono_signbit_float (float x)
    {
    	union { float f; int i; } u;
    
    	u.f = x;
    
    	return u.i < 0;
    }
    
    int
    mono_signbit_double (double x)
    {
    	union { double d; int i[2]; } u;
    
    	u.d = x;
    
    #if G_BYTE_ORDER == G_LITTLE_ENDIAN
    	return u.i [1] < 0;
    #else
    	return u.i [0] < 0;
    #endif
    }
    
    #endif

    Говно тут в том, что int далеко не везде будет 32 бит.
    https://github.com/mono/mono/blob/master/mono/utils/mono-math.c оттуда

    j123123, 19 Марта 2015

    Комментарии (5)
  4. Си / Говнокод #17767

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #define   CONC_LINE(a)  CONC(a, __LINE__)
    #define   CONC(a, b)  __CONC(a, b)
    #define __CONC(a, b)  a##b
    // ...
    int CONC_LINE(name);

    Способ присовокупить к названию переменной номер строки, где её объявили.
    Объясните кто-нибудь, почему #define CONC_LINE (a) __CONC ( a, __LINE__ ) дает: name__LINE__?

    refactor, 11 Марта 2015

    Комментарии (11)
  5. Си / Говнокод #17754

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    int overflow(const char *str)
    {
        char buf[9000];
        int res = atoi(buf);
        itoa(res, buf, 10);
        return strcmp(buf, str);
    }

    По мотивам #17745.

    gost, 09 Марта 2015

    Комментарии (3)
  6. Assembler / Говнокод #17584

    +135

    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
    descriptions[result].Append(tblib::Format("%").i(0x12345678, 0xBB));
    
    
    0040E729  push        0BBh 
    0040E72E  push        12345678h                                                                ; ага, запихали параметры для Format::i, заебись; теперь esp=0x0012f1f4
    0040E733  lea         eax,[esp+38h] 
    0040E737  push        eax                                                                      ; esp=0x0012f1f0
    0040E738  lea         ecx,[esp+1Ch] 
    0040E73C  mov         dword ptr [esp+3Ch],offset USER32_NULL_THUNK_DATA+40h (43C1A8h) 
    0040E744  mov         dword ptr [esp+40h],ebp 
    0040E748  mov         dword ptr [esp+44h],1 
    0040E750  call        tblib::HeapCArray<char>::HeapCArray<char><tblib::StringRef> (4161B0h)    ; esp=0x0012f1f4
    0040E755  push        400h                                                                     ; esp=0x0012f1f0
    0040E75A  mov         ecx,offset tbAlloc (18B0C88h) 
    0040E75F  mov         dword ptr [esp+2Ch],ebp 
    0040E763  mov         dword ptr [esp+28h],ebp 
    0040E767  mov         dword ptr [esp+24h],ebp 
    0040E76B  call        tblib::Allocator::Malloc (42C500h)                                       ; esp=0x0012f1f4
    0040E770  mov         dword ptr [esp+20h],eax 
    0040E774  neg         eax  
    0040E776  sbb         eax,eax 
    0040E778  and         eax,400h 
    0040E77D  lea         ecx,[esp+18h] 
    0040E781  mov         dword ptr [esp+24h],eax 
    0040E785  mov         dword ptr [esp+2Ch],0FFFFFFFFh 
    0040E78D  call        tblib::Format::PassToNext (41BC00h)            ; хуй знает почему, но после этой функции esp не меняется, конвенция такая видимо
    0040E792  sub         esp,0Ch                                        ; БЛЯДЬ СУКА НАХУЙ ЁБАНЫЙ ПИЗДЕЦ ТЫ ЧЁ СУКА ТВОРИШЬ ААААААААА!!!!!!!!!!!!!!!!!!!!!!!!
    0040E795  lea         ecx,[esp+24h] 
    0040E799  mov         edi,esp 
    0040E79B  call        tblib::Format::i (42DBA0h)                     ; esp=0x0012f1e8, указывает на мусор, параметры для функции - где-то выше
    ...

    MSVC 2003 релиз

    TarasB, 05 Февраля 2015

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static string ExeDirectory
    {
        get
        {
            var strBuff1 = System.Windows.Forms.Application.ExecutablePath;
            var strBuff2 = Path.GetFileName(strBuff1);
            return strBuff1.Remove(strBuff1.Length - strBuff2.Length, strBuff2.Length);
        }
    }

    Из моего проекта. Так я писал код 1.5 год назад.

    Janycz, 18 Января 2015

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

    +135

    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
    public enum Minutes
    	{
    		[Description("00")]
    		Zero = 0,
    
    		[Description("05")]
    		Five = 5,
    
    		[Description("10")]
    		Ten = 10,
    
    		[Description("15")]
    		Fifteen = 15,
    
    		[Description("20")]
    		Twenty = 20,
    
    		[Description("25")]
    		TwentyFive = 25,
    
    		[Description("30")]
    		Thirty = 30,
    
    		[Description("35")]
    		ThirtyFive = 35,
    
    		[Description("40")]
    		Forty = 40,
    
    		[Description("45")]
    		FortyFive = 45,
    
    		[Description("50")]
    		Fifty = 50,
    
    		[Description("55")]
    		FiftyFive = 55,
    	}

    schecterXA, 16 Января 2015

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

    +135

    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
    private static string GetMultipartFileContentType(string file)
    {
        var ext = file.Split('.').Last().ToLower();
    
        var types = new[]
        {
            new[] {"application/envoy","evy"},
            new[] {"application/fractals","fif"},
            new[] {"application/futuresplash","spl"},
            new[] {"application/hta","hta"},
            new[] {"application/internet-property-stream","acx"},
            new[] {"application/mac-binhex40","hqx"},
            new[] {"application/msword","doc"},
            new[] {"application/msword","dot"},
            new[] {"application/octet-stream","*"},
            new[] {"application/octet-stream","bin"},
            new[] {"application/octet-stream","class"},
            new[] {"application/octet-stream","dms"},
            new[] {"application/octet-stream","exe"},
            new[] {"application/octet-stream","lha"},
            new[] {"application/octet-stream","lzh"},
            new[] {"application/oda","oda"},
            // Многобукв...
            new[] {"x-world/x-vrml","xof"}
        };
    
        var toReturn = types.FirstOrDefault(t => t[1] == ext);
    
        return toReturn != null ? toReturn[0] : "application/octet-stream";
    }

    pushistayapodmyshka, 05 Января 2015

    Комментарии (13)
  10. Си / Говнокод #17396

    +135

    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
    /*
         * Lack of time prevents me from writing this segment properly.
         * May Krishna have mercy on my soul.
         */
        static const uint32_t pal            = 720 * 576 * 2;
        static const uint32_t ntsc_composite = 720 * 507 * 2;
        static const uint32_t ntsc_sdi       = 720 * 480 * 2;
        uint16_t new_width = width, new_height = height;
    
        if (height == 0) {
            new_width = 1920;
            new_height = 1080;
        }
    
        if (format == PAL) {
            rv = pal;
            memset(out_payload, 0x3F, rv);
        }
        else if (format == NTSC) {
            if (source == SDI_VIDEO) {
                rv = ntsc_sdi;
                memset(out_payload, 0x3F, rv);
            }
            else {
                rv = ntsc_composite;
                memset(out_payload, 0x3F, rv);
            }
        }
        else {
            rv = new_width * new_height * 2;
            memset(out_payload, 0x3F, rv);
        }

    Вот что переизбыток мочи делает.

    codemonkey, 31 Декабря 2014

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

    +135

    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
    /// <summary>
    /// Converts to number.
    /// </summary>
    /// <param name="value">The value.</param>
    /// <returns>System.String.</returns>
    public static string convertToNumber(string value) {
        string mvalue = "0";
        string wildchars = @"~!@#$%^&*()_+={}[]|\/?><,`:;'";
        bool chknegative = false;
    	if (value == null)
    		value = "";
        try {
            if (value == "") {
                mvalue = "0";
            }
            for (var i = 0; i < wildchars.Length; i++) {
                string wildchar = wildchars.Substring(i, 1);
                //chknegative = value.Contains(wildchar);
                mvalue = value.Replace(wildchar, "");
                value = mvalue;
            }
    
    
            chknegative = value.Contains("-");
    
            if (chknegative) {
                mvalue = value.Replace("-", "");
                mvalue = "-" + mvalue;
            }
            else {
                mvalue = value;
            }
        }
        catch {
            mvalue = "0";
        }
        return mvalue;
    }

    barsv, 29 Декабря 2014

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