1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. Java / Говнокод #12588

    +72

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public class Test {
        public static final int a;
        static {
            System.out.println(Main.a);
            a = 42;
            System.out.println(Main.a);
        }
    }

    javac такой javac...

    Так видит проблему: http://ideone.com/jhPN5X
    А вот так - нет: http://ideone.com/qAMIvH

    bormand, 14 Февраля 2013

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

    +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
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    template <typename IdType, class Tag>
    class id {
    public:
        typedef IdType value_type;
    
        explicit id(value_type val)
            : value(val)
        {}
    
        bool operator==(id rhs)
        {
            return rhs.value == value;
        }
    
        bool operator!=(id rhs)
        {
            return rhs.value != value;
        }
    
        value_type value;
    };
    
    #define HASKELL_NEWTYPE(type_name, value_type) struct __##type_name##_tag__ {}; \
        typedef ::id<value_type, __##type_name##_tag__> type_name

    Когда newtype нет, но очень хочется.
    http://ideone.com/VRu56j
    Простите за синтетику

    roman-kashitsyn, 14 Февраля 2013

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

    +138

    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
    $sql_ex = array();
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '5')
    	$sql_ex[] = " `ex`.`num` = 5 ";
    else
    	$sql_ex[] = " `ex`.`num` != 5 ";
    
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '7')
    	$sql_ex[] = " `ex`.`num` = 7 ";
    else
    	$sql_ex[] = " `ex`.`num` != 7 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '4')
    	$sql_ex[] = " `ex`.`num` = 4 ";
    else
    	$sql_ex[] = " `ex`.`num` != 4 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '10')
    	$sql_ex[] = " `ex`.`num` = 10 ";
    else
    	$sql_ex[] = " `ex`.`num` != 10 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '11')
    	$sql_ex[] = " `ex`.`num` = 11 ";
    else
    	$sql_ex[] = " `ex`.`num` != 11 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '14')
    	$sql_ex[] = " `ex`.`num` = 14 ";
    else
    	$sql_ex[] = " `ex`.`num` != 14 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '19')
    	$sql_ex[] = " `ex`.`num` = 19 ";
    else
    	$sql_ex[] = " `ex`.`num` != 19 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '20')
    	$sql_ex[] = " `ex`.`num` = 20 ";
    else
    	$sql_ex[] = " `ex`.`num` != 20 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '21')
    	$sql_ex[] = " `ex`.`num` = 21 ";
    else
    	$sql_ex[] = " `ex`.`num` != 21 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '13')
    	$sql_ex[] = " `ex`.`num` = 13 ";
    else
    	$sql_ex[] = " `ex`.`num` != 13 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '12')
    	$sql_ex[] = " `ex`.`num` = 12 ";
    else
    	$sql_ex[] = " `ex`.`num` != 12 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '6')
    	$sql_ex[] = " `ex`.`num` = 6 ";
    else
    	$sql_ex[] = " `ex`.`num` != 6 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '17')
    	$sql_ex[] = " `ex`.`num` = 17 ";
    else
    	$sql_ex[] = " `ex`.`num` != 17 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '23')
    	$sql_ex[] = " `ex`.`num` = 23 ";
    else
    	$sql_ex[] = " `ex`.`num` != 23 ";
    if(isset($this->request->get["id"]) && $this->request->get["id"] == '16')
    	$sql_ex[] = " `ex`.`num` = 16 ";
    else
    	$sql_ex[] = " `ex`.`num` != 16 ";
    $sql_extra = '';
    if (!empty($sql_ex)) $sql_extra = ' AND '.implode(" AND ", $sql_ex);

    В начале нужно было одно условие, потом еще и еще и ...

    gvncode, 14 Февраля 2013

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

    +9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    y=fopen(lex,"w+");
    fclose(y);
    FILE *r=fopen(result,"w+");
    fclose(r);
    FILE *k=fopen("pryklad.obj","w+");
    fclose(k);

    Abbath, 13 Февраля 2013

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