1. C# / Говнокод #9751

    +114

    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
    private int GetInsertion(byte[] firstArr, byte[] secondArr)
            {
                int result = -1;
                int counter = 0;
                if (firstArr.Count() >= secondArr.Count())
                {
                    for (int i = 0; i < firstArr.Count(); i++)
                    {
                        if (firstArr[i] == secondArr[counter])
                        {
                            counter++;
                            if (counter == secondArr.Count())
                            {
                                result = i - counter + 1;
                                break;
                            }
                        }
                        else
                        {
                            counter = 0;
                        }
                    }
                }
                return result;
            }

    находит индекс вхождения одного массива в другой

    razzil, 23 Марта 2012

    Комментарии (1)
  2. ActionScript / Говнокод #9750

    −124

    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
    if (param.visible == 'cache')
    {
    	while (parseCacheResult.indexOf('$data') != -1) parseCacheResult = parseCacheResult.replace('$data', '_dataCache');
    	while (parseCacheResult.indexOf('$name') != -1) parseCacheResult = parseCacheResult.replace('$name', param.nameParam);
    	while (parseCacheResult.indexOf('$type') != -1) parseCacheResult = parseCacheResult.replace('$type', param.type);
    } else if (param.visible == 'static')
    {
    	while (parseStaticResult.indexOf('$data') != -1) parseStaticResult = parseStaticResult.replace('$data', '_dataStatic');
    	while (parseStaticResult.indexOf('$name') != -1) parseStaticResult = parseStaticResult.replace('$name', param.nameParam);
    	while (parseStaticResult.indexOf('$type') != -1) parseStaticResult = parseStaticResult.replace('$type', param.type);
    }
    else
    {
    	while (parseDynamicResult.indexOf('$data') != -1) parseDynamicResult = parseDynamicResult.replace('$data', '_dataDynamic');
    	while (parseDynamicResult.indexOf('$name') != -1) parseDynamicResult = parseDynamicResult.replace('$name', param.nameParam);
    	while (parseDynamicResult.indexOf('$type') != -1) parseDynamicResult = parseDynamicResult.replace('$type', param.type);
    }
    
    while (setResult.indexOf('$name') != -1) setResult = setResult.replace('$name', param.nameParam);
    while (setResult.indexOf('$type') != -1) setResult = setResult.replace('$type', param.type);
    while (setResult.indexOf('$className') != -1) setResult = setResult.replace('$className', className);
    
    while (getResult.indexOf('$name') != -1) getResult = getResult.replace('$name', param.nameParam);
    while (getResult.indexOf('$type') != -1) getResult = getResult.replace('$type', param.type);
    
    while (varResult.indexOf('$name') != -1) varResult = varResult.replace('$name', param.nameParam);
    while (varResult.indexOf('$type') != -1) varResult = varResult.replace('$type', param.type);
    while (varResult.indexOf('$comment') != -1) varResult = varResult.replace('$comment', param.comment);
    while (varResult.indexOf('$default') != -1) varResult = varResult.replace('$default', param.defaultValue);
    
    }
    
    var result : String = baseTemplate;
    while (result.indexOf('$className') != -1) result = result.replace('$className', className);
    while (result.indexOf('$comment') != -1) result = result.replace('$comment', comment);
    while (result.indexOf('$baseClass') != -1) result = result.replace('$baseClass', baseClass);
    while (result.indexOf('$singleton_1') != -1) result = result.replace('$singleton_1', singl_1);
    while (result.indexOf('$singleton_2') != -1) result = result.replace('$singleton_2', singl_2);
    
    result = result.replace('$var', varResult);
    result = result.replace('$set', setResult);
    result = result.replace('$get', getResult);
    result = result.replace('$parseDynamic', parseDynamicResult);
    result = result.replace('$parseStatic', parseStaticResult);
    result = result.replace('$parseCache', parseCacheResult);
    result = result.replace('$values', valuesList);
    result = result.replace('$dynamic', data.dynamicClass == 1 ? 'dynamic' : '');

    Как то родилось в процессе допилок кодогена )

    kyzi007, 23 Марта 2012

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

    +142

    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
    public abstract class MySqlDataBase extends AbstractDataBase {
    
        public MySqlDataBase() throws Exception {
        }
    
        public void connection) {
            // Тут наш говнокод...
        }
    
        public abstract void createDB() {
            // Тут наш говнокод...
        }   
        
        public abstract void executeQuery() {
            // Тут наш говнокод...
        }
    
        public abstract void shutdown() {
            // Тут наш говнокод
        }
    
        public abstract DBObject getObject(String q);
        
        public abstract Vector getObjectVector(String q);
        
        public abstract void insertObject(DBObject o);
        
        public abstract void updateObject(DBObject o);
    }

    JavaCoder, 23 Марта 2012

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

    +62

    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
    package ru.jimbot.db;
    
    public abstract void AbstractDataBase {
    
        public AbstractDataBase {
        }
    
        public abstract void connection();
    
        public abstract void createDB();   
        
        public abstract void executeQuery();
    
        public abstract void shutdown();
    
    }

    JavaCoder, 23 Марта 2012

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

    +79

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if ("5".equals(pid)) {
    
    } else {
    	if ("1".equals(pid) || "4".equals(pid)) {
    		type = "fl";
    	} else if ("6".equals(pid)){
    		type = "nw";
    	}else {
    		type = "ul";
    	}
    }

    Из базы формируется дерево элементов для меню. Там же есть какая-то сортировка. Меняем в базе сортировку, а все работает по-старому. Лезем копать и находим.

    akkuch, 23 Марта 2012

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

    +157

    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
    if ($this->_hasParam('error')) {
                    if (intval(htmlentities($this->getRequest()->getParam('error'))) == -1100) {
                        $this->payment_messages->addMess($this->translate->translate('please.remember.fill'));
                    } elseif (intval(htmlentities($this->getRequest()->getParam('error'))) == -1300) {
                        $this->payment_messages->addMess($this->translate->translate('credit.card.not.accepted'));
                    } elseif (intval(htmlentities($this->getRequest()->getParam('error'))) == -1022) {
                        $this->payment_messages->addMess($this->translate->translate('transaction.declined.card.number'));
                    } elseif (intval(htmlentities($this->getRequest()->getParam('error'))) == -1018) {
                        $this->payment_messages->addMess($this->translate->translate('transaction.declined.card.number'));
                    } else {
                        $this->payment_messages->addMess($this->translate->translate('payment.system.error'));
                    }
                    $this->view->payment_messages = $this->payment_messages->getMess();
                }

    В продолжение #9742
    Это Team leader!!!

    Quetzalcoatl, 23 Марта 2012

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

    +158

    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 function delete_post($id_op){
            $ret = 'false';
            if((!empty($id_op))){
                    try{
                                        $ret1 = $this->getAdapter()->delete($this->users_posts_table,  'op_id = '.intval($id_op));
                                        $ret2 = $this->getAdapter()->delete($this->offer_posts_table,  'id_op = '.intval($id_op));
                                        if($ret1>0 && $ret2>0){
                                            $ret = 'true';
                                        }
                                        }catch(Exception $e){
                            $this->logger->log('module: deleting in  users_posts, offer_posts tables '.$e->getMessage(), Zend_Log::ERR);
                     }
            }
            else{
                            $ret = 'false';
                            $this->logger->log('function: delete_post : id_op is null', Zend_Log::ERR);
            }
            return $ret;
        }

    Код тим лидера.
    форматирование автора

    Quetzalcoatl, 23 Марта 2012

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

    +155

    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
    function sql_ommetr($q,&$dbt,$line)
    {
    	$result = mysql_query($q, $dbt);
    	if (!$result)
    	{
    		if (!mysql_ping($dbt))
    		{
    			$dbt = reinit_master_connection();
    			if (!mysql_ping($dbt))
    			{
    				trigger_error(__FILE__.":$line\t".mysql_errno($dbt)."\t".mysql_error($dbt)."\t| 2dieWhen executing: ".preg_replace("/\n+/"," ",$q)."\n",E_USER_WARNING);
    				die();
    			}else{
    				$result = mysql_query($q, $dbt);
    				if (!$result){
    					trigger_error(__FILE__.":$line\t".mysql_errno($dbt)."\t".mysql_error($dbt)."\t| 3dieWhen executing: ".preg_replace("/\n+/"," ",$q)."\n",E_USER_WARNING);
    					die();
    				}
    			}
    		}else{
    			$result = mysql_query($q, $dbt);
    			if (!$result){
    				trigger_error(__FILE__.":$line\t".mysql_errno($dbt)."\t".mysql_error($dbt)."\t| 3dieWhen executing: ".preg_replace("/\n+/"," ",$q)."\n",E_USER_WARNING);
    				die();
    			}
    		}
    	}
    	return $result;
    }

    Странно, я представлял себе Омметр немного иначе...

    roman-kashitsyn, 23 Марта 2012

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

    +148

    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
    <?php
    /**
     * Зиг хайль!
     *
     * @author Adolf Hitler <mein.fü[email protected]>
     * @version 1.0
     *
     * Date: 01.09.1939 14:18
     */
    
    namespace system\api\exception {
    
    	class ziga extends \Exception {
    		public function __construct($message = "Sieg Heil!", $code = 1488, \Exception $previous = NULL) {
    			parent::__construct($message, $code, $previous);
    		}
    	}
    
    }

    Сначала я нашел в проекте кусок кода throw new exception\ziga(); ...

    WinnerWolf, 23 Марта 2012

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