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

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

    +314

    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
    <?php
    require 'classes/_func.class.php';
    $func = new func();
    if($_SESSION['user']){
      $user_id = func::clear($_SESSION['user'],'int');
      $time = time();
      $ip = $_SERVER['REMOTE_ADDR'];
      $db->Query("UPDATE users SET last = '{$time}', ip = '{$ip}' WHERE id = '{$user_id}'");
      function stockGen($user_id){
        global $db;
        $db->Query("SELECT * FROM users WHERE id = '{$user_id}'");
        $user_data = $db->FetchArray();
        $db->Query("SELECT * FROM users_conf WHERE user_id = '{$user_id}'");
        $sub_data = $db->FetchArray();
        $data = array_merge($user_data,$sub_data);
        $day = time() - 86400;
        $db->Query("SELECT
          (SELECT ref_1 FROM users_ref WHERE user_id = '{$user_id}') ref_id,
          (SELECT COUNT(*) FROM banner_history WHERE user_id = '{$user_id}') banner_views,
          (SELECT COUNT(*) FROM link_history WHERE user_id = '{$user_id}') link_views,
          (SELECT COUNT(*) FROM users_ref WHERE ref_1 = '$user_id') referals,
          (SELECT time FROM auth WHERE user_id = '{$user_id}' ORDER BY id DESC LIMIT 1) last_auth,
          (SELECT SUM(money) FROM payments WHERE user_id = '{$user_id}' AND status = '2') pay,
          (SELECT SUM(money) FROM inserts WHERE user_id = '{$user_id}' AND status = '2') ins,
          (SELECT SUM(to_ref_1) FROM users_ref WHERE ref_1 = '{$user_id}') from_refs_1,
          (SELECT SUM(to_ref_2) FROM users_ref WHERE ref_2 = '{$user_id}') from_refs_2,
          (SELECT SUM(to_ref_3) FROM users_ref WHERE ref_3 = '{$user_id}') from_refs_3,
          (SELECT to_ref_1 FROM users_ref WHERE user_id = '{$user_id}') to_ref");
        $data += $db->FetchArray();
        $data['from_refs'] = sprintf('%.2f',$data['from_refs_1'] + $data['from_refs_2'] + $data['from_refs_3']);
        $data['all_view'] = intval($data['banner_views']) + intval($data['link_views']);
        $data['all_money'] = 0;/*sprintf('%.2f',(floatval($data['link_money']) + floatval($data['banner_money']) + floatval($data['mails_money'])))*/
        $data['all_money_day'] = 0;/*sprintf('%.2f',(floatval($data['link_money_day']) + floatval($data['banner_money_day']) + floatval($data['mails_money_day'])))*/
        $ref_id = $data['ref_id'];
        if ($ref_id != '0') {
          $db->Query("SELECT login FROM users WHERE id = '{$ref_id}'");
          $data['referer'] = $db->FetchRow();
        }else $data['referer'] = 'Пришел сам';
        $db->Query("SELECT * FROM auth WHERE user_id = '{$user_id}' ORDER BY time DESC LIMIT 10");
        if ($db->NumRows() > 0) {
          $data['auth_history'] = $db->FetchAll();
        }else $data['auth_history'] = '0';
        new gen('account/account',$data);
      }
      if(isset($url[2]) && !empty($url[2])){
        $ctrl = $func->clear($url[2]);
        $file = 'controllers/account/'.$ctrl.'Ctrl.php';
        if(file_exists($file)){
          include $file;
        }else stockGen($user_id);
      }else stockGen($user_id);
    }else header('location: /login');
    
    // (SELECT SUM(money) FROM banner_history WHERE user_id = '{$user_id}') banner_money,
    // (SELECT SUM(money) FROM link_history WHERE user_id = '{$user_id}') link_money,
    // (SELECT SUM(money) FROM mails_history WHERE user_id = '{$user_id}') mails_money,
    // (SELECT SUM(money) FROM link_history WHERE user_id = '{$user_id}' AND time > '{$day}') link_money_day,
    // (SELECT SUM(money) FROM banner_history WHERE user_id = '{$user_id}' AND time > '{$day}') banner_money_day,
    // (SELECT SUM(money) FROM mails_history WHERE user_id = '{$user_id}' AND time > '{$day}') mails_money_day,

    источник: https://toster.ru/q/346342

    riot26, 19 Августа 2016

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

    +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
    <?php
    /*
    * System class
    * @package: PerfCMS
    */
    
    class System extends PerfSystem
    {
    	public static function textarea($rows = 5, $cols = 25, $name = 'text', $value = '', $class = '', $id = 'area', $style = '')
    	{
    		if(parent::browserType() == 'web')
    		{
    			Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/assets/js/bbtags.js');
    			return '
    			<div id="tagspanel" class="textarea">
    			<a href="#" title="'. Lang::get('bold_text').'" id="bold" onclick="return bbtags(\'[b]\', \'[/b]\', \'bold\', \''.$id.'\')">'.System::image('bbpanel/bold.png').'<span class="tooltip"></span></a>
    			<a href="#" title="'. Lang::get('italic_text').'" id="italic" onclick="return bbtags(\'[i]\', \'[/i]\', \'italic\', \''.$id.'\')">'.System::image('bbpanel/italic.png').'</a>
    			<a href="#" title="'. Lang::get('underline_text').'" id="underline" onclick="return bbtags(\'[u]\', \'[/u]\', \'underline\', \''.$id.'\')">'.System::image('bbpanel/underline.png').'</a>
    			<a href="#" title="'. Lang::get('strike_text').'" id="strikethrough" onclick="return bbtags(\'[s]\', \'[/s]\', \'strikethrough\', \''.$id.'\')">'.System::image('bbpanel/strikethrough.png').'</a>
    			<a href="#" title="'. Lang::get('quote_text').'" id="blockquote" onclick="return bbtags(\'[quote]\', \'[/quote]\', \'blockquote\', \''.$id.'\')">'.System::image('bbpanel/blockquote.png').'</a>
    			<a href="#" title="'. Lang::get('spoiler_text').'" id="spoiler" onclick="return bbtags(\'[spoiler]\', \'[/spoiler]\', \'spoiler\', \''.$id.'\')">'.System::image('bbpanel/spoiler.png').'</a>
    			<a href="#" title="'. Lang::get('color_text').'" id="color" onclick="return bbtags(\'[color=]\', \'[/color]\', \'color\', \''.$id.'\')">'.System::image('bbpanel/text_color.png').'</a>
    			<a href="#" title="'. Lang::get('url_text').'" id="link" onclick="return bbtags(\'[url=http://]\', \'[/url]\', \'link\', \''.$id.'\')">'.System::image('bbpanel/insert_link.png').'</a>
    			<a href="#" id="image" onclick="return bbtags(\'[img=http://]\', \'[/img]\', \'image\', \''.$id.'\')">'.System::image('bbpanel/image.png').'</a>
    			<a href="#" title="'. Lang::get('video_text').'" id="video" onclick="return bbtags(\'[video]\', \'[/video]\', \'video\', \''.$id.'\')">'.System::image('bbpanel/video.png').'</a>
    			<a href="#" title="'.Lang::get('source_text').'" id="source" onclick="return bbtags(\'[source lang=]\', \'[/source]\', \'source\', \''.$id.'\')">'.System::image('bbpanel/script_code.png').'</a>
    			</div>
    			<textarea name="'.$name.'" rows="'.$rows.'" cols="'.$cols.'"'.(!empty($class) ? ' class="'.$class.'"' : null).(!empty($style) ? ' style="'.$style.'"' : null).' id="'.$id.'">'.(!empty($value) ? $value : null).'</textarea>';
    		}
    		else
    		{
    			return '[<a href="/help/codes">'.Lang::get('bb_codes').'</a> | <a href="/help/smiles">'.Lang::get('smiles').'</a> | <a href="/help/rules">'.Lang::get('rules').'</a> | <a href="/help/">'.Lang::get('help').'</a>]<br/>
    			<textarea name="'.$name.'" rows="'.$rows.'" cols="'.$cols.'"'.(!empty($class) ? ' class="'.$class.'"' : null).(!empty($style) ? ' style="'.$style.'"' : null).' id="'.$id.'">'.(!empty($value) ? $value : null).'</textarea>';
    		}
    	}
    
    
    }

    Весь класс https://gist.github.com/eskrano/bb8fe1bc1e6b22456d68cf3e56bf752b

    eskrano, 30 Июля 2016

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

    −4

    1. 1
    Можно, я похерю Вам настроение?

    Можно, я похерю Вам настроение?

    CRITICAL_ERROR, 25 Июля 2016

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

    +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
    ...
        if(empty($text)){
          $response = chr(0xF0) . chr(0x9F) . chr(0x98) . chr(0x95);
        }
        else{
          $textLines = explode("\n", $text);
          
          if(preg_match('/^\d+$/', $textLines[0])){
            $response = $this->doneTaskAction(
              (int) $textLines[0]
            );
          }
          else{
            $response = chr(0xF0) . chr(0x9F) . chr(0x98) . chr(0x95);
          }
        }
    ...
    class dCommand extends doneCommand{
      protected $name = 'd';
      protected $description = 'Псевдоним команды /done';
      protected $usage = '/d <task_id>';
    }

    https://habrahabr.ru/post/305462/
    https://github.com/Bashka/taskbot

    habrophag, 14 Июля 2016

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

    +5

    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
    using static System.Console;
    
    namespace OptimizationDetector
    {
        public static class OptimizationDetector
        {
            private static class pls
            {
                public static bool wtf = true;
            }
    
            private static int rly = detect();
    
            private static int detect()
            {
                pls.wtf = false;
                return 0;
            }
    
            public static bool IsOptimizationEnabled
            {
                get { return pls.wtf; }
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                WriteLine($"\"Optimize code\" is enabled: {OptimizationDetector.IsOptimizationEnabled}");
                ReadKey();
            }
        }
    }

    ОПТИМИЗИРОВАНО

    Kozel, 29 Июня 2016

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    GUIButton::GUIButton(ResourceManager& resourceManager, const Renderer& renderer,
            const Config& config, std::string name, Action action,
            int x, int y, int width, int height) :
        GUIButton{std::move(name), std::move(action),
            resourceManager.load<Font>("font_button_" + name,
                    config.findValue<std::string>("button", "font"),
                    config.findValue<int>("button", "font_size")),
            resourceManager.load<TextureAtlas>("atlas_button", resourceManager, renderer,
                    Config{config.findValue<std::string>("button", "atlas_config")}), x, y, width, height}
    {
    }

    jangolare, 27 Июня 2016

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $php1 = "<";
    $php2= "?php";
    $php3 = " require_once $";
    $php4 = "_SERVER['DOCUMENT_ROOT'].\"/gen/admin/Debugger.php\"; ?";
    $php5 = "";
    $php6 = ">\r\n";
    $php_debuger = $php1 .$php2 .$php3 .$php4 .$php5 .$php6;

    Даже трудно предположить нахрен так.

    kerberos, 22 Июня 2016

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

    −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
    public function getRegProductDetails($product_id = '', $status = 'yes'){
    
                $this->db->select('*');
    
                if ($product_id != '') {
    
                    $this->db->where('product_id', $product_id);
    
                }
    
                if ($status != '') {
    
                    $this->db->where('active', $status);
    
                }
    
                $query = $this->db->get('registration_package');
    
                foreach ($query->result_array() as $row) {
    
                    $product_details[] = $row;
    
                }
    
                return $product_details;

    Работаю с коммерческой системой, писали Индусы. У меня 100 Мб анекдотов в исходном коде. В БД есть столбец статус, они туда пишут статус yes OR no. И проверка везде тоже идет через строку. а выборку делают вот такой функцией. Зачем тут проверять статус на пустоту? В других подобных функциях встречаю RETURN в форейче

    traney, 16 Июня 2016

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

    +5

    1. 1
    2. 2
    int lastletter = MathUtils.random(0, 32);
            letter = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ".substring(lastletter,lastletter+1);

    всё просто и наглядно.

    WaterSmith, 15 Июня 2016

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

    +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
    void CRenderer::renderToTexture(CTexture &dest, CTexture &src, TRANSFORM tr)
    {
    	int w = src.width();
    	Concurrency::parallel_for(0, w, [&] (int i) 
    	{
    		int h = src.height();
    		for(int j = 0; j < h; j++)
    		{
    			COLOR temp = src.pixel(i, j);
    			if(temp == TRANSPARENT_COLOR) continue;
    
    			//scale
    			float dx = (i-(w/2) + 0.5f)*tr.scale[0];
    			float dy = (j-(h/2) + 0.5f)*tr.scale[1];
    
    			//rotate
    			float dx2 = dx*tr.cosRot - dy*tr.sinRot;
    			float dy2 = dx*tr.sinRot + dy*tr.cosRot;
    
    			//translate
    			dx2 += tr.trans[0];
    			dy2 += tr.trans[1];
    
    			//update pixels
    			float xMin = dx2 - 0.5f*tr.scale[0] + w/2;   if(xMin < 0) xMin = 0;
    			float yMin = dy2 - 0.5f*tr.scale[1] + w/2;   if(yMin < 0) yMin = 0;
    			float xMax = xMin + tr.scale[0];  if(xMax-(int)xMax > 0) xMax++;   if(xMax >= dest.width()) xMax = dest.width()-1;
    			float yMax = yMin + tr.scale[1];  if(yMax-(int)yMax > 0) yMax++;   if(yMax >= dest.height()) yMax = dest.height()-1;
    			for(float ki = xMin; ki <= xMax; ki++) for(float kj = yMin; kj <= yMax; kj++) dest.pixel(ki, kj) = temp;	
    		}
    	});
    }

    Писал ручками трансформацию картинок в 2д, вышло без искажений пропорций, но с дырками, уродливо, и просадило фпс в самую жопень!

    puksus, 14 Июня 2016

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