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

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

    +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
    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
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    void CScene::IncludeObjects()
    {
    // Reset All.
    	ExcludeObjects();
    
    // fill Vershiny of piramid...
    	point3d versh[4];
    	point3d eye = {IniSet.ptCamPos.x, IniSet.ptCamPos.y, IniSet.ptCamPos.z};
    	Screen2World(0, 0, versh[0]);
    	Screen2World(nScreenSzX, 0, versh[1]);
    	Screen2World(nScreenSzX, nScreenSzY, versh[2]);
    	Screen2World(0, nScreenSzY, versh[3]);
    
    // Increase before OO...
    	
    	int ix, sz = parrObjs.Size();
    	point3d vect;
    	for(ix = 0; ix < 4; ix++){
    		sub_vectors(&vect.x, &versh[ix].x, &eye.x);
    		norm_vect(&vect.x);
    		scale_vect(&vect.x, 200.f);
    		versh[ix] = vect;
    	}
    
    // Create faces of piramid and search collision with it...
    	point3d Piramid[4][3];
    	Piramid[0][0] = eye;
    	Piramid[1][0] = eye;
    	Piramid[2][0] = eye;
    	Piramid[3][0] = eye;
    	Piramid[0][1] = versh[0];
    	Piramid[0][2] = versh[1];
    	Piramid[1][1] = versh[1];
    	Piramid[1][2] = versh[2];
    	Piramid[2][1] = versh[2];
    	Piramid[2][2] = versh[3];
    	Piramid[3][1] = versh[3];
    	Piramid[3][2] = versh[0];
    	
    // Dyadya WALERA!!!!
    	for(ix = nObjOff; ix < sz; ix++){
    		CObj3d *pObj = parrObjs.e(ix);
    		pObj->Transform(FALSE);
    		point3d ptPos = pObj->GetPosition();
    
    		if(IniSet.nIncludeObjectMode == WS_INCLUDE_BARYCENTER){
    			point3d ptCentr = IniSet.ptCamTarget;
    			point3d vtVect;
    			
    			sub_vectors(&vtVect.x, &ptPos.x, &ptCentr.x);
    
    			plane plGran;
    			point3d ptCross;
    			for(int jx = 0; jx < 4; jx++){
    				comp_plane_eqn(&plGran.a, &Piramid[jx][0].x, &Piramid[jx][1].x, &Piramid[jx][2].x);
    				cross_line_plane(vtVect, &plGran.a, ptCentr, ptCross);
    				float f1, f2;
    				f1 = plGran.a * ptPos.x + plGran.b * ptPos.y + plGran.c * ptPos.z + plGran.d;
    				f2 = plGran.a * ptCentr.x + plGran.b * ptCentr.y + plGran.c * ptCentr.z + plGran.d;
    				if(f1 * f2 < 0.f){
    					if(point_in_triangle(Piramid[jx][0], Piramid[jx][1], Piramid[jx][2], ptCross)){
    						ptCross = ConvertPos3D(ptCross);
    						if(IniSet.bMirrorH){ ptCross.y = -ptCross.y; }
    						if(IniSet.bMirrorV){ ptCross.x = -ptCross.x; }
    						if(IniSet.bMirrorD){ ptCross.z = -ptCross.z; }
    
    						transform_back_point(&ptCross, &ptCross, &IniSet.mtMatr);
    						pObj->ptSavedPos = ptCross;
    						break;
    					}
    				}
    			}
    		}else{ // XYZ Axes.
    			point3d vtXYZ[3] = {{1.f, 0.f, 0.f},
    								{0.f, 1.f, 0.f},
    								{0.f, 0.f, 1.f}};
    
    			BOOL bFound = FALSE;
    			for(int ax = 0; ax < 3; ax++){
    
    				point3d vtVect;
    				transform_point(&vtVect, &vtXYZ[ax], &IniSet.mtMatr);
    				
    				for(int jx = 0; jx < 4; jx++){
    					plane plGran;
    					comp_plane_eqn(&plGran.a, &Piramid[jx][0].x, &Piramid[jx][1].x, &Piramid[jx][2].x);
    					
    					point3d ptCentr = IniSet.ptCamTarget;
    
    					point3d ptCross;
    					cross_line_plane(vtVect, &plGran.a, ptPos, ptCross);
    					float f1, f2;
    
    					f1 = plGran.a * ptPos.x + plGran.b * ptPos.y + plGran.c * ptPos.z + plGran.d;
    					f2 = plGran.a * ptCentr.x + plGran.b * ptCentr.y + plGran.c * ptCentr.z + plGran.d;
    
    					point3d vtDif;
    					sub_vectors(&vtDif.x, &ptCross.x, &IniSet.ptCamPos.x);
    					if(vec_length(&vtDif.x) < 0.01f){ continue; } // avoid crossing with eye.

    Гавнокод: включить все 3Д объекты в экран.

    falcoware, 21 Апреля 2016

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

    +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
    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
    public function get($userId = null, $advense = false) {
            
            if ($userId === null) $userId = $this->currentId;
            
            $user = DB::table('users')
                    ->select(
                            '*',
                            DB::raw('IF(email IS NOT NULL AND email_confirm IS NULL, 1, 0) AS email_confirm'),
                            DB::raw('IF(phone IS NOT NULL AND phone_confirm IS NULL, 1, 0) AS phone_confirm'),
                            DB::raw('IF(birthday IS NOT NULL, TIMESTAMPDIFF(YEAR,birthday,CURDATE()), NULL) AS age'),
                            DB::raw('IF(phone IS NOT NULL AND phone_confirm IS NULL AND email IS NOT NULL AND email_confirm IS NULL AND (new_first_name IS NOT NULL OR new_last_name IS NOT NULL OR new_status_text IS NOT NULL OR new_image_url IS NOT NULL), 1, 0) AS on_moderate'))
                    ->where('id', $userId)->first();
            
            if ($user === null) throw new Exception ('User is not found', 404);
            unset($user->password);
            $user->locality           = Geo::get($user->locality_id);
            $rating = $this->rating($userId);
            $user->rating           = (float)$rating->avg;
            $user->rating_counter   = (int)$rating->cnt;
            $user->counters        = $this->getCounters($userId);
    
            
            $contact = $this->contacts->isMyContact($userId);
            if ($userId != $this->currentId) {
                $user->created = null;
                $user->updated = null;
                $user->birthday = null;
                $user->email_confirm = null;
                $user->phone_confirm = null;
                $user->subscribed = null;
                $user->organizations = null;
                $contact = $this->contacts->isMyContact($userId);
                // Если пользователь не контакт авторизованного, сотрем контактную информацию
                if ( $contact === null || $contact === 'declined') {
                    $user->phone = null;
                    $user->email = null;
                    $user->last_name = mb_substr($user->last_name, 0, 1, 'UTF-8');
                }
                
            } else {
                if($user->new_first_name !== null) {
                    $user->first_name = $user->new_first_name;
                }
                if($user->new_last_name !== null) {
                    $user->last_name = $user->new_last_name;
                }
                if($user->new_image_url !== null) {
                    $user->image_url = $user->new_image_url;
                }
                if($user->new_status_text !== null) {
                    $user->status_text = $user->new_status_text;
                }
                $user->organizations = Organizations\Organizations::getByUserId($userId);
                $user->is_followed     = null;
                $user->is_my_contact   = null;
                $user->has_my_contact  = null;
                $user->has_my_opinion  = null;
            }
            unset($user->new_status_text);
            unset($user->new_image_url);
            unset($user->new_last_name);
            unset($user->new_first_name);
            unset($user->reset_code);
    
            
            $user->is_followed     = $this->followers->isFollowed($userId);
            $user->is_my_contact   = $this->contacts->isMyContact($userId);
            $user->has_my_contact  = $this->contacts->hasMyContact($userId);
            return $user;
            
        }

    Тыдыдыдыдыыыц, laravel code О_О
    Что же тут вообще происходит?

    lemax, 20 Апреля 2016

    Комментарии (10)
  4. Куча / Говнокод #19845

    −10

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (0) {
      unserialize ("");
      is_bool ("");
      is_array ("");
      is_string ("");
      is_integer ("");
      is_float ("");
    }

    github.com/vk-com/kphp-kdb/blob/master/KPHP/functions.txt

    d_fomenok, 19 Апреля 2016

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

    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
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    <script type="text/javascript">
            var currentLeveler = 0;
            var currentPrefix = 'povorot_';
            var currentPart = 0;
            var partsCount = [];
            var oldPart, oldLeveler;
            languagePrefix = "<?php echo $lang; ?>";
            partsCount[0] = 5;
            partsCount[1] = 4;
            partsCount[2] = 3;
    
            var levelersInfo = [[], [], []];
            var levelerParts = [[], [], []];
            var content = [];
    
            <?php
                while($row = mysql_fetch_array($tmp)){
                    $content[$row['block_id']] = $row['cont'];
                    echo "content[\"" .$row['block_id']. "\"] = '".$row['cont']."';\n";
                }
                for($j = 0; $j < 3; $j++)
                    for($i = 0; $i < 5; $i++){
    
                        $val1 = $content[$lang."_tech_leveler_info_".$j.$i];
                        $val2 = $content[$lang."_tech_part_info_".$j.$i];
                  
                        echo "levelersInfo[".$j."].push('".$val1."');";
                        echo "levelerParts[".$j."].push('".$val2."');";
                    }
            ?>
            $(document).ready(function () {
                $.each($(".changeable"), function () {
                    $(this).html(content[$(this).attr("id")]);
                });
            });
        </script>

    Формируем js код, через PHP на основе данных из базы данных... или в жопку аякс

    perryutkonos, 08 Апреля 2016

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

    +6

    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
    #ifdef _WIN32
    ...
    #elif defined __linux__
                std::string path;
                char buff[PATH_MAX];
                ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
                if (len != -1)
                {
                  buff[len] = '\0';
                  path = buff;
                }
                else
                {
                    return -1;
                }
    
                int pos = path.rfind("/");
                if (pos == std::string::npos)
                    return - 1;
    
                path = path.substr(0, pos + 1);
                path += "updater";
                std::string sys_path = path;
                boost::replace_all(sys_path, " ", "\\ ");
                std::string rm = "rm -f ";
                rm += sys_path;
                system(rm.c_str());
                _data.save_2_file(core::tools::from_utf8(path));
                std::string chmod = "chmod 755 ";
                chmod += sys_path;
                system(chmod.c_str());
                system(sys_path.c_str());
    #endif //_WIN32

    Как правильно обновлять #mailru/icqdesktop на Linux, если вы понимаете о чём я.

    gmmephisto, 31 Марта 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static bool AddStringIfNoExist(this List<string> strlist, string str)
    {
        if (str == "") return true;
        foreach (string s in strlist) if (s == str) return true;
        strlist.Add(str);
        return false;
    }

    Hashset? А что это такое?

    kerman, 29 Марта 2016

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

    −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
    <?php
    echo '<form method="post">';
    echo '<select name="table" size="1" >';
    echo '<option selected="selected" value="second">Выберите ресурсы </option>';
    echo '<option value="zerno"> Зерно </option>';
    echo '<option value="kykyr"> Кукуруза </option>'; 
    echo '<option value="lucern"> Люцерна </option>'; 
    echo '<option value="korov"> Корова </option>'; 
    echo '<option value="svin"> Свинья </option>'; 
    echo '<option value="riba"> Рыба </option>'; 
    echo '<option value="kombik"> Комбикорм </option>'; 
    echo '<option value="xleb"> Хлеб </option>'; 
    echo '<option value="myaso"> Мясо </option>';
    echo '<option value="moloko"> Молоко </option>';
    echo '<option value="navoz"> Навоз </option>';
    echo '</select>';
    echo '<input type="submit" value="Выбрать" />';
    echo '</form>';
    
    if ($_POST['table']=='zerno') $table=$_POST['table'];
    if ($_POST['table']=='kykyr') $table=$_POST['table'];
    if ($_POST['table']=='lucern') $table=$_POST['table'];
    if ($_POST['table']=='korov') $table=$_POST['table'];
    if ($_POST['table']=='svin') $table=$_POST['table'];
    if ($_POST['table']=='riba') $table=$_POST['table'];
    if ($_POST['table']=='kombik') $table=$_POST['table'];
    if ($_POST['table']=='xleb') $table=$_POST['table'];
    if ($_POST['table']=='myaso') $table=$_POST['table'];
    if ($_POST['table']=='moloko') $table=$_POST['table'];
    if ($_POST['table']=='navoz') $table=$_POST['table'];

    sliper, 28 Марта 2016

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

    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
    public destinationChanged(element: string): boolean {
                if (Boolean(this.scope.newDestination)) {
                    if (element == "input") {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    if (element == "select") {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
    
    Разметочка:
    <div ng-show="controller.destinationChanged('select')">
    <!---->
     </div>
    
    <div ng-show="controller.destinationChanged('input')">
    <!---->
     </div>

    Удаление гланд широко известным способом

    kir_rik, 25 Марта 2016

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
      * @brief Макрос вызова функции изменения имени файла лога ПИМ
      *
      * @param FILE_NAME  Имя файла лога
      *
      * @return Ничего
      */
    #define LOG_PIM_SET_FILE_NAME(FILE_NAME)  Soc::setLogFileName(FILE_NAME)

    Самый нужный макрос в мире

    cpp_best_practo, 17 Марта 2016

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

    +6

    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
    function utf8ToCp1251($s,$type="w") {
        if ((is_string($s) && strlen($s)>0) && ((mb_detect_encoding($s,'UTF-8,CP1251')) == "UTF-8"))    { 
            $out="";
            for ($c=0;$c<strlen($s);$c++)         { 
                $i=ord($s[$c]); 
                if ($i<=127) @$out.=$s[$c]; 
                if (@$byte2)     { 
                    $new_c2=($c1&3)*64+($i&63); 
                    $new_c1=($c1>>2)&5; 
                    $new_i=$new_c1*256+$new_c2; 
                    if ($new_i==1025) { 
                        $out_i=168; 
                    } else { 
                        if ($new_i==1105) { 
                            $out_i=184;
                        } else { 
                        $out_i=$new_i-848; 
                        } 
                    } 
                    @$out.=chr($out_i); 
                    $byte2=false; 
                } 
                
                if (($i>>5)==6)  { 
                  $c1=$i; 
                  $byte2=true; 
                } 
            } 
            return $out; 
        } 
        else return $s; 
    }

    Одна из стандартных функций битрикса.
    Видимо iconv им не знаком...

    tanur, 17 Марта 2016

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