1. JavaScript / Говнокод #19856

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    function checkPermission(user, post) {
      return equals(post.author, user) ||
             user.role = 'admin';
    }

    when you see it, you'll shit bricks

    thepotato, 21 Апреля 2016

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

    +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
    List<dynamic> reporting = item.company_profile_data?.AnnualFinancialStatementFiles ??
                                              new List<dynamic>();
                    string annual = "";
                    foreach (var report in reporting)
                    {
                        if (report.File != null)
                        {
                            string name = report.File?.Info?.Name;
                            if (name != null) annual = annual + name.Substring(0, name.LastIndexOf('.')) + ", ";
                        }
                    }
                    item.Name = annual;

    П - производительность.

    Psilon, 21 Апреля 2016

    Комментарии (13)
  3. Куча / Говнокод #19854

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?xml version="1.0" encoding="windows-1251"?>
    <Анкета ВерсияСхемы="2.05" ДатаФормирования="2016-04-19T17:04:57" ФорматДаты="ДФ=yyyy-MM-dd; ДЛФ=DT" ФорматВремени="ДФ=ЧЧ:мм:сс; ДЛФ=T" РазделительДатаВремя="T" >
     <Вопрос Ид="" Значение="">
     <Ответ Тип="Простой"></Ответ>
     <Ответ Тип="Комплексный">
     <ЧастьВопроса Тип="Компания"></ЧастьВопроса>
     <ЧастьВопроса Тип="Должность"></ЧастьВопроса>
     </Ответ>
     </Вопрос>
    </Анкета>

    Мда...

    Stefan_Hitskov, 21 Апреля 2016

    Комментарии (13)
  4. 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)
  5. 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)
  6. PHP / Говнокод #19848

    +4

    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
    // Авторизация
    $app->post('/action/login', function(Request $request, Response $response)
    {
    	global $connection, $hash;
    	
    	$data = $request->getParsedBody('login');
    	$login = $data['login'];
    	$password = md5($data['password']);
    	
    	$result = mysqli_query($connection, "SELECT `password` FROM `users` WHERE `login` = '$login'");
    	$row = $result->fetch_assoc();
    	
    	if(!empty($login) and !empty($password))
    	{
    		if($password === $row['password'])
    		{
    			$_SESSION['auth'] = $hash;
    			echo "<script>location.href='/log';</script>";
    		}
    		else
    		{
    			redirect();
    		}
    	}
    });

    st55, 19 Апреля 2016

    Комментарии (32)
  7. Куча / Говнокод #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)
  8. Куча / Говнокод #19841

    +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
    m =: 256$0
    index =: 0
    output =: 0$0
    input =: 0$0
    code =: 0$0
    cycles =: 0$0
    codeIndex =: 0
    setCode =: 3 : 'code =: transform y'
    transform =: '><+-.,[]'&i.
    preset =: 3 : 'cycles =: 0$0 [ codeIndex =: 0 [ output =: 0$0 [ m =: 256$0 [ index=:0'
    returnOutput =: 3 : 'output { a.'
    changeValue =: 3 : 'm =: (index&{.,y,(>:index)&}.) m'  
    addCodeIndex =: 3 : 'codeIndex =: (>: codeIndex)'
    setCodeIndex =: 3 : 'codeIndex =: {: cycles'
    deleteCycle =: 3 : 'cycles =: }: cycles'
    		 
    func_1 =: 3 : 'index =:256&|@>:index'
    func_2 =: 3 : 'index =:256&|@<:index'
    func_3 =: 3 : 'changeValue@(256&|)@>:@(index&{) m'
    func_4 =: 3 : 'changeValue@(256&|)@<:@(index&{) m'
    func_5 =: 3 : 'output=:output, ((index&{) m)'
    func_6 =: 3 : '(input =: }.input)[ changeValue(256&|@{.input)'
    func_7 =: 3 : 'cycles =: cycles&, codeIndex'
    func_8 =: 3 : '(setCodeIndex`deleteCycle@.(0&=))@(index&{) m'
    
    doAction =: func_1`func_2`func_3`func_4`func_5`func_6`func_7`func_8@.]  
    doInstuction =: 3 : '(doAction[addCodeIndex)@{.@(codeIndex&{) code'
    ExitCond =: 3 : 'codeIndex = (# code)'
    		 
    interpreter =: 3 : '(((,&1 [ doInstuction )`0: @. ExitCond)^:_) 0'
    brainFuck =: returnOutput [ interpreter [ setCode [ preset
    
    brainFuck '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.'

    интерпретатор брейнфака на J

    kegdan, 19 Апреля 2016

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

    −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
    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
    namespace raytracing
    {
        struct Scene::Implementation
        {
            std::vector<std::unique_ptr<RenderObject>> renderObjects;
            std::vector<Light> lights;
            Camera camera;
        };
    }
    
    Scene::Scene() :
        implementation{std::make_unique<Implementation>()}
    {
    }
    
    void Scene::insertObject(RenderObject* renderObject) noexcept
    {
        implementation->renderObjects.push_back(std::unique_ptr<RenderObject>{renderObject});
    }
    
    const RenderObject* Scene::getIntersectedObject(Ray ray, vec3f* intersectionPoint) const noexcept
    {
        const auto& renderObjects = implementation->renderObjects;
    
        if (renderObjects.empty())
            return nullptr;
    
        struct IntersectionData
        {
            const RenderObject* renderObject;
            float t;
            bool isIntersect;
            vec3f intersectionPoint;
        } temp{};
    
        for (decltype(implementation->renderObjects)::const_iterator iter = renderObjects.cbegin();
                iter != renderObjects.cend(); ++iter)
        {
            IntersectionData intersectionData;
    
            intersectionData.renderObject = (*iter).get();
            intersectionData.isIntersect = (*iter)->isIntersect(ray, intersectionData.t,
                    &intersectionData.intersectionPoint);
    
            if (intersectionData.isIntersect)
            {
                if (temp.isIntersect)
                {
                    if (temp.t > intersectionData.t)
                        temp   = intersectionData;
                }
                else
                    temp = intersectionData;
            }
        }
    
        if (intersectionPoint)
            *intersectionPoint = temp.intersectionPoint;
    
        return temp.renderObject;
    }
    
    namespace raytracing
    {
        struct Renderer::Implementation
        {
            vec3f trace(const Scene& scene, Ray ray) const noexcept
            {
                vec3f intersectionPoint;
                const RenderObject* const renderObject = scene.getIntersectedObject(ray, &intersectionPoint);
    
                vec3f color{};
    
                if (!renderObject)
                    return color;
    
                for (Light l : scene.getLights())
                {
                    const Ray lightRay{intersectionPoint, (l.position - intersectionPoint).normalize()};
    
                    float brightness = renderObject->getNormal(intersectionPoint).dot(lightRay.direction);
                    if (brightness < 0.0F)
                        brightness = 0.0F;
    
                    color += renderObject->getColor(intersectionPoint) * 255.0F * brightness;
                }
    
                return color;
            }
        }
    }

    Сумеете ли вы найти ошибку?

    jangolare, 18 Апреля 2016

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    var pricerawjson = "%7B%22price%22%3A%226973.00%22%2C%22status%22%3A%22active%22%2C%22sell_status%22%3A%22available%22%2C%22old_price%22%3A%227607.0000%22%2C%22price_formatted%22%3A%226%20973%22%2C%22old_price_formatted%22%3A%227%20607%22%7D";
    if (pricerawjson.length == 0) {
          pricerawjson = '%7B%22price%22%3A%226973%22%2C%22price_formatted%22%3A%226%20973%22%2C%22old_price%22%3A7607%2C%22old_price_formatted%22%3A%227%20607%22%2C%22status%22%3A%22active%22%2C%22sell_status%22%3A%22available%22%7D';
    }

    kyzi007, 18 Апреля 2016

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