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

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    File f = new File(Environment.getExternalStorageDirectory().toString());
                    for (File temp : f.listFiles()) {
                        if (temp.getName().equals("temp.jpg")) {
                            f = temp;
                            break;
                        }
                    }

    Мне больно

    ilsy, 09 Июня 2015

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

    +142

    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
    type
      TForm1 = class(TForm)
        IBDB1: TIBDatabase;
        MainMenu1: TMainMenu;
        N1: TMenuItem;
        N2: TMenuItem;
        IBTransaction1: TIBTransaction;
        Pochtamt: TIBQuery;
        DSOPS: TDataSource;
        Detal: TIBQuery;
        DSDetal: TDataSource;
        IBQuery1: TIBQuery;
        ListBox1: TListBox;
        N3: TMenuItem;
        RabMesto: TIBQuery;
        DSRabMesto: TDataSource;
        IdIPWatch1: TIdIPWatch;
        DBGrid2: TDBGrid;
        Panel1: TPanel;
        Button2: TButton;
        Label2: TLabel;
        Edit1: TEdit;
        Label3: TLabel;
        Label4: TLabel;
        Edit3: TEdit;
        Label5: TLabel;
        Label6: TLabel;
        Edit4: TEdit;
        Button3: TButton;
        PMOPS: TPopupMenu;
        N6: TMenuItem;
        N7: TMenuItem;
        PMRabMesto: TPopupMenu;
        N9: TMenuItem;
        N10: TMenuItem;
        ListBox2: TListBox;
        Label14: TLabel;
        Label15: TLabel;
        Button6: TButton;
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        TabSheet2: TTabSheet;
        Panel2: TPanel;
        Label11: TLabel;
        Label12: TLabel;
        Label13: TLabel;
        Button4: TButton;
        Memo1: TMemo;
        Button5: TButton;
        Edit6: TEdit;
        DBGrid1: TDBGrid;
        Label1: TLabel;
        DBMemo1: TDBMemo;
        Label16: TLabel;
    //    DBGrid2: TDBGrid;
        TabSheet3: TTabSheet;
        N11: TMenuItem;
        Label18: TLabel;
        Label9: TLabel;
        Edit7: TEdit;
        Label10: TLabel;
        MaskEdit1: TMaskEdit;
        MaskEdit2: TMaskEdit;
        TabSheet5: TTabSheet;
        N12: TMenuItem;
        LSostav: TIBQuery;
        DSLSostav: TDataSource;
        DBGrid4: TDBGrid;
        ListBox3: TListBox;
        PMLSostav: TPopupMenu;
        N13: TMenuItem;
        N14: TMenuItem;
        N15: TMenuItem;
        Panel3: TPanel;
        Label22: TLabel;
        Edit2: TEdit;
        Label23: TLabel;
        Edit8: TEdit;
        Label24: TLabel;
        MaskEdit3: TMaskEdit;
        MaskEdit4: TMaskEdit;
        MaskEdit5: TMaskEdit;
        Label25: TLabel;
        Label26: TLabel;
        MaskEdit6: TMaskEdit;
        Label27: TLabel;
        Button7: TButton;
        Button8: TButton;
        Label28: TLabel;
        Edit9: TEdit;
        Label29: TLabel;
        Edit10: TEdit;
        UpDown1: TUpDown;
        Label30: TLabel;
        Edit11: TEdit;
        Edit12: TEdit;
        Label31: TLabel;
        Label32: TLabel;
        Button9: TButton;
        N16: TMenuItem;

    Там еще 400 строк объявления компонентов формы и процедур и функций с аналогичными названиями...

    BotGovnokot, 08 Июня 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public static function compress($data, $options = null)
    {
        return (new static)
            ->html_compress($data, $options);
    }

    Расширяшка для Yii2, экономия байтов
    https://github.com/rmrevin/yii2-minify-view

    Fike, 06 Июня 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    var leftDate = GetAll().Select(i => i.SaveDateTime).OrderBy(i => i).FirstOrDefault();
    var rigthDate = GetAll().Select(i => i.SaveDateTime).OrderByDescending(i => i).FirstOrDefault();
    
    // 1e7 - количество тактов в секунде (а в итоге: проверка разницы в неделю)
    while (rigthDate.Ticks - leftDate.Ticks > 1e7 * 60 * 60 * 24 * 7)
    {
    ....................................
    }

    с точностью до тика.

    andrewiv, 05 Июня 2015

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

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    int a = 0;
    bool is09 = false;
    for(int i=0;i<=9;i++){ //Проверяем каждую от 0 до 9
      if(a == i) { is09 = true; break; } //Если таковым является то true
    }
    
    //И само условие :)
    if(is09){
      //Если 0 - 9
    } else {
      //Если нет
    }

    Зацените такой индуссо-китайский код (да я знаю как правильно), но для прикола

    acterhd, 04 Июня 2015

    Комментарии (2)
  7. Java / Говнокод #18281

    +142

    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
    public int func_175687_A(BlockPos p_175687_1_)
        {
            int var2 = 0;
            EnumFacing[] var3 = EnumFacing.values();
            int var4 = var3.length;
    
            for (int var5 = 0; var5 < var4; ++var5)
            {
                EnumFacing var6 = var3[var5];
                int var7 = this.getRedstonePower(p_175687_1_.offset(var6), var6);
    
                if (var7 >= 15)
                {
                    return 15;
                }
    
                if (var7 > var2)
                {
                    var2 = var7;
                }
            }
    
            return var2;
        }

    Notch видимо не слышал про Math.Max

    GameLoper, 03 Июня 2015

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

    +142

    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 Texture loadTextureFromIntBuffer(int[] data, int width,
            int height)
        {
            // Convert:
            int numPixels = width * height;
            byte[] dataBytes = new byte[numPixels * 4];
            
    ...
            
            // Cleans variables
            dataBytes = null;
            data = null;
            
    ...
        }

    Пример из документации Vuforia SDK под android.
    Давайте поможем GC собрать мусор

    chtulhu, 03 Июня 2015

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

    +142

    1. 1
    if(!(!empty($_REQUEST['sysblock'])||!empty($_REQUEST['module'])))

    sevenflash, 03 Июня 2015

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

    +142

    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
    #include <iostream>
    #include <set> 
    #include <queue>
    #include <iterator>
    #include <algorithm>
    
    using namespace std;
    
    class Complex
    { 
    public: 
    	char a;
    	char b;
    
    public:
    
    	Complex(){}
    
    	Complex(char i, char j)
    	{
    		this->a = i;
    		this->b = j;
    	}
    	
    	
    	friend bool operator < (const Complex& complex1, const Complex& complex2)
    	{
    		return ((complex1.a < complex2.a && complex1.b < complex2.b) || (complex1.a < complex2.a && complex1.b == complex2.b) || (complex1.a == complex2.a && complex1.b < complex2.b));
    	}
    
    	friend bool operator >(const Complex& complex1, const Complex& complex2)
    	{
    		return ((complex1.a > complex2.a && complex1.b > complex2.b) || (complex1.a > complex2.a && complex1.b == complex2.b) || (complex1.a == complex2.a && complex1.b > complex2.b));
    	}
    
    	friend ostream& operator << (ostream& out, Complex const& complex)
    	{
    		out << "First: " << complex.a << " Second: " << complex.b;
    		return out;
    	}
    
    	friend bool operator == (const Complex& complex1, const Complex& complex2)
    	{
    		return ( complex1.a == complex2.a && complex1.b == complex2.b);
    	}
    
    	~Complex()
    	{
    	}
    };

    "Не говнокод, потому что работает" © Автор говнокода

    Giraffe, 02 Июня 2015

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

    +142

    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
    if (filter != null)
                for (FilterItem item : filter.getItems()) {
                    if (StringUtils.isBlank(item.getProperty()) || StringUtils.isBlank(item.getValue())) {
                        log.warn("Skipping wrong filter: {}", PrintHelper.objectToString(item));
                        continue;
                    }
    
                    String property = item.getProperty().trim();
                    String value = item.getValue().trim();
                    
                    if (property.equals(USER_ACCESS_LEVEL)) {
                        this.accessLevelType = Integer.valueOf(value);
                        paramsMap.put("user_access_level_type.id", ":" + USER_ACCESS_LEVEL);
                        valuesMap.put(USER_ACCESS_LEVEL, this.accessLevelType);
                    } if (property.equals(USER_TYPE)) {
                        this.userType = Integer.valueOf(value);
                        paramsMap.put("user_type.id", ":" + USER_TYPE);
                        valuesMap.put(USER_TYPE, this.userType);
                    } if (property.equals(FEDERAL_DISTRICT_ID)) {
                        this.federalDistrictId = Integer.valueOf(value);
                        paramsMap.put("user_org_detail.federal_district_fkey", ":" + FEDERAL_DISTRICT_ID);
                        valuesMap.put(FEDERAL_DISTRICT_ID, this.federalDistrictId);
                    } if (property.equals(CONSTITUENT_ENTITY_ID)) {
                        this.constituentEntityId = Integer.valueOf(value);
                        paramsMap.put("user_org_detail.constituent_entity_fkey", ":" + CONSTITUENT_ENTITY_ID);
                        valuesMap.put(CONSTITUENT_ENTITY_ID, this.constituentEntityId);
                    } if (property.equals(FORESTRY_ID)) {
                        this.forestryId = value;
                        paramsMap.put("user_org_detail.forestry_fkey", ":" + FORESTRY_ID);
                        valuesMap.put(FORESTRY_ID, this.forestryId);
                    } if (property.equals(USER_ROLE_ID)) {
                        this.userRoleId = value;
                        paramsMap.put("user_role.role_fkey", ":" + USER_ROLE_ID);
                        valuesMap.put(USER_ROLE_ID, this.userRoleId);
                    } if (property.equals(USER_LOGIN)) {
                        this.userLogin = value;
                        paramsMap.put("usr.login", ":" + USER_LOGIN);
                        valuesMap.put(USER_LOGIN, "%" + this.userLogin + "%");
                    } if (property.equals(USER_NAME)) {
                        this.userName = value;
    
                        String[] query = this.userName.split(" ");
                        String[] fnamePlaceholders = {};
                        String[] lnamePlaceholders = {};
                        String[] mnamePlaceholders = {};
    
                        for (int i = 0; i < query.length; i++) {
                            String fname = ":first_name_" + i;
                            fnamePlaceholders = ArrayUtils.add(fnamePlaceholders, fname);
                            String lname = ":last_name_" + i;
                            lnamePlaceholders = ArrayUtils.add(lnamePlaceholders, lname);
                            String mname = ":middle_name_" + i;
                            mnamePlaceholders = ArrayUtils.add(mnamePlaceholders, mname);
    
                            valuesMap.put("first_name_" + i, "%" + query[i] + "%");
                            valuesMap.put("last_name_" + i, "%" + query[i] + "%");
                            valuesMap.put("middle_name_" + i, "%" + query[i] + "%");
                        }
    
                        userParams.put("usr.first_name", fnamePlaceholders);
                        userParams.put("usr.last_name", lnamePlaceholders);
                        userParams.put("usr.middle_name", mnamePlaceholders);
                    } if (property.equals(USER_STATUS)) {
                        this.userStatus = value;
                        paramsMap.put("usr.status", ":" + USER_STATUS);
                        valuesMap.put(USER_STATUS, this.userStatus);
                    } if (property.equals(PARTY_NAME)) {
                        this.partyName = value;
                        String[] query = value.split(" ");
                        String[] fnamePlaceholders = {};
                        String[] lnamePlaceholders = {};
                        String[] mnamePlaceholders = {};
    
                        for (int i = 0; i < query.length; i++) {
                            String fname = ":person_first_name_" + i;
                            fnamePlaceholders = ArrayUtils.add(fnamePlaceholders, fname);
                            String lname = ":person_last_name_" + i;
                            lnamePlaceholders = ArrayUtils.add(lnamePlaceholders, lname);
                            String mname = ":person_mid_name_" + i;
                            mnamePlaceholders = ArrayUtils.add(mnamePlaceholders, mname);
    
                            valuesMap.put("person_first_name_" + i, "%" + query[i] + "%");
                            valuesMap.put("person_last_name_" + i, "%" + query[i] + "%");
                            valuesMap.put("person_mid_name_" + i, "%" + query[i] + "%");
                        }
    
                        partyParams.put("party.person_first_name", fnamePlaceholders);
                        partyParams.put("party.person_last_name", lnamePlaceholders);
                        partyParams.put("party.person_mid_name", mnamePlaceholders);
    
                        partyParams.put("party.party_name", new String[]{":party_name"});
                        valuesMap.put("party_name", "%" + this.partyName + "%");
    
                    } if (property.equals(PARTY_INN)) {
                        this.partyInn = value;
                        paramsMap.put("party.inn", ":" + PARTY_INN);
                        valuesMap.put(PARTY_INN, this.partyInn);
                    } if (property.equals(USER_IS_MASTER)) {
                        this.userIsMaster = Boolean.valueOf(value);
                        paramsMap.put("user_org_detail.organization_master", ":" + USER_IS_MASTER);

    конструктор для named jdbc
    ... если долго смотреть на строки, можно увидеть жирафа...

    floppy, 02 Июня 2015

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