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

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

    +74

    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
    public class FSMSmilesMatcher {
    	private Callback mCallback;
    	private State mStartState;
    	
    	public interface Callback {
    		public void onMatch(int matchStart, int matchEnd, int matchId);
    	}
    	
    	//matching whole leading substring cause it's easier to build that way
    	private class State {
    		protected HashMap<String, State> substates; //substring which led to this state + next symbol
    		protected String whole; //whole match
    		protected int matchId;
    		
    		//result = symbols to skip before starting next match
    		protected int process(String input, int matchStart, int matchEnd) {
    			if(matchStart >= input.length() || matchStart >= matchEnd)
    				return 0;
    			if(substates == null) {
    				if(whole == null || whole.length() == 0) {
    					return 0; //shouldn't happen
    				} else if(input.length() >= matchStart + whole.length() && input.substring(matchStart, matchStart + whole.length()).equals(whole)) {
    					mCallback.onMatch(matchStart, matchStart + whole.length(), matchId);
    					return whole.length()> 1 ? whole.length() - 1: 0;
    				}
    			} else if(matchEnd <= input.length()) {
    				State nextState = substates.get(input.substring(matchStart, matchEnd));
    				if(nextState != null)
    					return nextState.process(input, matchStart, matchEnd + 1);
    			}
    			return 0;
    		}
    	}
    	
    	//checks only next symbol
    	//removes long tails (into single 'whole' match)
    	private class OptimizedState extends State{
    		private OptimizedState(State inState) {			
    			if(inState.substates != null) {
    				this.substates = new HashMap<String, State>();
    				for(String key : inState.substates.keySet()) {
    					this.substates.put(key.substring(key.length()-1, key.length()).toLowerCase(), new OptimizedState(inState.substates.get(key)));
    				}				
    				if(this.substates.size() == 1) {
    					State subState = this.substates.values().iterator().next();
    					if(subState.substates == null) {
    						this.substates = null;
    						this.whole = subState.whole;
    						this.matchId = subState.matchId;
    					}
    				}
    			} else {
    				this.whole = inState.whole;
    				this.matchId = inState.matchId;
    			}
    		}
    		
    		@Override
    		protected int process(String input, int matchStart, int matchEnd) {
    			if(matchStart >= input.length() || matchStart >= matchEnd)
    				return 0;
    			if(substates == null) {
    				if(whole == null || whole.length() == 0) {
    					return 0; //shouldn't happen
    				} else if(input.length() >= matchStart + whole.length() && input.substring(matchStart, matchStart + whole.length()).equalsIgnoreCase(whole)) {
    					mCallback.onMatch(matchStart, matchStart + whole.length(), matchId);
    					return whole.length()> 1 ? whole.length() - 1: 0;
    				}
    			} else if(matchEnd <= input.length()) {
    				State nextState = substates.get(input.substring(matchEnd - 1, matchEnd).toLowerCase());
    				if(nextState != null)
    					return nextState.process(input, matchStart, matchEnd + 1);
    			}
    			return 0;
    		}
    	}
    
    	...	
    
    	private HashMap<String, State> generateSubstates(List<ImageMatchElement> matches, String lead) {
    		List<String> variants = new ArrayList<String>();
    		HashMap<String, Integer> completeMatches = new HashMap<String, Integer>();
    		
    		...		
    
    		if(variants.size() == 0) {
    			return null;
    		} else {
    			HashMap<String, State> substates = new HashMap<String, State>();
    			for(String variant: variants) {
    				State state = new State();
    				if(completeMatches.containsKey(variant)) {
    					state.whole = variant;
    					state.matchId = completeMatches.get(variant);
    				} else {
    					state.substates = generateSubstates(matches, variant);
    				}
    				substates.put(variant, state);
    			}
    		...

    Требовалось заменить коды смайликов в текстовом сообщении заменить на соответствующие картинки (типа ":* привет :-p ^_^" заменить на "[картинка] привет [картинка] [картинка]".

    enikey87, 09 Апреля 2012

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

    +167

    1. 1
    unlink(__FILE__);

    __proto__, 03 Апреля 2012

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

    +134

    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
    /* страйкер, почини trim */
      while (1)
        {
          file_ptr start;
          int i;
          long c;
    
          /* See if the next `string_min' chars are all graphic chars.  */
        tryline:
          if (stop_point && address >= stop_point)
    	break;
          start = address;
          for (i = 0; i < string_min; i++)
    	{
    	  c = get_char (stream, &address, &magiccount, &magic);
    	  if (c == EOF)
    	    {
    	      free (buf);
    	      return;
    	    }
    	  if (! STRING_ISGRAPHIC (c))
    	    /* Found a non-graphic.  Try again starting with next char.  */
    	    goto tryline;
    	  buf[i] = c;
    	}

    Раз уж вспоминаем дрѣвния говны

    Written by Richard Stallman <[email protected]>
    and David MacKenzie <[email protected]>.

    bugmenot, 26 Марта 2012

    Комментарии (11)
  5. PHP / Говнокод #9745

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $version = (int)$_GET['version'];
    	
    	if (!empty($version))
    	{
    		$version = '1.4.6.2';
    	}
    	else
    	{
    		$version = '1.4.6.2';
    	}

    Ну и на кой?

    ibnLoky, 23 Марта 2012

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

    −122

    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
    var daytoday:String;
    var today = new Date();
    var monthtoday;
    var year = today.getFullYear(); 
    var timer:Timer = new Timer(1000);
    timer.addEventListener(TimerEvent.TIMER, clock);
    timer.start();
    function clock(e:TimerEvent):void {
       var datetoday:Date=new Date();
       switch (datetoday.day) {
           case 0:
           daytoday="ВОСКРЕСЕНЬЕ";
           break;
           case 1:
           daytoday="ПОНЕДЕЛЬНИК";
           break;
           case 2:
           daytoday="ВТОРНИК";
           break;
           case 3:
           daytoday="СРЕДА";
           break;
           case 4:
           daytoday="ЧЕТВЕРГ";
           break;
           case 5:
           daytoday="ПЯТНИЦА";
           break;
           case 6:
           daytoday="СУББОТА";
           break;
       }
       дэй_оф_вик.text=String(daytoday);
     
       switch (datetoday.month) {
           case 0:
           monthtoday="Января";
           break;
           case 1:
           monthtoday="Февраля";
           break;
           case 2:
           monthtoday="Марта";
           break;
           case 3:
           monthtoday="Апреля";
           break;
           case 4:
           monthtoday="Мая";  
           break;  
           case 5:  
           monthtoday="Июня";
           break;
           case 6:
           monthtoday="Июля";
           break;
           case 7:
           monthtoday="Августа";
           break;
           case 8:
           monthtoday="Сентября";
           break;
           case 9:
           monthtoday="Октября";
           break;
           case 10:
           monthtoday="Ноября";
           break;
           case 11:
           monthtoday="Декабря";
           break;
       }
       month.text=String(monthtoday);  
       day.text=String(datetoday.date);
       data_txt.text = year;
    }

    Мне больше всего нравится 33 строка...

    kyzi007, 18 Марта 2012

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

    +994

    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
    int main()
    {   
       //выводит на экран среднее арифметическое чисел 1, 3, 5
       std::cout << Mean + 1 + 3 + 5 << std::endl;
       //выводит на экран среднее геометрическое чисел 2, 4, 8
       std::cout << Mean * 2 * 4 * 8 << std::endl;
    }
    
    //реализация
    
    class CMean
    {
       mutable double out;
       mutable size_t cnt;
       mutable size_t type;
    public:
       CMean(): out(0), cnt(0), type(-1)  {}
       CMean& operator + (double n)
       {
          return type = 0, out+= n, ++cnt, *this;   
       }
       CMean& operator * (double n)
       {   
          return (type == (size_t)-1 ? type = 1, out = 1 : 0), out*= n, ++cnt, *this;   
       }
       size_t reset() const {return type = -1, out = cnt = 0;};
       friend std::ostream& operator << (std::ostream&, const CMean&);   
    } Mean;
    
    std::ostream& operator << (std::ostream& _os, const CMean& _arith)
    {
       return _os << (!_arith.type ? _arith.out / _arith.cnt : std::pow(_arith.out, 1.0 / _arith.cnt)) + _arith.reset();
    }

    Вывод на экран арифметической и геометрической прогрессии.

    gooseim, 15 Марта 2012

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

    +78

    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
    Drawable d = getResources().getDrawable(R.drawable.screen_width);
            int width = d.getMinimumWidth();
            switch (width) {
                case 1024:
                    CAMERA_WIDTH = 1024;
                    CAMERA_HEIGHT = 600;
                    break;
                case 800:
                    CAMERA_WIDTH = 800;
                    CAMERA_HEIGHT = 480;
                    break;
                case 480:
                    CAMERA_WIDTH = 480;
                    CAMERA_HEIGHT = 320;
                    break;
                case 320:
                    CAMERA_WIDTH = 320;
                    CAMERA_HEIGHT = 240;
                    break;
                default:
                    CAMERA_WIDTH = 800;
                    CAMERA_HEIGHT = 480;
                    break;
            }

    Вот так автор определял размер экрана в Android...по размеру загруженной картинки в ресурсах
    Про getResources().getConfiguration().screen Layout наверное он не знал...

    TeknoMatik, 05 Марта 2012

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

    +997

    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
    static std::string printFloatNumber(float num,bool friendly=false)
    {
    	std::ostringstream out ;
    
    	if(friendly)
    	{
    		char tmp[100] ;
    		std::string units[4] = { "B/s","KB/s","MB/s","GB/s" } ;
    
    		int k=0 ;
    		while(num >= 800.0f && k<5)
    			num /= 1024.0f,++k;
    
    		sprintf(tmp,"%3.2f %s",num,units[k].c_str()) ;
    		return std::string(tmp) ;
    	}
    	else
    	{
    		out << num ;
    		return out.str() ;
    	}
    }

    Исходники RetroShare - это просто шедевр!

    rat4, 04 Марта 2012

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

    +121

    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
    case 64:
    						{
    							this.RA.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_555 = this.CCR;
    							expr_555.Value += 1;
    							break;
    						}
    					case 65:
    						{
    							this.RB.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_58F = this.CCR;
    							expr_58F.Value += 1;
    							break;
    						}
    					case 66:
    						{
    							this.RC.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_5C9 = this.CCR;
    							expr_5C9.Value += 1;
    							break;
    						}
    					case 67:
    						{
    							this.RD.Value = this.memory.getValue(this.CCR.Value);
    							HideRegister expr_603 = this.CCR;
    							expr_603.Value += 1;
    							break;
    						}
    					default:
    						if (command != 129)
    						{
    							switch (command)
    							{
    							case 192:
    								if (this.getBit(this.FR.Value, 0))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_67C = this.CCR;
    									expr_67C.Value += 1;
    								}
    								break;
    							case 193:
    								if (!this.getBit(this.FR.Value, 0))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_6CF = this.CCR;
    									expr_6CF.Value += 1;
    								}
    								break;
    							case 194:
    								if (this.getBit(this.FR.Value, 1))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_71F = this.CCR;
    									expr_71F.Value += 1;
    								}
    								break;
    							case 195:
    								if (!this.getBit(this.FR.Value, 1))
    								{
    									this.CCR.Value = this.memory.getValue(this.CCR.Value);
    								}
    								else
    								{
    									HideRegister expr_76C = this.CCR;
    									expr_76C.Value += 1;
    								}
    								break;
    							}
    						}
    						else
    						{
    							this.CCR.Value = this.memory.getValue(this.CCR.Value);
    						}
    						break;
    					}
    				}
    			}
    			this.FR.Value = value;
    		}

    Элсы,свечи,ифы и просто хороший код №3
    (продолжение следует)
    годная реализация того что можно было написать в 10 строчек

    budlokoder_steb_dm, 03 Марта 2012

    Комментарии (11)
  11. PHP / Говнокод #9578

    +162

    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
    function include_wp_head($src)
    {
        $paths = array(
            ".",
            "..",
            "../..",
            "../../..",
            "../../../..",
            "../../../../..",
            "../../../../../..",
            "../../../../../../.."
        );
       
        foreach ($paths as $path) {
            if(file_exists($path . '/' . $src)) {
                return $path . '/' . $src;
            }
        }
    }

    WordPress Form Manager

    ddavydov, 01 Марта 2012

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