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

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

    +136.2

    1. 1
    2. 2
    3. 3
    var ids = form.Keys;
    
    if(ids.Length == 0 || ids.Length > 1) { throw Exception;}

    кидать исключение если ids.Length !=1

    xrundelek, 28 Августа 2009

    Комментарии (7)
  3. Куча / Говнокод #18003

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    "brutushafens", "ebal3_14","ebal_mamu_3_14","putin_xyilo","3_14-pidoraha","gde_siski_blyat","ebal3_14",
                 "vi_vse_pidarasi","ebanutie_sobaki","peremoga_ili_zrada","da_vi_ohueli","poluebki","3_14_nu_ti_i_mudak",
                 "3_14-huesos","novorossi9-huesossi9","jjjgirteo", "xyja4it", "StackBlower","bawluntuk", "Kaffier", 
                 "patah", "Xalyazij", "mauntin","sukablya","slava_ukraine","xyilka",
                 "Parazit", "kalximik", "Sundukovskiy", "Talbin", "eblankah", "krokodildoh", "karbagol", "youloh",
                 "marixyan", "Germanik", "vavizh", "Bubby", "xavij", "vadim", "isivgr", "Zuruck", "hhhh5", "anawistka", 
                 "NigerFromGabbanah", "Gromov", "maldyn003", "Iydywka", "treoie", "blandermein", "botbatbotbatbot", 
                 "gzhegow", "zabydligah", "celovalnik", "Miwkarik", "tschedosch", "molasessia", "ambipuur", "hinter", "bayanist", 
                 "gazenva85", "kargoudn", "Pikyn", "onnanon"

    50 оттенков сала

    Для борьбы с вредителями

    kegdan, 16 Апреля 2015

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

    +136

    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
    printf("Enter item code: ");                                        //Prompts user
    scanf ("%14s", codenew1);                                           //Read user input
    len = strlen(codenew1);                                             //Read each character into variable len
    
    while (len != strspn(codenew1, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))
    {
        printf ("Name contains non-alphabet characters. Try again!: "); //Prompts user to try again
        scanf ("%14s", codenew1);                                       //Reads user input
        len = strlen(codenew1);                                         //Read each character into variable len
    }                                                                   //Endwhile
    strncpy(codenew, codenew1,2);                                       //Copy the first two characters from the variable codenew1
    codenew[2] = 0;                                                     //Store first two characters into variavle codenew
    
    for ( j = 0; j < num_items; j++)                                    //Loop for num_items times
    {                                                                   //Beginning of for loop
        if (strcmp(array[j].code1, codenew) == 0)                       //If codenew is found in file
        {                                                               //Beginning of if statement
            price[i] = item_qty[i] * array[j].price1;                   //Calculating the price of an item
            printf("Price : %d", price[i]);                             //Prints price
            printf("\nEnter '%s' to confirm: ", array[j].itemname1);    //Confirming the item
            scanf("%19s", item_name1[i]);
            while (strcmp(item_name1[i], array[j].itemname1 )!=0)       //Looping until both item names are the same
            {                                                           //Begin while loop
                printf("Item name is not %s ,Try Again!: ", array[j].itemname1);    //Prompt user to try again
                scanf ("%19s", item_name1[i]);                              //Reads item name into an array
                len = strlen(item_name1[i]);                                //Reads each character into variable len
            }                                                               //End while loop
            len = strlen(item_name1[i]);                                    //Read each character into variable len
            while (len != strspn(item_name1[i], "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"))    //While len contains non alphabetic characters
            {                                                                       //Beginning while
                printf ("Name contains non-alphabet characters. Try again!: ");     //Prompts user to try again
                scanf ("%19s", item_name1[i]);                                      //Read user input
                len = strlen(item_name1[i]);                                        //Read each character into variable len
            }                                                                       //End while
            strncpy(item_name[i], item_name1[i], 20);                               //Copy the first two characters from the variable codenew1
            item_name[i][20] = 0;                                                   //Store first 20 characters in variable item_name[i]
            total_price+= price[i];                                     //Calculate total price
            break;                                                      //Terminates loop
        }                                                               //End of if statement
        else 
            if (strcmp(array[j].code1, codenew) != 0)                       //If codenew is found in file
            {
                printf("Invalid input! Try again.");
                goto Here;
            }
    }                                                           //End of for loop

    Бесценные комментарии!
    http://stackoverflow.com/questions/29045067/error-check-files

    myaut, 14 Марта 2015

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

    +136

    1. 1
    2. 2
    for (j = 0; j < NUM_DMA_BUFFERS; j++)
            *(int *)dev->channel[0].virtDma[j] = 0x1235+j;

    ЯННП

    codemonkey, 23 Февраля 2015

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

    +136

    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
    #include <stdint.h>
    #include <Windows.h>
    #include <intrin.h>
    
    typedef long dt;
    
    namespace {
    	dt InitializationIsInProgress = 0;
    	dt InitializationIsFinished = 0;
    }
    
    dt InterlockedLoad(dt volatile * t){
    	return InterlockedCompareExchange(t, 0, 0);
    }
    
    dt InterlockedAssign(dt volatile * t, dt v){
    	dt c = 0;
    	while (c = InterlockedCompareExchange(t, v, c));
    }
    
    void InitializeSystem(){
    	if (InterlockedLoad(&InitializationIsFinished) == 1)
    		return;
    	while (InterlockedCompareExchange(&InitializationIsInProgress, 1, 0) == 1) Sleep(0);
    	//__ReadWriteBarrier();
    	if (InterlockedLoad(&InitializationIsFinished) == 1)
    		return;
    	Work();
    	InterlockedAssign(&InitializationIsFinished, 1);
    	InterlockedAssign(&InitializationIsInProgress, 0);
    }

    Не судите строга. Воспользуюсь как пастебином. Если найдете ошибки - пришлю пирожок.

    LispGovno, 04 Февраля 2015

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

    +136

    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
    private static string RemoveInvalidChars(string source)
    {
        foreach (var c in invalidChars)
            source = source.Replace(c.ToString(), "");
    
        return source;
    }
    
    public static string Validate(string source)
    {
        source = RemoveInvalidChars(source);
    
        return source;
    }

    pushistayapodmyshka, 02 Февраля 2015

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static IEnumerable<T> Remove<T>(this IEnumerable<T> source, T key)
    {
        return source.Where(element => !element.Equals(key));
    }
    
    public static IEnumerable<string> Remove(this IEnumerable<string> source, string key)
    {
        return source.Where(element => element != key);
    }

    Немного велосипедостроения.

    pushistayapodmyshka, 30 Января 2015

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

    +136

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        double bytesIn = double.Parse(e.BytesReceived.ToString());
        double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
        double percentage = bytesIn / totalBytes * 100;
        label2.Text = "Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive;
        progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
    }

    Вычилсяем проценты :D

    Xekep, 28 Января 2015

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

    +136

    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
    struct hostent *rc_gethostbyname(const char *hostname)
    {
    	struct 	hostent *hp;
    #ifdef GETHOSTBYNAME_R
    #if defined (GETHOSTBYNAMERSTYLE_SYSV) || defined (GETHOSTBYNAMERSTYLE_GNU)
    	struct 	hostent hostbuf;
    	size_t	hostbuflen;
    	char	*tmphostbuf;
    	int	res;
    	int	herr;
    	
    	hostbuflen = 1024;
    	tmphostbuf = malloc(hostbuflen);
    #endif
    #endif
    
    #ifdef GETHOSTBYNAME_R
    #if defined (GETHOSTBYNAMERSTYLE_GNU)
    	while ((res = gethostbyname_r(hostname, &hostbuf, tmphostbuf, hostbuflen, &hp, &herr)) == ERANGE)
    	{
    		/* Enlarge the buffer */
    		hostbuflen *= 2;
    		tmphostbuf = realloc(tmphostbuf, hostbuflen);
    	}
    	free(tmphostbuf);
    #elif defined (GETHOSTBYNAMERSTYLE_SYSV)
    	hp = gethostbyname_r(hostname, &hostbuf, tmphostbuf, hostbuflen, &herr);
    	free(tmphostbuf);
    #else
    	hp = gethostbyname(hostname);
    #endif
    #else
    	hp = gethostbyname(hostname);
    #endif
    
    	if (hp == NULL) {
    		return NULL;
    	}
    	return hp;
    }

    freeradius-client 1.1.6, казалось бы серьезная либа... Говно мамонта, конечно, но оно валяется в репе бубунты 14.10... Неужели никто еще не заметил? :)

    bormand, 15 Января 2015

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

    +136

    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
    GetDate(string dateTimeText){
                    DateTime date = new DateTime();
                    String[] parsedDate = dateTimeText.Split('/');
                    bool allNumbers = true;
    
                    foreach (string s in parsedDate)
                    {
                        int value;
                        if (!int.TryParse(s, out value) && allNumbers)
                        {
                            allNumbers = false;
                        }
                    }
                    if (parsedDate.Length == 3 && allNumbers)
                    {
                        String newDateText = parsedDate[1] + "/" + parsedDate[0] + "/" + parsedDate[2];
    
                        DateTime.TryParse(newDateText, out date);
                    }
     return date;
    }

    парсинг юзеринпута в датетайм пикере

    zxxc, 05 Января 2015

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