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

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

    +49

    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
    #include <stdio.h>
    #include <math.h>
    #include "determinant.h"
    
    double det(double **matrix, int size)
    {
        if(size==2)
        {
            return matrix[0][0]*matrix[1][1]-matrix[0][1]*matrix[1][0];
        }
        else if(size==1)
            {
                return matrix[0][0];
            }
        int result = 0;
        for(int j=0; j<size; j++)
        {
            if(matrix[0][j]!=0)
            {
                result+=matrix[0][j]*(unsigned)pow(-1.f,(unsigned)j)*det(minor(matrix, size, 0, j), size-1);
            }
        }
        return result;
    }
    
    double **minor(double **matrix, int size, int str, int col)
    {
        double **minor=new double *[size-1];
        int m_str = 0;
        int m_col;
        for(int i=0; i<size; i++)
        {
            if(i!=str)
            {
                m_col = 0;
                minor[m_str]=new double[size-1];
                for(int j=0; j<size; j++)
                {
                    if(j!=col)
                    {
                        minor[m_str][m_col]=matrix[i][j];
                        m_col++;
                    }
                }
                m_col++;
            }
        }
        return minor;
    }

    Считаю определитель рекурсией, во время теста в этом сорце вылетает ошибка EXC_BAD_ACCESS(code=1, access=0x8),
    после одного прохода рекурсии, с чем это связано? Помогите разобраться :)

    aesc_smirnov, 07 Декабря 2014

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

    −396

    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
    @implementation SlideMenuNavigationBar
    
    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        for (UIView *aView in self.subviews) {
            
            // Correcting menu toggle button position
            if ([[aView.class description] isEqualToString:@"UIButton"] && aView.frame.origin.x < self.frame.size.width/2) {
                CGRect frame = aView.frame;
                frame.origin.x = 12; // 8 for correlation
                frame.origin.y = -1; // 1 for correlation
                aView.frame = frame;
            }
            
            if (aView.frame.origin.x > self.frame.size.width/2 && !isIPad && ![[aView.class description] isEqualToString:@"ColoredView"]) {
                CGRect frame = aView.frame;
                frame.origin.x = 260; // 8 for correlation
                frame.origin.y = -1;  // 1 for correlation
                aView.frame = frame;
            }
            
            // Correcting back button and right button positions
            if ([[aView.class description] isEqualToString:@"_UINavigationBarBackIndicatorView"]) {
                CGRect frame = aView.frame;
                frame.origin.y = [self.class navigationBarHeight] - kDefaultNavigationBarHeight + 5; // 5 for correlation
                aView.frame = frame;
            }
            if ([[aView.class description] isEqualToString:@"UINavigationButton"]) {
                CGRect frame = aView.frame;
                frame.origin.y = [self.class navigationBarHeight] - kDefaultNavigationBarHeight + 2; // 2 for correlation
                aView.frame = frame;
            }
            
            if ([aView isKindOfClass:[NavigationBarButton class]]) {
                CGRect frame = aView.frame;
                frame.origin.x = 278; // 8 for correlation
                frame.origin.y = 6;   // 1 for correlation
                aView.frame = frame;
            }
        }
    }
    
    @end

    фиг знает что думали :D

    l0gg3r, 11 Ноября 2014

    Комментарии (6)
  4. ActionScript / Говнокод #17062

    −91

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    [Embed(source = "/assets/video_preview/VideoSlideThumb.png")]
    public static const VIDEO_PREVIEW: Class;
    
    public static function get videoPreviewBD(): BitmapData
    {
    	var image : Bitmap = new VIDEO_PREVIEW ();
    	return image.bitmapData.clone();		
    }

    Когда-то давно бытовала такая пословица: What Intel giveth Microsoft taketh away. Но похоже что переходное красное знамя подхватили и в других организациях по-меньше.

    wvxvw, 04 Ноября 2014

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

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public new string ID
    {
    	get
    	{
    		return base.ID;
    	}
    	set
    	{
    		base.ID = value;
    	}
    }

    taburetka, 24 Октября 2014

    Комментарии (6)
  6. Java / Говнокод #16913

    +117

    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
    @Override
    public void afterPersistenceInit() {
    	val conn = emProvider.get().unwrap(Connection.class);
    
    	try {
    		log.info("Transaction isolation level: {}", getLevelString(conn.getTransactionIsolation()));
    	} catch (final SQLException e) {
    		log.error("Error getting transaction isolation level", e);
    	}
    }
    
    private String getLevelString(final int isolationLevel) {
    	// Poor man's enums. Use reflection to find a constant with the given value
    	try {
    		for (val maybeLevelConstant: Connection.class.getDeclaredFields()) {
    			if (maybeLevelConstant.getType() == int.class && maybeLevelConstant.getName().startsWith("TRANSACTION_")
    					&& maybeLevelConstant.getInt(null) == isolationLevel) {
    				return maybeLevelConstant.getName();
    			}
    		}
    	} catch (final IllegalArgumentException | IllegalAccessException e) {
    		return "UNKNOWN";
    	}
    	
    	return "UNKNOWN";
    }

    Ищем рефлексией константу с нужным значением. И всё для того, чтобы напечатать её в логе. Вот что крест животворящий отсутствие энумов в legacy API делает.

    someone, 23 Октября 2014

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

    +117

    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
    @Nullable
    public static BigDecimal getWidth(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallWidth();
    	case M:
    		return spec.getMediumWidth();
    	case L:
    		return spec.getLargeWidth();
    	default:
    		throw new AssertionError();
    	}
    }
    
    @Nullable
    public static BigDecimal getHeight(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallHeight();
    	case M:
    		return spec.getMediumHeight();
    	case L:
    		return spec.getLargeHeight();
    	default:
    		throw new AssertionError();
    	}
    }
    
    public static BigDecimal getDiameter(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallDiameter();
    	case M:
    		return spec.getMediumDiameter();
    	case L:
    		return spec.getLargeDiameter();
    	default:
    		throw new AssertionError();
    	}
    }
    
    @Nullable
    public static BigDecimal getWeight(final ITagSpecification spec, final TagSize size) {
    	switch (size) {
    	case S:
    		return spec.getSmallWeight();
    	case M:
    		return spec.getMediumWeight();
    	case L:
    		return spec.getLargeWeight();
    	default:
    		throw new AssertionError();
    	}
    }

    Бойлерплейт - он такой. А можно ли с JPA это как-то изящнее сделать? Дело в том, что {small|medium|large}{Width|Height|Diamet er|Weight} - это двенадцать столбцов таблицы в БД. Пока единственное, что приходит на ум - это сделать три одинаковых @Embedded'а на каждый размер.

    someone, 19 Октября 2014

    Комментарии (6)
  8. PHP / Говнокод #16882

    +158

    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
    if($mark['data']){
         switch ($mark['data']->point) {
         case '0':
             $table.= "незачет";
             break;
         case '1':
             $table.= "зачет";
             break;
         case '2':
             $table.=  "неудовлетворительно";
             break;
         case '3':
             $table.=  "удовлетворительно";
             break;
         case '4':
             $table.=  "хорошо";
             break;
         case '5':
             $table.=  "отлично";
             break;
            
         default:
             $table.=  "";
             break;
        }
    }else{
        $table.=  "";
    }

    saksmt, 17 Октября 2014

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

    +158

    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
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    $table = "<w:tbl>";
    $table .='<w:tblPr>
                <w:tblW w:w="0" w:type="auto"/>
                <w:jc w:val="center"/>
                <w:tblBorders>
                    <w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                    <w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/>
                </w:tblBorders>
                <w:tblLook w:val="04A0" w:firstRow="1" w:lastRow="0" w:firstColumn="1" w:lastColumn="0" w:noHBand="0" w:noVBand="1"/>
            </w:tblPr>';
    $table .= "<w:tblGrid>
        <w:gridCol w:w='800'/>
        <w:gridCol w:w='3700'/>
        <w:gridCol w:w='2000'/>
        <w:gridCol w:w='1757'/>
        <w:gridCol w:w='1000'/>
        <w:gridCol w:w='1000'/>
    </w:tblGrid>";
    $table .= "<w:tr>";
    $table .='
    <w:trPr>
        <w:jc w:val="center"/>
    </w:trPr>
    ';
    $table .= "<w:tc>";
    $table .= "<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>"; 
    $table .= "<w:t>";
    $table .= "№ п/п";
    $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                <w:cantSplit/>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr><w:t>";
        $table .= "Фамилия, И.О. студента";
        $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr><w:t>";
        $table .= "Номер билета";
        $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr>
                </w:pPr>
                <w:r w:rsidRPr='003D674F'>
                    <w:rPr>
                        <w:sz w:val='24'/>
                        <w:szCs w:val='24'/>
                    </w:rPr><w:t>";
        $table .= "Оценка* прописью";
        $table .= "</w:t></w:r></w:p></w:tc>";
    
        $table .= "<w:tc>"; 
        $table.="<w:p w14:paraId='22B64392' w14:textId='77777777' w:rsidR='00D55405' w:rsidRPr='003D674F' w:rsidRDefault='003D674F' w:rsidP='00D55405'>
                <w:pPr>
                    <w:rPr>
    // ... over200 LOC

    Это контроллер, чтоб вы знали...

    saksmt, 17 Октября 2014

    Комментарии (6)
  10. PHP / Говнокод #16860

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function viplogin() {
        global $lang, $userrec;
        $ret="<div class=viplogin>".array_pop($var1=mqfa("select id, mixtxt$lang from txts where name='viplogin'")).(!INADMIN?"":"<input style=\"width:35px;\" type=button class=\"changebtn\" value=\"Edit 721\" onclick=\"window.open('edit.php?table=txts&id=$var1[id]&&'+Math.random(),'_blank','toolbar=0, scrollbars=1, resizable=1, width=653, height=620');\">")."</div>".($userrec["local"] || $userrec["isadmin"]?"<a href=# onclick=\"window.open('txted.php?lang=$lang&id=$var1[id]','_blank','width=700, height=500')\">edit</a>":"");
        $ret.="<center><a href=\"".echolink("lang=$lang&page=buyvip")."\">".echoword2("buyvip")."</a></center>";
        return $ret;
    }

    как правильно логинить важных пользователей

    afwbkbc, 15 Октября 2014

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

    −112

    1. 1
    `dirname $1`"/"`basename $1 | sed "s/\.squashfs//"`

    шелл. обрезаем расширение имени файла (заданого в $1). хергештельт ин дойчланд.

    Dummy00001, 15 Октября 2014

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