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

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

    −165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    delete
        from liaison
    where
        type = 'UsersGroup' and
        `group` = 'static_' || (select id from usergroup where name = :grp)

    Час назад вынес этим запросом все связи между группами и юзерами в боевой базе ;)

    P.S. Почему в mysql все дерьмо, работающее совсем не так, как оно работает почти во всех остальных СУБД, включено по умолчанию?

    bormand, 22 Мая 2013

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

    +160

    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
    $query = "INSERT INTO analiz SET
        obegin = $duss,
        vbegin = $leas,
        lbegin = $duls,
        opodk  = $dusc,
        vpodk  = $leac,
        lpodk  = $dulc,
        oend   = $duse,
        vend   = $leae,
        lend   = $dule,
        ozatr  = $dusZ,
        vzatr  = $leaZ,
        lzatr  = $dulZ,
        ooplat = $dusU,
        voplat = $leaU,
        loplat = $dulU,
        opay   = $dusN,
        vpay   = $leaN,
        lpay   = $dulN,
        date   = '$dnow'";

    cOde = $pzDc

    rsvasilyev, 02 Апреля 2013

    Комментарии (23)
  4. Java / Говнокод #12810

    +86

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    @Override
    public boolean equals(Object obj)
    {
       return obj != null && obj.equals(this);
    }

    SSSandman, 26 Марта 2013

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

    +140

    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
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    [WebMethod]
            public void runCompareService(string mAuthToken, int documentId, int origVerNum, int revisedVerNum)
            {
                //string result = null;
                DirectoryInfo tmpDirInfo = getTempDirectoryPath(documentId);
                try
                {
                    //authToken = authClient.AuthenticateUser(username, password);
                    authToken = mAuthToken;
                    otAuth.AuthenticationToken = authToken;
    
                    try
                    {
                        string origFilePath = String.Format(tmpFilePath, tmpDirInfo.ToString(), origVerNum);
                        string revisedFilePath = String.Format(tmpFilePath, tmpDirInfo.ToString(), revisedVerNum);
                        string resultFilePath = String.Format(tmpResFilePath, tmpDirInfo.ToString(), origVerNum, revisedVerNum);
    
                        string origContextId = getDocContextId(documentId, origVerNum);
                        string revisedContextId = getDocContextId(documentId, revisedVerNum);
    
                        try
                        {
                            downlodFileByContextId(origContextId, origFilePath);
                            downlodFileByContextId(revisedContextId, revisedFilePath);
                            try
                            {
                                doCompare(origFilePath, revisedFilePath, resultFilePath);
                                try
                                {
                                    DownloadToBrowser(resultFilePath);
                                    
                                    //uploadResultToCS(targetId, resultFilePath);
                                }
                                catch (Exception e)
                                {
                                    throw new Exception(String.Format("Failed to Download To Browser. Error: {0}", e.ToString()));
                                }
                            }
                            catch (Exception e)
                            {
                                throw new Exception(String.Format("Failed to do compare method . Error: {0}", e.ToString()));
                            }
                        }
                        catch (Exception e)
                        {
                            throw new Exception(String.Format("Failed to create and download file. Error: {0}", e.ToString()));
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Failed to get Context ID for version Exeption details: " + e.ToString());
                    }
    
                }
                catch (Exception e)
                {
                    throw new Exception("Failed to auth user. Exeption details: " + e.ToString());
                }
                finally
                {
                    docManClient.Close();
                    contentServiceClient.Close();
                    if (Directory.Exists(tmpDirInfo.ToString()))
                    {
                        tmpDirInfo.Delete(true);
                    }
                }
                
            }

    Landing, 04 Марта 2013

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

    +138

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    /// <summary>
            /// Преобразование системных наименований клавиш в "понятные пользователю"
            /// </summary>
            /// <param name="key">Нажатая системная клавиша</param>
            /// <returns>Понятное представление</returns>
            public static string ReplaceKeyCode(System.Windows.Forms.Keys key)
            {
                switch (key)
                {
                    case Keys.OemQuestion: return "'?'";
                    case Keys.OemOpenBrackets: return "'{'";
                    case Keys.Oemtilde: return "'~'";
                    case Keys.Next: return "PageDown";
                }
                switch (key)
                {
                    case Keys.A: return "A";
                    case Keys.Add: return "Num'+'";
                    case Keys.Alt: return "Alt";
                    case Keys.B: return "B";
                    case Keys.Back: return "Backspace";
                    case Keys.C: return "C";
                    case Keys.Cancel: return "Cancel";
                    case Keys.Clear: return "Clear";
                    case Keys.ControlKey: return "Ctrl";
                    case Keys.D: return "D";
                    case Keys.D0: return "0";                case Keys.D1: return "1";                case Keys.D2: return "2";                case Keys.D3: return "3";
                    case Keys.D4: return "4";                case Keys.D5: return "5";                case Keys.D6: return "6";                case Keys.D7: return "7";
                    case Keys.D8: return "8";                case Keys.D9: return "9";                case Keys.Decimal: return "Num'.'";
                    case Keys.Delete: return "Delete";
                    case Keys.Divide: return "Num'/'";
                    case Keys.Down: return "Down";
                    case Keys.E: return "E";
                    case Keys.End: return "End";
                    case Keys.Escape: return "Esc";
                    case Keys.F: return "F";
                    case Keys.F1: return "F1";
                    case Keys.F10: return "F10";
                    case Keys.F11: return "F11";
                    case Keys.F12: return "F12";
                    case Keys.F2: return "F2";
                    case Keys.F3: return "F3";
                    case Keys.F4: return "F4";
                    case Keys.F5: return "F5";
                    case Keys.F6: return "F6";
                    case Keys.F7: return "F7";
                    case Keys.F8: return "F8";
                    case Keys.F9: return "F9";
                    case Keys.G: return "G";
                    case Keys.H: return "H";
                    case Keys.Home: return "Home";
                    case Keys.I: return "I";
                    case Keys.Insert: return "Insert";
                    case Keys.J: return "J";
                    case Keys.K: return "K";
                    case Keys.L: return "L";
                    case Keys.M: return "M";
                    case Keys.N: return "N";
                    case Keys.Next: return "Next";
                    case Keys.NumPad0: return "Num0";
                    case Keys.NumPad1: return "Num1";
                    case Keys.NumPad2: return "Num2";
                    case Keys.NumPad3: return "Num3";
                    case Keys.NumPad4: return "Num4";
                    case Keys.NumPad5: return "Num5";
                    case Keys.NumPad6: return "Num6";
                    case Keys.NumPad7: return "Num7";
                    case Keys.NumPad8: return "Num8";
                    case Keys.NumPad9: return "Num9";
                    case Keys.O: return "O";
                    case Keys.Oem1: return "';'";
                    case Keys.Oem5: return "'/'";
                    case Keys.Oem6: return "'{'";
                    case Keys.Oem7: return "\"";
                    case Keys.OemMinus: return "'-'";
                    case Keys.OemPeriod: return "'>'";
                    case Keys.Oemcomma: return "'<'";
                    case Keys.Oemplus: return "'+'";
                    case Keys.P: return "P";
                    case Keys.PageUp: return "PageUp";
                    case Keys.Q: return "Q";
                    case Keys.R: return "R";
                    case Keys.S: return "S";
                    case Keys.ShiftKey: return "Shift";
                    case Keys.Space: return "Space";
                    case Keys.Subtract: return "Num'-'";
                    case Keys.T: return "T";
                    case Keys.Tab: return "Tab";
                    case Keys.U: return "U";
                    case Keys.Up: return "Up";
                    case Keys.V: return "V";
                    case Keys.W: return "W"; 
                    case Keys.X: return "X";
                    case Keys.Y: return "Y";
                    case Keys.Z: return "Z";
                    case Keys.Menu: return "Alt";
                    case Keys.Multiply: return "Num'*'";
                    default: return string.Empty;
                }
            }

    HLW, 02 Марта 2013

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

    +16

    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
    BOOL EnsureThreadIsSuspended (HANDLE hThread, Thread* pThread)
    {
        STATIC_CONTRACT_NOTHROW;
        STATIC_CONTRACT_GC_NOTRIGGER;
    
        WRAPPER_CONTRACT;
    
        CONTEXT ctx;
        ctx.ContextFlags = CONTEXT_INTEGER;
        BOOL ret;
        ret = ::GetThreadContext(hThread, &ctx);
    
        return ret;
    }

    А ведь и правда, никто не гарантирует, что поток будет остановлен к тому моменту, когда SuspendThread() вернет управление...

    Ccik, 06 Февраля 2013

    Комментарии (23)
  8. Java / Говнокод #12507

    +77

    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
    public static long[] intArrayToLongArray(int[] in) {
        long[] out = new long[in.length];
        for (int i=0, n=in.length; i<n; i++)
            out[i] = in[i];
        return out;
    }
    
    public static void vibrateByResource(Context context, int resId) {
        Vibrator vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
        long[] pattern = intArrayToLongArray(context.getResources().getIntArray(resId));
        vibrator.vibrate(pattern, -1);
    }
    
    vibrateByResource(this, R.array.vibroPatternSuccess);

    vibrate() принимает только long[], но не int[], в ресурсах могут храниться только int[] но не long[]. В результате родился вот такой говнокодик.

    bormand, 30 Января 2013

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

    +13

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    void SetInterruptHandler(int id, unsigned int offset) {
            __asm cli;
            unsigned int *idt = (unsigned int*)0;
            idt[id*2+0] = 0x00080000 | (offset & 0x0000FFFF);
            idt[id*2+1] = 0x00008E00 | (offset & 0xFFFF0000);
            __asm sti;
    }

    Как и обещал в http://govnokod.ru/12413#comment166763, выкладываю исходник говнолоадера, запускающего 32-х битный сишный код с дискетки: https://github.com/bormand/tryos, хотя судя по всему никому это не интересно...

    Если кому-то все-таки придет в голову странное желание это собрать - нужна вижуалка (к сожалению код написан лет 5 назад, когда я юзал вижуалку) и nasm. Путь к nasm прописываем в Makefile, запускаем nmake, полученный floppy.dsk можно скормить виртуалбоксу, или же зарезать на дискету, если удастся вспомнить как она выглядит...

    UPD: Скрин http://rghost.ru/43035733.view

    bormand, 14 Января 2013

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

    +23

    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 <iostream>
    using namespace std;
     
    class Class {
    public:
        explicit Class(int a) : m_int(a) {}
        
        int get() const { return m_int; }
        
        void swapThis(int a) {
            delete this;
            Class **thisptr = reinterpret_cast<Class**>(&a);
            thisptr--;
            *thisptr = new Class(a);
            cout << "this: " << this << endl
                 << "that: " << *thisptr << endl;
        }
    private:
        int m_int;
    };
     
    int main() {
        Class *s = new Class(13);
        s->swapThis(42);
        cout << s->get() << endl;
        delete s;
        
        return 0;
    }

    Что творит хакингкостылинг + инлайн методы.
    http://ideone.com/5Kyitw

    Elvenfighter, 29 Декабря 2012

    Комментарии (23)
  11. Java / Говнокод #12303

    +65

    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
    public TransportEntry getTransportEntry(int transportId) {
    		TransportEntry result = null;
    		AbstractTransport transport = TransportManager.getInstance(getActivity()).getTransportById(transportId);
    
    		if (mTransports == null || transport == null)
    			return null;
    
    		int count = mTransports.size();
    		for (int i = 0; i < count; i++) {
    			final TransportEntry entry = mTransports.get(i);
    			if (entry.getTransportId() == transportId) {
    				// нашли нужный транспорт. вернем его, если что...
    				result = entry;
    				// если он еще и онлайн - то сразу возвращаем - самое подходящее
    				if (transport.isUserOnline(entry.getData()))
    					return result;
    			}
    		}
    		return result;

    Если что...

    dkunin, 17 Декабря 2012

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