1. 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)
  2. 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)
  3. Куча / Говнокод #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)
  4. Куча / Говнокод #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)
  5. 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)
  6. 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)
  7. C# / Говнокод #19838

    +17

    1. 1
    Code = string.Concat(Code1 + '/' + Code1);

    Конкат 100%

    andrew123, 18 Апреля 2016

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

    −10

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

    d_fomenok, 17 Апреля 2016

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

    −10

    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
    static bool IsPalindrome( int value ) { 
    int reverseValue = 0; 
    if(value < 0) value = -value; 
    int tempValue = value; 
    int reverseValueTens = 1; 
    while(tempValue > 0) { 
    reverseValueTens *= 10; 
    tempValue /= 10; 
    } 
    reverseValueTens /= 10; 
    tempValue = value; 
    while(tempValue > 0) { 
    //Alert( reverseAbsValueAddition ); 
    reverseValue += (tempValue - (tempValue/10)*10) * reverseValueTens; 
    reverseValueTens /= 10; 
    tempValue /= 10; 
    } 
    //Alert( reverseAbsValue ); 
    return reverseValue == value; 
    }

    d_fomenok, 17 Апреля 2016

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

    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
    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
    private void CaretNormalize()  {
                if (Template.Terminals.Count == 0) { _sTermEnd = _sOffStart = _sOffEnd = _sTermStart = 0; return; }
                if (_sTermStart == _sTermEnd) {
                    if (_sTermStart < 0) _sTermEnd = _sOffStart = _sOffEnd = _sTermStart = 0;
                    else if (_sTermEnd > Template.Terminals.Count - 1) {
                        _sTermEnd = _sTermStart = Template.Terminals.Count - 1;
                        _sOffStart = _sOffEnd = Template.Terminals[Template.Terminals.Count - 1].Text.Length;
                    }
                    else  {
                        if (_sOffStart != _sOffEnd) {
                            var nos = Math.Min(_sOffStart, _sOffEnd);
                            _sOffEnd = Math.Max(_sOffStart, _sOffEnd);
                            _sOffStart = nos;
                            if (_sOffStart < 0)  {
                                _sTermEnd = --_sTermStart;
                                if (_sTermEnd < 0) _sTermStart = _sOffStart = 0; else _sOffStart = Template.Terminals[_sTermEnd].Text.Length - 1;
                            }
                            if (_sOffEnd > Template.Terminals[_sTermEnd].Text.Length - 1) {
                                _sTermEnd = ++_sTermStart;
                                if (_sTermEnd > Template.Terminals.Count - 1)
                                {
                                    _sTermEnd = Template.Terminals.Count - 1;
                                    _sOffEnd = Template.Terminals[_sTermEnd].Text.Length;
                                }
                                else _sOffEnd = 0;
                            }
                        }
                        else
                        {
                            if (_sOffStart < 0) {
                                _sTermEnd = --_sTermStart;
                                if (_sTermEnd < 0)  _sTermStart = _sOffEnd = _sOffStart = 0; else _sOffEnd = _sOffStart = Template.Terminals[_sTermEnd].Text.Length - 1;
                            }
                            if (_sOffEnd > Template.Terminals[_sTermEnd].Text.Length - 1) {
                                _sTermEnd = ++_sTermStart;
                                if (_sTermEnd > Template.Terminals.Count - 1) {
                                    _sTermEnd = Template.Terminals.Count - 1;
                                    _sOffEnd = _sOffStart = Template.Terminals[_sTermEnd].Text.Length;
                                } else _sOffEnd = _sOffStart = 0;
                            }
                        }
                    }
                } else {
                    if (_sTermStart > _sTermEnd) {
                        var t = _sTermStart;
                        _sTermStart = _sTermEnd;
                        _sTermEnd = t;
                        t = _sOffStart;
                        _sOffStart = _sOffEnd;
                        _sOffEnd = t;
                    }
                    if (_sTermStart < 0) _sOffStart = _sTermStart = 0;
    
                    if (_sTermEnd > Template.Terminals.Count - 1) {
                        _sTermEnd = Template.Terminals.Count - 1;
                        _sOffEnd = Template.Terminals[Template.Terminals.Count - 1].Text.Length;
                    }
                    if (_sOffStart < 0) {
                        --_sTermStart;
                        if (_sTermStart < 0) _sTermStart = _sOffStart = 0; else _sOffStart = Template.Terminals[_sTermStart].Text.Length - 1;
                    }
                    if (_sOffEnd > Template.Terminals[_sTermEnd].Text.Length - 1) {
                        ++_sTermEnd;
                        if (_sTermEnd > Template.Terminals.Count - 1) {
                            _sTermEnd = Template.Terminals.Count - 1;
                            _sOffEnd = Template.Terminals[_sTermEnd].Text.Length;
                        }
                        else _sOffEnd = 0;
                    }
                }
            }

    qwe345asd, 17 Апреля 2016

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