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

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

    +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
    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
    public class Path {
    	private String path;	
    	private char winSep = '\\';
    	private char unixSep = '/';
    	
    	public void set(String path){				
    		if(!path.endsWith(File.separator)){ 
    			path.concat(File.separator);
     		}
    		this.path = path;
    		if(File.separatorChar == winSep && path.charAt(0) == unixSep){ 
    			this.path = path.replace(unixSep, winSep).substring(1); 
     		}		
    				
    	 }
    
    	public String get(){
    		String path = new String(this.path);
     		return path;  	
    	}
    	
    	public String getRoot(){
    		String root = null;
    		 if(File.separatorChar == unixSep){ 
    			root = "/";
    		} 		
    		if(File.separatorChar == winSep){ 
    			root = this.path.substring(0, this.path.indexOf(winSep)+1);
    		}		
    		return root;
    	}
    	
    }

    в 6 йаве нету класса Path, пришлось самому делать костыль-велосипед. тут где-то ошибочка есть, пока не смотрел.

    spivti, 22 Ноября 2013

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

    +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
    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
    private HandlerRegistration historyChangeHandlerRegistration;
    
    @Override
    protected void onLoad() 
    {
           super.onLoad();
           if(historyChangeHandlerRegistration == null)
           {
                historyChangeHandlerRegistration = History.addValueChangeHandler(historyHandler);
           }
    }
    	
    @Override
    protected void onUnload()
    {
            super.onUnload();
    	    
            if (historyChangeHandlerRegistration != null)
            {
                historyChangeHandlerRegistration.removeHandler();
                historyChangeHandlerRegistration = null;
            }
    }
    
    private ValueChangeHandler<String> historyHandler = new ValueChangeHandler<String>()
    {
            @Override
            public void onValueChange(ValueChangeEvent<String> event)
            {
                if(historyChangeHandlerRegistration != null)
                {
                       //some work with history token
                }
                else
                {
                       // и сюда возможно попасть
                }
            }
    };

    GWT работа с site history

    Lennis, 12 Ноября 2013

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

    +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
    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
    /*
     * 
     * 
     */
    
    public class Chapter1 {
    	private String text[] = { "Returns a  new string that is a ",
    			"substring of this string" };
    	private String splitted[];
    
    	private int k = 2; // 
    	private char c = '<'; 
    
    	public void run() {
    		for (int i = 0; i < text.length; i++) {
    			text[i] = makeString(text[i], change(i)); 
    														
    			System.out.println(text[i]);
    			
    		}
    	}
    
    	/*
    	 * 
    	 */
    	private String makeString(String textLine, String[] changed) {
    		StringBuilder sBui = new StringBuilder(textLine);
    
    		int i = 0; // changed index
    		int beginIndex = 0; 
    		
    
    		for (int j = 0; j < splitted.length; j++) {
    			beginIndex = sBui.indexOf(splitted[j], beginIndex); // word begin		
    			int endIndex = beginIndex + splitted[j].length(); // word end
    			
    			if(splitted[j].length() > k){			
    				sBui.delete(beginIndex, endIndex);
    				sBui.insert(beginIndex, changed[i++]);
    			} 
    			
    			beginIndex = endIndex;
    		}
    						
    		return sBui.toString();
    	}
    
    	/*
    	 * 
    	 * 
    	 */
    	public String[] change(int i) {
    
    		splitted = text[i].split("\t|\n| "); 
    
    		for (int indx = 0; indx < splitted.length; indx++) {
    			if (splitted[indx].length() > k) {
    				StringBuilder sBuild = new StringBuilder(splitted[indx]);
    				sBuild.setCharAt(k, c);
    				splitted[indx] = sBuild.toString(); // irasomas pakeistas zodis				
    			}
    		}
    
    		return splitted;
    	}
    
    } // end

    help, задание - вкаждом слове текста к-тую буквы заменить с символом, если длина слова меньше к, замену не выполнять.

    Exception in thread "main" java.lang.StringIndexOutOfBoundsExceptio n: String index out of range: -1 (проблема)

    spivti, 24 Августа 2013

    Комментарии (104)
  5. 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)
  6. Java / Говнокод #12609

    +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
    20. 20
    21. 21
    22. 22
    package com.example.testing;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
        
    }

    Govnisti_Diavol, 17 Февраля 2013

    Комментарии (8)
  7. 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)
  8. PHP / Говнокод #12103

    +65

    1. 1
    $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

    Opencart, catalog/model/catalog/product.php

    Они что издеваются? А я-то думаю что у меня ложит mysql сервер на колени...

    fooser, 12 Ноября 2012

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

    +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
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    $somevar = $_GET['somevar'];
    //получили? теперь вот так
    if($somevar == 1){$somevar = 15;}
    if($somevar == 2){$somevar = 20;}
    if($somevar == 3){$somevar = 25;}
    if($somevar == 4){$somevar = 30;}
    if($somevar == 5){$somevar = 35;}
    if($somevar == 6){$somevar = 40;}
    if($somevar == 7){$somevar = 45;}
    if($somevar == 8){$somevar = 50;}
    
    //пропустим неважное
    
    $output .=''.$somevar.' ';
    
    //пропустим неважное
    
    //а теперь обратно
    if($somevar){
    	if($somevar == 15){$somevar = 1;}
    	if($somevar == 20){$somevar = 2;}
    	if($somevar == 25){$somevar = 3;}
    	if($somevar == 30){$somevar = 4;}
    	if($somevar == 35){$somevar = 5;}
    	if($somevar == 40){$somevar = 6;}
    	if($somevar == 45){$somevar = 7;}
    	if($somevar == 50){$somevar = 8;}

    Для чего это? А кто бы знал.
    PHP это модно и просто :)
    Коменты добавлены чтобы понятней было немного.

    111111, 01 Октября 2012

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

    +65

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function draw_text() {  
            // ....
            /* remove background color */
            imagecolortransparent($im_text, $bg_color);
            return $im_text;
            imagedestroy($im_text);
    }

    Функция вывода текста CAPTCHA в modx Evolution.

    MaXL, 02 Августа 2012

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

    +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
    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
    $quGroup = mysql_query($x = "
            SELECT
                a.latitude, a.longitude, a.catid, a.id, a.title, a.arttype, a.userid, b.firstname, b.lastname, b.usertype,
                a.latitude2, a.longitude2, a.latitude3, a.longitude3, a.latitude4, a.longitude4, a.latitude5, a.longitude5,
                a.latitude6, a.longitude6, a.latitude7, a.longitude7, a.latitude8, a.longitude8, a.latitude9, a.longitude9,
                a.latitude10, a.longitude10, a.latitude11, a.longitude11
            from materials a, users b
            where a.status='1' and a.userid=b.id and add_date > $day)
            $sql_cond");
        while ($flGroup = mysql_fetch_row($quGroup)) {
            $j++;
            $a1 = $a2 = array ();
            $l1 = $flGroup[0];
            $l2 = $flGroup[1];
            if ($l1 && $l2) {
                $a1[] = $l1;
                $a2[] = $l2;
            }
    
            $latitude2 = $flGroup[10];
            $longitude2 = $flGroup[11];
            if ($latitude2 && $longitude2) {
                $a1[] = $latitude2;
                $a2[] = $longitude2;
            }
    
            $latitude3 = $flGroup[12];
            $longitude3 = $flGroup[13];
            if ($latitude3 && $longitude3) {
                $a1[] = $latitude3;
                $a2[] = $longitude3;
            }
    
            $latitude4 = $flGroup[14];
            $longitude4 = $flGroup[15];
            if ($latitude4 && $longitude4) {
                $a1[] = $latitude4;
                $a2[] = $longitude4;
            }
    
            $latitude5 = $flGroup[16];
            $longitude5 = $flGroup[17];
            if ($latitude5 && $longitude5) {
                $a1[] = $latitude5;
                $a2[] = $longitude5;
            }
    
            $latitude6 = $flGroup[18];
            $longitude6 = $flGroup[19];
            if ($latitude6 && $longitude6) {
                $a1[] = $latitude6;
                $a2[] = $longitude6;
            }
    
            $latitude7 = $flGroup[20];
            $longitude7 = $flGroup[21];
            if ($latitude7 && $longitude7) {
                $a1[] = $latitude7;
                $a2[] = $longitude7;
            }
    
            $latitude8 = $flGroup[22];
            $longitude8 = $flGroup[23];
            if ($latitude8 && $longitude8) {
                $a1[] = $latitude8;
                $a2[] = $longitude8;
            }
    
            $latitude9 = $flGroup[24];
            $longitude9 = $flGroup[25];
            if ($latitude9 && $longitude9) {
                $a1[] = $latitude9;
                $a2[] = $longitude9;
            }
    
            $latitude10 = $flGroup[26];
            $longitude10 = $flGroup[27];
            if ($latitude10 && $longitude10) {
                $a1[] = $latitude10;
                $a2[] = $longitude10;
            }
    
            $latitude11 = $flGroup[28];
            $longitude11 = $flGroup[29];
            if ($latitude11 && $longitude11) {
                $a1[] = $latitude11;
                $a2[] = $longitude11;
            }
    
            if (!$l1 && !$l2 && !$latitude2 && !$longitude2 && !$latitude3 && !$longitude3 && !$latitude4 && !$longitude4 && !$latitude5 && !$longitude5 && !$latitude6 && !$longitude6 && !$latitude7 && !$longitude7 && !$latitude8 && !$longitude8 && !$latitude9 && !$longitude9 && !$latitude10 && !$longitude10 && !$latitude11 && !$longitude11)
                continue;
    
    ...
    }

    как изящно

    shmaltorhbooks, 28 Июня 2012

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