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

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

    +133

    1. 1
    2. 2
    if (dbg)
    	printf("2\n");

    // This is debug mode

    codemonkey, 22 Января 2015

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

    +133

    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
    //......................................
    void DlPortWritePortUshort(WORD addr, WORD data) {
      DWORD br;
      (&addr)[1]=data;
      DeviceIoControl(hdriver,IOCTL_WRITE_PORT_USHORT,&addr,4,NULL,0,&br,NULL);
    }
    
    DWORD DlPortReadPortUlong(WORD addr) {
     DWORD br;
     DeviceIoControl(hdriver,IOCTL_READ_PORT_ULONG,&addr,2,&addr,4,&br,NULL);
     return *(DWORD*)&addr;
    }
    
    void DlPortWritePortUlong(WORD addr, DWORD data) {
      DWORD br;
      DeviceIoControl(hdriver,IOCTL_WRITE_PORT_ULONG,&addr,8,NULL,0,&br,NULL);
    }
    //......................................

    Кусок очередного форка dll-ки для работы с очередным, мать его, форком драйвера inpout32.sys.
    Попался в поисках исправленного драйвера и dll-обёртки для него.

    harvestor, 22 Января 2015

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

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var hContextMenu = (ContextMenu)MainDataGrid.Resources["CellContextMenu"];
    //UndoMenuItem.CommandTarget = MainDataGrid;
    UndoMenuItem.Command = ((MenuItem)hContextMenu.Items[0]).Command; //Undo
    //RedoMenuItem.CommandTarget = MainDataGrid;
    RedoMenuItem.Command = ((MenuItem)hContextMenu.Items[1]).Command; //Redo
    //CutMenuItem.CommandTarget = MainDataGrid;
    CutMenuItem.Command = ((MenuItem)hContextMenu.Items[3]).Command; //Cut
    //CopyMenuItem.CommandTarget = MainDataGrid;
    CopyMenuItem.Command = ((MenuItem)hContextMenu.Items[4]).Command; //Copy
    //PasteMenuItem.CommandTarget = MainDataGrid;
    PasteMenuItem.Command = ((MenuItem)hContextMenu.Items[5]).Command; //Paste

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

    Janycz, 18 Января 2015

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

    +133

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace nonopt
    {
        class Program
        {
            static void Main(string[] args)
            {
                string h = "h";
                string e = "e";
                string l1 = "l";
                string l2 = "l";
                string o1 = "o";
                string he = h + e;
    			string ll = l1 + l2;
                string hell = he + ll;
                string hello = hell + o1;
                string w = "w";
                string o2 = "o";
                string r = "r";
                string l3 = "l";
                string d = "d";
                string wo = w + o2;
                string rl = r + l3;
                string worl = wo + rl;
                string world = worl + d;
                string empty = " ";
                Console.WriteLine(hello + empty + world);
    			Console.ReadKey();
            }
        }
    }

    pewppy, 10 Января 2015

    Комментарии (11)
  6. Куча / Говнокод #17423

    +133

    1. 1
    http://www.youtube.com/watch?v=yRsT5wBSYZ0

    Советую

    LispGovno, 09 Января 2015

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

    +133

    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
    public static T ElementAtReverse<T>(this IEnumerable<T> source, int index)
    {
        while (true)
        {
            var array = source as T[] ?? source.ToArray();
    
            var elementsCount = array.Count();
    
            if (index < elementsCount || elementsCount == 0)
                return array.ElementAt(elementsCount - 1 - index);
    
            source = array;
            index = index % elementsCount;
        }
    }

    pushistayapodmyshka, 18 Декабря 2014

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

    +133

    1. 1
    2. 2
    3. 3
    BaseIndexerObjectType type;
    <...>
    var searchType = (SearchEntity)Enum.Parse(typeof(SearchEntity), type.ToString());

    Наткнулся на просторах рабочего кода. Конвертируем один енум в другой.

    Yuuri, 17 Декабря 2014

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

    +133

    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
    bool findImageToleranceIn(CTSInfo *info, bitmap *imageToFind, int32_t *x, int32_t *y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint16_t tolerance)
    {
        int I, J, XX, YY;
        info->tol = tolerance;
        int dX = (x2 - x1) - (imageToFind->width - 1);
        int dY = (y2 - y1) - (imageToFind->height - 1);
        for (I = 0; I < dY; ++I)
        {
            for (J = 0; J < dX; ++J)
            {
                for (YY = 0; YY < imageToFind->height; ++YY)
                {
                    for (XX = 0; XX < imageToFind->width; ++XX)
                    {
                        rgb32* pixel = &imageToFind->pixels[YY * imageToFind->width + XX];
                        rgb32* targetPixel = &info->targetImage->pixels[(YY + I) * info->targetImage->width + (XX + J)];
                        if (pixel->a != 0)
                        {
                            if (!(*info->ctsFuncPtr)(info, pixel, targetPixel))
                            {
                                goto Skip;
                            }
                        }
                    }
                }
                *x = J + x1;
                *y = I + y1;
                return true;
                Skip:
                continue;
            }
        }
        *x = -1;
        *y = -1;
        return false;
    }

    В чём здесь сакральный смысл GoTo?

    Cynicrus, 01 Декабря 2014

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

    +133

    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
    private static List<User> Users
    {
        get
       {
           if (_customers == null) {             _customers = new List<Customer>(); }
            lock (((ICollection)_customers).SyncRoot)
           {
                    return _customers;
           }
    }
    set
      {
          lock (((ICollection)Customer).SyncRoot)
          {
                _customers = value;
           }
       }

    one12351, 27 Ноября 2014

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

    +133

    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
    if (*wpPat == L'\\')
        {
          wpCharStart=wpPat;
          if (++wpPat >= wpMaxPat) goto Error;
    
          if (*wpPat == L'x')
          {
            if (++wpPat >= wpMaxPat) goto Error;
    
            if (*wpPat == L'{')
            {
              wpStrTmp=++wpPat;
              for (;;)
              {
                if (wpPat >= wpMaxPat) goto Error;
                if (*wpPat++ == L'}') break;
              }
              if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
              {
                nPatChar=(int)hex2decW(wpStrTmp, (wpPat - 1) - wpStrTmp);
                if (nPatChar == -1)
                {
                  wpPat=wpStrTmp;
                  goto Error;
                }
                if (nPatChar <= MAXWORD)
                  lpREGroupItem->nGroupLen+=1;
                else
                  lpREGroupItem->nGroupLen+=2;
              }
            }
            else
            {
              if (wpPat + 2 > wpMaxPat)
                goto Error;
              wpPat+=2;
              if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
                ++lpREGroupItem->nGroupLen;
            }
          }
          else if (*wpPat == L'u')
          {
            if (wpPat + 5 > wpMaxPat)
              goto Error;
            wpPat+=5;
            if (lpREGroupItem->nGroupLen != -1 && !bClassOpen)
              ++lpREGroupItem->nGroupLen;
          }

    Регулярные велосипеды.
    Akelpad.

    gost, 25 Ноября 2014

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