1. Java / Говнокод #12599

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    private String stateChangedReason;
    ...
    
    if (stateChangedReason != null && stateChangedReason instanceof String) {
                dealerManageInfo.setChangeStateReason(stateChangedReason.toString());
    }

    amarfey, 15 Февраля 2013

    Комментарии (14)
  2. JavaScript / Говнокод #12598

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    var declination= function(n, form1, form2, form5){
            n = n % 100;
            var n1 = n % 10;
            if (n > 10 && n < 20) return form5;
            if (n1 > 1 && n1 < 5) return form2;
            if (n1 == 1) return form1;
            return form5;
        }

    хуита, 15 Февраля 2013

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

    +121

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public class DefaultQueryEngine implements QueryEngine {
    
        private static volatile QueryEngine DEFAULT;
        
        public static QueryEngine getDefault() {
            if (DEFAULT == null) {
                DEFAULT = new DefaultQueryEngine(new DefaultEvaluatorFactory(CollQueryTemplates.DEFAULT));
            }
            return DEFAULT;
        }

    https://github.com/mysema/querydsl/blob/master/querydsl-collections/src/main/java/com/mysema/query/collections/DefaultQueryEngine.java

    Ехал дефолт через дефолт...

    someone, 15 Февраля 2013

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

    +151

    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
    <?php
    class MainController extends ModuleAdminController {
    	public $defaultAction = 'admin';
    	
    	public function actionCreate() {
    		$this->redirect('admin');
    	}
    	
    	public function actionDelete($id) {
    		$this->redirect('admin');
    	}
    	
    	public function actionView($id) {
    		$this->redirect('admin');
    	}
    }

    Модули в Yii такие коварные :(

    Diwms, 15 Февраля 2013

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

    +133

    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
    private function init_categories()
    	{
    		// Дерево категорий
    		$tree = new stdClass();
    		$tree->subcategories = array();
    		
    		// Указатели на узлы дерева
    		$pointers = array();
    		$pointers[0] = &$tree;
    		$pointers[0]->path = array();
    		
    		// Выбираем все категории
    		$query = $this->db->placehold("SELECT c.id, c.parent_id, c.name, c.description, c.url, c.meta_title, c.meta_keywords, c.meta_description, c.image, c.visible, c.position
    										FROM __categories c ORDER BY c.parent_id, c.position");
    											
    		// Выбор категорий с подсчетом количества товаров для каждой. Может тормозить при большом количестве товаров.
    		// $query = $this->db->placehold("SELECT c.id, c.parent_id, c.name, c.description, c.url, c.meta_title, c.meta_keywords, c.meta_description, c.image, c.visible, c.position, COUNT(p.id) as products_count
    		//                               FROM __categories c LEFT JOIN __products_categories pc ON pc.category_id=c.id LEFT JOIN __products p ON p.id=pc.product_id AND p.visible GROUP BY c.id ORDER BY c.parent_id, c.position");
    		
    		
    		$this->db->query($query);
    		$categories = $this->db->results();
    				
    		$finish = false;
    		// Не кончаем, пока не кончатся категории, или пока ниодну из оставшихся некуда приткнуть
    		while(!empty($categories)  && !$finish)
    		{
    			$flag = false;
    			// Проходим все выбранные категории
    			foreach($categories as $k=>$category)
    			{
    				if(isset($pointers[$category->parent_id]))
    				{
    					// В дерево категорий (через указатель) добавляем текущую категорию
    					$pointers[$category->id] = $pointers[$category->parent_id]->subcategories[] = $category;
    					
    					// Путь к текущей категории
    					$curr = $pointers[$category->id];
    					$pointers[$category->id]->path = array_merge((array)$pointers[$category->parent_id]->path, array($curr));
    					
    					// Убираем использованную категорию из массива категорий
    					unset($categories[$k]);
    					$flag = true;
    				}
    			}
    			if(!$flag) $finish = true;
    		}
    		
    		// Для каждой категории id всех ее деток узнаем
    		$ids = array_reverse(array_keys($pointers));
    		foreach($ids as $id)
    		{
    			if($id>0)
    			{
    				$pointers[$id]->children[] = $id;
    
    				if(isset($pointers[$pointers[$id]->parent_id]->children))
    					$pointers[$pointers[$id]->parent_id]->children = array_merge($pointers[$id]->children, $pointers[$pointers[$id]->parent_id]->children);
    				else
    					$pointers[$pointers[$id]->parent_id]->children = $pointers[$id]->children;
    					
    				// Добавляем количество товаров к родительской категории, если текущая видима
    				// if(isset($pointers[$pointers[$id]->parent_id]) && $pointers[$id]->visible)
    				//		$pointers[$pointers[$id]->parent_id]->products_count += $pointers[$id]->products_count;
    			}
    		}
    		unset($pointers[0]);
    		unset($ids);
    
    		$this->categories_tree = $tree->subcategories;
    		$this->all_categories = $pointers;	
    	}

    построение дерева категорий в платной cms simpla

    alpex, 15 Февраля 2013

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

    +71

    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
    private static final int IDX_OBJECT = 0;
    private static final String PARTY_ACCOUNT_BALANCE_QUERIES = "Select party.id from Party party WHERE party.TaxID='615100175';Select account.id from PaymentAccount account, Party party WHERE party.TaxID='615100175';Select balance.id from PaymentBalance balance WHERE balance.BalanceType='10000';";
    private static final int queryAmount = 3;
    public void createPaymentAccountUpdate() {
    	String[] QUERY = new String[queryAmount];
    	int startIndex = 0, endIndex=0;
    	IRecordset [] rs=null;
    
    	for (int i = 0; i < queryAmount; i++) {
    		endIndex = PARTY_ACCOUNT_BALANCE_QUERIES.indexOf(';', startIndex);
    		QUERY[i] = PARTY_ACCOUNT_BALANCE_QUERIES.substring(startIndex, endIndex);
    		startIndex = endIndex + 1;
    	} 
    	for (int i = 0; i < queryAmount; i++) {
    		rs[i] = s_mgr.newQuery().execute(QUERY[i].toString());
    	}
    	if (rs[0].moveNext()) {
    		IParty party = (IParty)rs[0].valueFromIndex(IDX_OBJECT);
    		if (rs[1].moveNext()) {
    			IPaymentAccount pa = (IPaymentAccount) rs[1].valueFromIndex(IDX_OBJECT);
    			pa.setParty(party);
    		}
    		if (rs[2].moveNext()) {
    			IPaymentBalance pb = (IPaymentBalance) rs[2].valueFromIndex(IDX_OBJECT);
    			pa.setBalance(pb);
    		}            
    		pa.setComment("Test account update created"); 
    		pa.Save();
    	}
    }

    Лучше уж никаких тестов, чем такие

    askell, 14 Февраля 2013

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

    +24

    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
    int MyForm::modelId(int button, bool rarefied, bool grouped)
    {
        if (button == 4)
            return 9;
        else
        {
            Q_ASSERT(button == 1 || button == 2 || button == 3);
            if (!rarefied)
                return (button - 1);
            else
            {
                if (!grouped)
                    return 3 + (button - 1);
                else
                    return 6 + (button - 1);
            }
        }
    }

    Энумы? Не, не слышал.

    ABBAPOH, 14 Февраля 2013

    Комментарии (18)
  8. C++ / Говнокод #12592

    +16

    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
    char tab1[22][8]={"program","var","begin","end","int","float","bool","if","then","else","for","to","do","while","readln","writeln","as","||","!","&&","true","false"};
    char tab2[18][3]={"==","<",">","+","-","*","/","(",")",".",",",";"," ","!=","<=",">=",10};
    
    //Много кода
    
    if(!strcmp("program",st.top())&&!strcmp("program",&mas[j][0]))
    	{
    		st.pop();
    		j++;
    	}
    	else
    		if(!strcmp("var",st.top())&&!strcmp("var",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("begin",st.top())&&!strcmp("begin",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("end",st.top())&&!strcmp("end",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("int",st.top())&&!strcmp("int",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    		else
    			if(!strcmp("float",st.top())&&!strcmp("float",&mas[j][0]))
    		{
    			st.pop();
    			j++;
    		}
    
    //Еще строк 200 такого

    Abbath, 14 Февраля 2013

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

    +14

    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
    int main(int argc, char* argv[])
    {
    
         SetConsoleCP(1251);// установка кодовой страницы win-cp 1251 в поток ввода
       SetConsoleOutputCP(1251); // установка кодовой страницы win-cp 1251 в поток вывода
        setlocale(LC_ALL,"Ukrainian");
    
        if(argc<2)
        {
            argv[1] = (char*)malloc(500*sizeof(char));
            //printf("Vvedit' imya vxidnogo failu: \n");
            //scanf("%s",argv[1]);
            argv[1]="1.txt";
    
        }

    Abbath, 14 Февраля 2013

    Комментарии (9)
  10. Java / Говнокод #12589

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public static void trustAllHttpsCertificates() {
        // Is the deprecated protocol setted?
        if (isDeprecatedSSLProtocol()) {
            __trustAllHttpsCertificates();
        } else {
            _trustAllHttpsCertificates();
        } // else
    } // trustAllHttpsCertificates

    Captain Obvious поучаствовал?
    P.S. Похоже, это писал старый программист, закалённый в борьбе с VisualBasic.

    wissenstein, 14 Февраля 2013

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