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

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

    +70

    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
    @OnEvent("search")
    	@ReportGritter(title = "message:error", text = "message:database_error")
    	Results search() {
    		final List<Result> results = new ArrayList<Result>();
    		int count = 0;
    		final List<?> search1 = this.bands.search(this.query);
    		final String group1 = HSSearch.GROUP_BANDS;
    		if (!search1.isEmpty()) {
    			results.addAll(this.transform(search1, group1));
    			count += search1.size();
    		}
    		final List<?> search2 = this.albums.search(this.query);
    		final String group2 = HSSearch.GROUP_ALBUMS;
    		if (!search2.isEmpty()) {
    			results.addAll(this.transform(search2, group2));
    			count += search2.size();
    		}
    		final List<?> search3 = this.tracks.search(this.query);
    		final String group3 = HSSearch.GROUP_TRACKS;
    		if (!search3.isEmpty()) {
    			results.addAll(this.transform(search3, group3));
    			count += search3.size();
    		}
    		this.results.setResults(results);
    		this.results.setCount(count);
    		return this.results;
    	}
    
    	private <E> String toTitle(final E item) {
    		if (item instanceof BandEntity) {
    			return ((BandEntity) item).getTitle();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return String.format("%s (%d)", aitem.getTitle(), Integer.valueOf(aitem.getYear()));
    		}
    		if (item instanceof TrackEntity) {
    			return ((TrackEntity) item).getTitle();
    		}
    		return item.toString();
    	}
    
    	private <E> String toUrl(final E item) {
    		if (item instanceof BandEntity) {
    			final BandEntity bitem = (BandEntity) item;
    			return this.links.createPageRenderLinkWithContext(Band.class, bitem.getLetter(), bitem.getAlias())
    					.toAbsoluteURI();
    		}
    		if (item instanceof AlbumEntity) {
    			final AlbumEntity aitem = (AlbumEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, aitem.getBand().getLetter(),
    					aitem.getBand().getAlias(), aitem.getAlias()).toAbsoluteURI();
    		}
    		if (item instanceof TrackEntity) {
    			final TrackEntity titem = (TrackEntity) item;
    			return this.links.createPageRenderLinkWithContext(Album.class, titem.getAlbum().getBand().getLetter(),
    					titem.getAlbum().getBand().getAlias(), titem.getAlbum().getAlias()).toAbsoluteURI();
    		}
    		return this.links.createPageRenderLinkWithContext("").toAbsoluteURI();
    	}
    
    	private <E> List<Result> transform(final List<E> search, final String groupName) {
    		final ArrayList<Result> res = new ArrayList<Result>();
    		if (!search.isEmpty()) {
    			final String group = this.messages.get(groupName);
    			res.add(new Result(group));
    			for (final E item : search) {
    				res.add(new Result(group, this.toTitle(item), this.toUrl(item)));
    			}
    		}
    		return res;
    	}

    DRY in Action.
    мое домашнее творчество.

    Lure Of Chaos, 06 Июня 2013

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

    +152

    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
    function CreatePriceListArray($result_array)//TODO:Формирует древовидную форму прайс листа
    {
    		//print_r($result_array);
        $price_list=array();//Жилая недвижимость
        $current_object_name="";
        $current_section_name="none";
        $current_section_id=0;
        $current_object_array=null;
        $current_section_array=null;
        $current_kvartira_type=null;
        $current_kvartira_type_name="";
        $current_kvartira=null;
        $current_kvartira_area="";
        
        foreach($result_array as $value)
        {
            if($current_object_name != $value['object'])
            {
                if($current_object_array !=null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                    $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
                }
                $current_object_array=array();
                $current_object_name=$value['object'];
                $current_section_name="none";
                $current_section_id=0;
                $current_section_array=null;
            }
    
            if($current_section_name != $value['section_name'])
            {
                   // echo $current_kvartira_type['name']; echo ' | ';
                //if($current_kvartira_type['name'] != '') 
                {
                    
                    foreach ($current_kvartira_type as $value)
                    
                    //print_r($current_kvartira_type);
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);                
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                    $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
                }
                $current_section_array=array();
                $current_section_name = $value['section_name'];
                $current_section_id=$value['section_id'];
               // $current_kvartira_type=null;
                $current_kvartira_type_name="";
            }
    
            if($current_kvartira_type_name != $value['kvartira_name'])
            {
               // if($current_kvartira_type != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                    $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
                }
                $current_kvartira_type=array();
                $current_kvartira_type_name = $value['kvartira_name'];
                $current_kvartira=null;
                $current_kvartira_area="";
            }
    
            if($current_kvartira_area != $value['area'])
            {
               // if($current_kvartira != null)
                {
                    $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
                }
                $current_kvartira=array();
                $current_kvartira_area = $value['area'];
            }
            
            $current_kvartira[]=$value['floor'];
        }
    		
    			
           $current_kvartira_type[]=array('name'=>$current_kvartira_area,'count_object'=>count($current_kvartira),'object_array'=>$current_kvartira);
           $current_section_array[]=array('name'=>$current_kvartira_type_name,'count_object'=>count($current_kvartira_type),'object_array'=>$current_kvartira_type);
           $current_object_array[]=array('name'=>$current_section_name,'id'=>$current_section_id,'count_object'=>count($current_section_array),'object_array'=>$current_section_array);
    //echo $current_object_name;        
    if($current_object_name!='') $price_list[]=array('name'=>$current_object_name,'count_object'=>count($current_object_array),'object_array'=>$current_object_array);
    
    echo '<!--';
    print_r($price_list);
    echo '-->';
        return $price_list;    
    }

    Пытаюсь тут что-то найти... Идет второй час.

    ghz, 04 Июня 2013

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

    −89

    1. 1
    2. 2
    const char *aPositionCString = [@"a_position" cStringUsingEncoding:NSUTF8StringEncoding];
    GLuint aPosition = glGetAttribLocation(program, aPositionCString);

    Вместо того, чтобы написать так:
    GLuint aPosition = glGetAttribLocation(program, "a_position");

    zummenix, 03 Июня 2013

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

    +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
    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
    public CommandResult update() {
                CommandResult res = null;
                try {
                    long start = System.nanoTime();
                    res = _port.runCommand(_mongo.getDB("admin"), isMasterCmd);
                    long end = System.nanoTime();
                    float newPingMS = (end - start) / 1000000F;
                    if (!successfullyContacted)
                        _pingTimeMS = newPingMS;
                    else
                        _pingTimeMS = _pingTimeMS + ((newPingMS - _pingTimeMS) / latencySmoothFactor);
    
                    getLogger().log(Level.FINE, "Latency to " + _addr + " actual=" + newPingMS + " smoothed=" + _pingTimeMS);
    
                    successfullyContacted = true;
    
                    if (res == null) {
                        throw new MongoInternalException("Invalid null value returned from isMaster");
                    }
    
                    if (!_ok) {
                        getLogger().log(Level.INFO, "Server seen up: " + _addr);
                    }
                    _ok = true;
    
                    // max size was added in 1.8
                    if (res.containsField("maxBsonObjectSize")) {
                        _maxBsonObjectSize = (Integer) res.get("maxBsonObjectSize");
                    } else {
                        _maxBsonObjectSize = Bytes.MAX_OBJECT_SIZE;
                    }
                } catch (Exception e) {
                    if (!((_ok) ? true : (Math.random() > 0.1))) {
                        return res;
                    }
    
                    final StringBuilder logError = (new StringBuilder("Server seen down: ")).append(_addr);
    
                    if (e instanceof IOException) {
    
                        logError.append(" - ").append(IOException.class.getName());
    
                        if (e.getMessage() != null) {
                            logError.append(" - message: ").append(e.getMessage());
                        }
    
                        getLogger().log(Level.WARNING, logError.toString());
    
                    } else {
                        getLogger().log(Level.WARNING, logError.toString(), e);
                    }
                    _ok = false;
                }
    
                return res;
            }

    https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/ConnectionStatus.java

    Незаметен.

    serpinski, 31 Мая 2013

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

    +65

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // вот такой вот паттерн инициализации статических переменных во всех классах проекта... 
    private static Properties globalProps = null;
    
    static {
            globalProps = new Properties();
    }

    вот такой вот паттерн инициализации статических переменных во всех классах проекта...ин-лайн инициализацию автору делать почему то не хотелось...и ведь вроде не индус писал, а белый человек...

    aa_kovalev, 29 Мая 2013

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

    +130

    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
    Class barcode
    	...
    	Dim CharData
    
    	Dim CharNumber
    
    	Public Function GetHTMLBar(BarData  ,  BarHeight  )
    		...
    		For lop = 1 To Len(x)
    			For s = 0 To UBound(CharData)
    					...
    					tsum = tsum + (CLng(CharNumber(s)) * lop)
    					...
    				End If
    			Next 
    		Next 
    	End Function
    
    	Private Sub Class_Initialize()
    		CharNumber = Split("0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106", ",")
    		...
    	End Sub
    End class

    VBScript.
    Массив, содержащий собственные индексы?

    slbsomeone, 24 Мая 2013

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

    +150

    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
    function deleteDublicateItems(){
        $q = '
        select COUNT(*), id, vk_id
        from `items`
        group by `vk_id`
        having COUNT(*) > 1';
        $sql = mysql_query($q);
        
        if (mysql_num_rows($sql)){	
    	while($row = mysql_fetch_assoc($sql)){
    	    $sql2 = mysql_query('select * from `items` where `vk_id` = "'.$row['vk_id'].'" and `id` != "'.$row['id'].'"');
    	    
    	    if (mysql_num_rows($sql2)) {
    		while($row2 = mysql_fetch_assoc($sql2)) {
    		    $sql3 = mysql_query('select * from `images` where `item_id` = "'.$row2['id'].'"');
    		    
    		    if (mysql_num_rows($sql3)) {
    			while ($row3 = mysql_fetch_assoc($sql3)) {
    			    @unlink( ROOT . DS . 'uploads' . DS . 'images' . DS . $row3['name'] . '.' . $row3['ext']);
    			    mysql_query('delete from `images` where `id` = "'.$row3['id'].'"');
    			}
    		    }		    
    		    mysql_query('delete from `items` where `id` = "'.$row2['id'].'"');
    		}
    	    }
    	}
        }
    }

    удаление дубликатов

    Serious_Andy, 22 Мая 2013

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    (function() {
        (function init() {
            document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
        })();
    })();
    
    function DOMContentLoaded() {
        //...
    }

    И да, jQuery подключена на странице.

    madhead, 13 Мая 2013

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

    +17

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #include<iostream>
    using namespace std;
    int main(){
    	int n,a[100100],d[100100],ans=d[0]=1,i,j;
    	cin>>n>>a[0];
    	for(i = 1;i<n;++i)
    		for(j =i-1,cin>>a[i],d[i]=1;j>=0;--j) 
    			if(a[i]>a[j]) ans = max(ans, d[i]=max(d[i],d[j]+1));
    	cout<<ans;
    }

    Решение задачи нахождения НВП (наибольшей возр. подпосл-ти)

    AvadaKedavra, 26 Апреля 2013

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

    +137

    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
    if (curMenu != null)
    {
      depth = curMenu.Depth;
      Menu menuG = null;
      if (depth == 1)
      {
        menuG = curMenu;
      }
      if (depth == 2)
      {
        menuG = curMenu.Menu2;
      }
      if (depth == 3)
      {
        menuG = curMenu.Menu2.Menu2;
      }
      if (depth == 4)
      {
        menuG = curMenu.Menu2.Menu2.Menu2;
      }
      if (depth == 5)
      {
        menuG = curMenu.Menu2.Menu2.Menu2.Menu2;
      }
      if (depth == 6)
      {
        menuG = curMenu.Menu2.Menu2.Menu2.Menu2.Menu2;
      }
      if (depth == 7)
      {
        menuG = curMenu.Menu2.Menu2.Menu2.Menu2.Menu2.Menu2;
      }
      if (depth == 8)
      {
        menuG = curMenu.Menu2.Menu2.Menu2.Menu2.Menu2.Menu2.Menu2;
      }
    }

    Nested set для петухов!

    validol, 19 Апреля 2013

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