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

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

    −1

    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
    AnsiString message=IntToStr((int)GetTickCount());
    		if(message.Length()>=3)
    			message=message.SubString(message.Length()-3, 3);
    		else if(message.Length()==2)
    			message="0"+message;
    		else if(message.Length()==1)
    			message="00"+message;
    		message=dt.FormatString("yy")+dt.FormatString("mm")+dt.FormatString("dd")+" "+
    			dt.FormatString("hh")+dt.FormatString("nn")+dt.FormatString("ss")+" "+message;
    		message=message+" "+aMessage;
    		if(FMemoMes){
    			FMemoMes->Lines->Add(message);
    		}

    Выводит сообщение aMessage, вставляя в начало сообщения текущие дату и время с миллисекундами.

    appach, 27 Июня 2016

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

    0

    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
    function setLastHandshake ($carID) {
    	$HsList = json_decode(file_get_contents('carconnection.txt'), 1);
    	if ($HsList == "null" || $HsList == null) {
    		$HsList = json_decode("[]");
    	}
    	$carCount = count($HsList);
    	$i = 0;
    	foreach ($HsList as &$row) {
    		if ($row['car'] == $carID) {
    			$row['lastHS'] = (string)time();
    			break;
    		}
    		else {
    		$i++;
    		}
    		if ($i == $carCount) {
    			$HsList[] = array('car' => (string)$carID, 'lastHS' => (string)time());
    		}
    	}
    	if ($HsList == "null" || $HsList == null) {
    		return -1;
    	}
    	$f = fopen('carconnection.txt', 'w');
    	fwrite($f, json_encode($HsList));
    }

    tooyz, 20 Июня 2016

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

    0

    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
    function * getTreePost(postsInfo, id) {
      var parent = _.filter(postsInfo, function (item) {
        return Boolean(item._id == id);
      });
    
      var children = _.filter(postsInfo, function (item) {
        return Boolean(item.parentId);
      });
    
      return _.union(parent, findChildren(id, children));
    
      function findChildren(parentId) {
        if (parentId) {
          var data = _.where(children, {parentId: parentId});
          var ret = [];
          if (data.length) {
            _.each(data, function (item, index) {
              var data_r = findChildren(item._id);
              if (data_r.length) {
                ret = _.union(data_r, ret);
              }
            });
            return _.union(data, ret);
          } else
            return [];
        } else return [];
      }
    }

    обычная рекурсия

    volodymyrkoval, 18 Мая 2016

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

    +1

    1. 1
    2. 2
    3. 3
    if (round($this->shot, 2, PHP_ROUND_HALF_DOWN) > round($this->getSumBonus(), 2, PHP_ROUND_HALF_DOWN)) {
          return false;
    }

    Сравнение двух double числе

    govnokoderphp, 10 Мая 2016

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

    +1

    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
    // новый тестовый экшн в контроллере
            public function actionNew($alias)
        {
            $model=Partners::model()->model()->findByAttributes(array('alias'=>$alias));
                   
                    if($model==null)
                throw new CHttpException(404,'The requested page does not exist.');
                           
                    $this->render('view',array(
                'model'=>$this->loadModel($model->id),
            ));
           
        }
     
    // правило в конфиге
    // '<module:\w+>/<controller:\w+>/<alias:\w+>' => '<module>/<controller>/new',

    https://vk.com/echo_php?w=wall-175_189930%2Fall

    Уи1

    Keeper, 07 Мая 2016

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <ol ng-init="citationsLimit = 3" ng-model="citationsLimit">
    	<li class="citation citationList" ng-repeat="citation in answerFact.citations | limitTo: citationsLimit as citationsResult">
    		<i class="fa ic-marker fa-circle" aria-hidden="true"></i>
    		<div class="citation-text">
    			<span ng-bind-html="citation.highlightedSentenceString"></span>
    			<span ng-if="citation.source">
    				(<a  href="{{citation.source}}" target="_blank">{{citation.source}}</a>)
    			</span>
    		</div>
    	</li>
    </ol>

    ifmy, 06 Мая 2016

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

    0

    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
    <?php
    namespace DoctrineExtensions;
    use \Doctrine\ORM\Event\LoadClassMetadataEventArgs;
    /**
     * Расширение для Doctrine ORM
     * Позволяет отслеживать и работать не со всей базой, а только с таблицами с префиксом
     * Необходимо для уживания с битриксом
     *
     * Class TablePrefix
     * @package DoctrineExtensions
     */
    class TablePrefix
    {
        protected $prefix = '';
        public function __construct($prefix)
        {
            $this->prefix = (string) $prefix;
        }
        public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
        {
            $classMetadata = $eventArgs->getClassMetadata();
            $classMetadata->setTableName($this->prefix . $classMetadata->getTableName());
            foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
                if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY) {
                    $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
                    $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName;
                }
            }
        }
    }

    Адепты битрикса добрались до Doctrine ORM. И вот что из этого получилось.
    Заставь дурака ORM подключать, он и events задрочит.

    Keeper, 06 Мая 2016

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

    +1

    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
    if(!strpos($amount,'.')) {
        $amount = $amount . '.00';
    } else {
    	$strlength = strlen(explode('.',$amount)[1]);
    	if($strlength != 2) {
    		if($strlength == 1) {
    			$amount = $amount . '0';
    		}
    		if($strlength > 2) {
    			$amount = round($amount,2);
    		}
    	}
    }

    Получение дробного до сотых числа

    ykpon, 05 Мая 2016

    Комментарии (1)
  10. JavaScript / Говнокод #19924

    0

    1. 1
    2. 2
    3. 3
    //- ASAP OR DIE♪
        //   re: ASAP OR DIE♪
        //-   next time, you should die

    mcheguevara2, 04 Мая 2016

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

    −10

    1. 1
    2. 2
    3. 3
    4. 4
    static void Alert(object text)
    		{
    			Console.WriteLine(text);
    		}

    d_fomenok, 17 Апреля 2016

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