1. PHP / Говнокод #20166

    +5

    1. 1
    2. 2
    3. 3
    if ($this->_session->isLoggedIn() && isset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['before-form']['children'])) {
        // some code
    }

    Самая правильная проверка наличия элемента в DOM...

    Tim_Walker, 09 Июня 2016

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

    +3

    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
    function get_users(){
    	$limit = 5;
    	$offset = 0;// $limit * intval($_POST["offset"]);
    	$ids = mysql_escape_string($_POST['ids']);
    	$res = mysql_query("SELECT * from users where id not in ($ids) limit 6 offset $offset");
    	$i = 0;
    	if($res){
    		while ($user = mysql_fetch_object($res)) {
    			$i++;
    			if($i == 6){
    				$i = 5;
    				$more = 'yes';
    				continue;
    			}
    			$users['i' . $i] = $user;
    		}
    		$data = array("status" => "ok", "users" => $users, "count" => $i, 'more' => $more ? $more : "0");
    		echo json_encode($data, JSON_UNESCAPED_UNICODE);
    }

    Пагинация??? Давайте просто пришлём id тех, кого не нужно возвращать

    nikolawan, 09 Июня 2016

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

    +3

    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
    class TM
    {
        function TM()
        {
             $this->startBuffering();
             register_shutdown_function(array($this, 'endBuffering'));
        }
     
        public function startBuffering()
        {
            ob_start();
        }
     
        public function endBuffering()
        {
            if(ob_get_level() > 1)
            {
                $data = ob_get_contents();
                ob_end_clean();
                
                $this->insertBufferedContent($data);
                
                echo $data;
            }
        }
     
        function insertBufferedContent(&$data)
        {
            if(!empty($this->buffered))
            {
                foreach($this->buffered as $contentID => $contentData)
                {
                    $search[] = ' <!--'.$contentID.'--> ';
                }
     
                $data = str_replace($search, $this->buffered, $data);
            }
        }
     
        function showBuffered($contentID)
        {
            if(ob_get_level() > 1)
            {
                echo '<!--'.$contentID.'-->';
            }
        }
        
        function setBuffered($contentID, $data)
        {
            $this->buffered[$contentID] = $data;
        }
    }
    
    $tm = new TM();

    даже комментировать не хочется

    Взято отсюда:
    http://blog.kpitv.net/article/how-to-set-title/
    Автор:
    http://govnokod.ru/user/13961

    dead_star, 09 Июня 2016

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

    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
    {if 1}
        {if !empty($stickers)}
            <div class="sticker-box" style="width: 152px">
                {foreach $stickers as $sticker}
                    <span><em>{$sticker.value}</em><span><img src="/i/stickers/{$sticker.name}.png" /></span></span>
                {/foreach}
            </div>
        {/if}
        <a href="javascript:;" style="{if !empty($stickers)}top:-7px;{/if}position:relative;display: block; text-align: center;"><img src="{$i->icon[0].files.icon}" alt="{$i->icon[0].fields.title|default:$i->title}" height="{if !empty($stickers)}110{else}130{/if}" /></a>
    {else}
        <a href="javascript:;"><img src="/i/b.gif" style="background: url({$i->icon[0].files.icon}) 50% 50% no-repeat" alt="{$i->icon[0].fields.title|default:$i->title}" width="130" height="130" /></a>
    {/if}

    StTv, 09 Июня 2016

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

    +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
    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
    // can only do five hundred at a time. can't find documentation
        // for this number, but if I do more than that I get an error
        // message
    	for (five_hundred <- pageranks.grouped(500))
    	{
    	  try
    	  {
    	    upload(five_hundred)
    	  }
    	  catch
    	  {
    	    // the datastore is not entirely reliable. for less than 1% of the
    	    // calls it seems to fail randomly. which is a bit annoying if
    	    // you're uploading a lot of data and don't want to stop when half of
    	    // it is already stored
    	    case ex : Throwable =>
    	    {
    	      try
    	      {
    	        ex.printStackTrace()
    	        // try a second time
    	        upload(five_hundred)
    	      }
    	      catch
    	      {
    	        // don't try a third time. just continue
    	        case ex : Throwable => ex.printStackTrace()
    	      }
    	    }
    	  }
    	}

    Наткнулся на пост, в котором некий Ph. D рекламировал scala в качестве замены питону

    Fike, 09 Июня 2016

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

    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
    if($blog) {
    		$content = get_blog($db, $blog);
    		$content = $content[0];
    		$desc = $content[1];
    		$keyw = $content[2];
    	}
    	if(!$blog) {
    		$content = get_news($db, "SELECT * FROM `news` ORDER BY `id` DESC");
    		$desc = "Блог Neon Games";
    		$keyw = "Блог, Neon, Games, NeonGames, Игры, разработка игр, Разработка";
    	}
    	$content = parse_text($content);

    parse_text на уже готовом HTML

    UsernameAK, 08 Июня 2016

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

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?
    if($login=='')
    {
       global $APPLICATION;
       $APPLICATION->ThrowException('Имя входа должно быть заполнено.'); 
       return false;
    }
    
    // Получить последнее исключение можно методом 
    $APPLICATION->GetException()
    ?>

    Bitrix. Лучшие стандарты веб-разработки и новое ядро! Создатели логики try-catch-throw наверное перевернулись бы 100500 раз в гробу увидев такую "реализацию". Пруф как "нужно делать": https://dev.1c-bitrix.ru/api_help/main/reference/cmain/throwexception.php

    zenn1989, 08 Июня 2016

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

    −97

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Запрос = Новый Запрос();
    Запрос.Текст = "ВЫБРАТЬ
    		|	РАЗНОСТЬДАТ(&Дата1, &Дата2, МЕСЯЦ) КАК РезультатРазность";
    Запрос.УстановитьПараметр("Дата1",СтрТЧ.ДатаНачала);
    Запрос.УстановитьПараметр("Дата2",СтрТЧ.ДатаОкончания);
    Результат = Запрос.Выполнить().Выгрузить();
    КолвоМесяцев = Результат[0].РезультатРазность+1;

    Классика жанра. Ходим на сервер, чтобы посчитать разность дат. Ну да, сервер же у нас целыми днями воздух гоняет, заняться ему больше нечем. Давайте 2+2 складывать начнем через сервак.
    Причем, б*ть, через сервер приложений, который в свою очередь погонит запрос на сервер MSSQL.

    mrbus, 08 Июня 2016

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

    −2

    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
    namespace spine {
    
    static SkeletonBatch* instance = nullptr;
    
    void SkeletonBatch::setBufferSize (int vertexCount) {
    	if (instance) delete instance;
    	instance = new SkeletonBatch(vertexCount);
    }
    
    SkeletonBatch* SkeletonBatch::getInstance () {
    	if (!instance) instance = new SkeletonBatch(8192);
    	return instance;
    }
    
    SkeletonBatch::SkeletonBatch (int capacity) :
    	_capacity(capacity), _position(0)
    {
    	_buffer = new V3F_C4B_T2F[capacity];
    	_firstCommand = new Command();
    	_command = _firstCommand;
    
    	Director::getInstance()->getScheduler()->scheduleUpdate(this, -1, false);
    }
    
    SkeletonBatch::~SkeletonBatch () {
    	Director::getInstance()->getScheduler()->unscheduleUpdate(this);
    
    	Command* command = _firstCommand;
    	while (command) {
    		Command* next = command->next;
    		delete command;
    		command = next;
    	}
    
    	delete [] _buffer;
    }

    https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-cocos2dx/3/src/spine/SkeletonBatch.cpp
    Это просто шедевЕр! Течет как ссаные тряпки...

    MarkusD, 08 Июня 2016

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

    +2

    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
    <?php
    /*
    You can place here your functions and event handlers
    
    AddEventHandler("module", "EventName", "FunctionName");
    function FunctionName(params)
    {
            //code
    }
    */
    
    AddEventHandler('form', 'onBeforeResultAdd', 'my_onBeforeResultAdd');
    CModule::IncludeModule('cleantalk.antispam');
    
    function my_onBeforeResultAdd($WEB_FORM_ID, $arFields, $arrVALUES) {
     $ct_status = COption::GetOptionString('cleantalk.antispam', 'status', '0');
     if ($ct_status == 1) {
      global $APPLICATION;
      $aParams = array();
      $aParams['type'] = 'comment';
      $aParams['sender_email'] = isset($arrVALUES['email']) ? $arrVALUES['email'] : '';
      $aParams['sender_nickname'] = isset($arrVALUES['nickname']) ? $arrVALUES['nickname'] : '';
      $aParams['message_title'] = isset($arrVALUES['title']) ? $arrVALUES['title'] : '';
      $aParams['message_body'] = isset($arrVALUES['message']) ? $arrVALUES['message'] : '';
      $aResult = CleantalkAntispam::CheckAllBefore($aParams, FALSE);
      if (isset($aResult) && is_array($aResult)) {
       if ($aResult['errno'] == 0) {
        if ($aResult['allow'] == 1) {
            //Not spammer - just return;
            return;
        } else {
         if (preg_match('//u', $aResult['ct_result_comment'])) {
          $err_str=preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/iu','',$aResult['ct_result_comment']);
          $err_str=preg_replace('/<[^<>]*>/iu', '', $err_str);
         } else {
          $err_str=preg_replace('/^[^\*]*?\*\*\*|\*\*\*[^\*]*?$/i','',$aResult['ct_result_comment']);
          $err_str=preg_replace('/<[^<>]*>/i', '', $err_str);
         }
         $APPLICATION->ThrowException($err_str);
         return false;
        }
       }
      }
     }
    }
    ?>

    Четкая конторка написала четкий антиспам-модуль для битрикса и показывает как его нужно использовать. Тут все в одном флаконе - от игнорирования всех стандартов PSR разом до иррациональной реализации ... Пост на хабре: https://habrahabr.ru/company/cleantalk/blog/302800/

    zenn1989, 08 Июня 2016

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