1. Список говнокодов пользователя YpaHeLI_

    Всего: 15

  2. C++ / Говнокод #28624

    +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
    while (!cmpts.empty() && !ec)
        {
          path f = std::move(cmpts.front());
          cmpts.pop_front();
    
          if (f.empty())
    	{
    	  // ignore empty element
    	}
          else if (is_dot(f))
    	{
    	  if (!is_directory(result, ec) && !ec)
    	    ec.assign(ENOTDIR, std::generic_category());
    	}
          else if (is_dotdot(f))
    	{
    	  auto parent = result.parent_path();
    	  if (parent.empty())
    	    result = pa.root_path();
    	  else
    	    result.swap(parent);
    	}
          else
    	{
    	  result /= f;
    
    	  if (is_symlink(result, ec))
    	    {
    	      path link = read_symlink(result, ec);
    	      if (!ec)
    		{
    		  if (--max_allowed_symlinks == 0)
    		    ec.assign(ELOOP, std::generic_category());
    		  else
    		    {
    		      if (link.is_absolute())
    			{
    			  result = link.root_path();
    			  link = link.relative_path();
    			}
    		      else
    			result = result.parent_path();
    
    		      cmpts.insert(cmpts.begin(), link.begin(), link.end());
    		    }
    		}
    	    }
    	}
        }

    Это из GNU libstdc++.
    Код то может и не говно, но от форматирования блевать тянет.
    Зачем такое кто знает?

    YpaHeLI_, 06 Марта 2023

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

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Решил поставить пароль на BIOS (UEFI), но и он, оказывается, не панацея.
    Если ты параноик, то просто таскай ноутбук с собой, а вот если у тебя системник - смирись, за тобой могут следить.
    
    https://techarks.ru/windows/bios/kak-vosstanovit-ili-ustanovit-parol-bios-ili-uefi-dlya-kompyuterov-s-windows/
    https://habr.com/ru/post/128466/

    YpaHeLI_, 24 Ноября 2022

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

    −3

    1. 1
    Ну и как вы стали сеньорами? Делитесь опытом.

    YpaHeLI_, 06 Октября 2022

    Комментарии (64)
  5. Куча / Говнокод #28375

    −4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    На работе такая таска:
    Есть сервис, который запускает наши сервисы и следит за ними, напр. перезапускает, если один из них упал.
    Таска такая, что нужно посылать всем сервисам сообщения из командной строки.
    Т.е. уже можно послать сигналы из командной строки (SIGTERM, SIGHUP, и.т.д)
    `svctl -s stop` - наример.
    Но теперь нужно посылать SIGUSR1, перед этим записав в файл сообщение, тоже переданное из командной строки. Все запущенные сервисы по этому сигналу должны прочитать файл с сообщением и обработать его.
    И вот тут я сомневаюсь, что так правильно.
    1. Может лучше открыть именованный канал, и туда всё посылать, без сигналов? Но тут треды и код усложнится, а проект простой, на 20 методов в двух классах.
    2. Если это всё же правильно, то вместо файла тоже может использовать именованный канал для обмена сообщениями?

    YpaHeLI_, 19 Сентября 2022

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

    +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
    <?php defined('SYSPATH') or die('No direct script access.');
    /*
     * Базовый класс главной страницы
     */
    class Controller_Index extends Controller {
    
    
            public function before() {
                    parent::before();
                    I18n::lang('ru');
                    $settings = Kohana::config('settings');
                    Cookie::$salt = 'asd12d2';
                    Session::$default = 'cookie';
                    $this->session = Session::instance();
            }
    
        public function action_index() {
    
            //Путь до файла первоночального xml (xsl)
            $path_xml='tpl/xml.xsl';
            //Путь конечного xsl
            $path_xsl='tpl/index.xsl';
    
            $url = $this->request->param('stuff');
                    //print_r($_SERVER);
                    /*if($_SERVER ['REQUEST_URI']=='/'){
                            $this->request->redirect($_SERVER ['HTTP_X_FORWARDED_PROTO'].'://'.$_SERVER['HTTP_HOST'],'301');
                    }*/
            if(empty($url)){
                $url='/';
            }
    
    
            $htmlfile='cache-html/'.md5($url);
    $allurl=$_SERVER ['REQUEST_URI'];
    if($allurl=='/20-40-kvm') $this->request->redirect('/sadovye-domiki','301');
    if($allurl=='/40-80-kvm') $this->request->redirect('/sadovye-domiki','301');
    if($allurl=='/80-i-bolee-kvm') $this->request->redirect('/sadovye-domiki','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=0&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/sadovye-domiki','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=1&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=81-400') $this->request->redirect('/80-i-bolee-kvm','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=1&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=40-80') $this->request->redirect('/40-80-kvm','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/stroitelstvo-dachnyh-domov','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=2&technology%5B%5D=0&technology%5B%5D=1&technology%5B%5D=2&technology%5B%5D=3&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/kottedzhi','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=0&technology%5B%5D=2&technology%5B%5D=3&floors%5B%5D=1&floors%5B%5D=1.5&price=0-3000000&area=0-400') $this->request->redirect('/bani','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&price=0-3000000&area=0-400') $this->request->redirect('/bani-iz-profilirovannogo-brusa','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=0&floors%5B%5D=1&floors%5B%5D=1.5&price=0-3000000&area=0-400') $this->request->redirect('/karkasnye-bani','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=3&technology%5B%5D=3&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/bani-iz-ocilindrovannogo-brevna','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=316018-3000000&area=0-400') $this->request->redirect('/brus','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=2&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/kottedzhi-profilirovannyj-brus','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=0&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=329056-3000000&area=0-400') $this->request->redirect('/dachnye-doma-karkasnaya-tehnologiya','301');
    
    if($allurl=='/nashi-proecty?searcher=48291&section=3924&destination%5B%5D=0&destination%5B%5D=1&destination%5B%5D=2&technology%5B%5D=1&floors%5B%5D=1&floors%5B%5D=1.5&floors%5B%5D=2&price=0-3000000&area=0-400') $this->request->redirect('/individualnye-proekty','301');

    Там ещё дальше веселье продолжается, но гк не дает запостить больше

    YpaHeLI_, 02 Апреля 2022

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

    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
    function normalizeUrl($url)
    {
        if (strpos($url, 'http://') === 0) {  
             $domain = substr($url, 7);
         } elseif (strpos($url, 'https://') === 0) {
              $domain = substr($url, 8);
         } else {
              $domain = $url;
         }
    
         return "https://{$domain}";
    }

    YpaHeLI_, 27 Декабря 2021

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

    +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
    struct file_id
    {
        uint64_t        persistent;
        uint64_t        volatile_;
    
        static const size_t RAW_LENGTH  = 16;
        operator std::string() const
        { return std::string(reinterpret_cast<const char*>(&persistent), RAW_LENGTH); }
    
        // Операторы для использования file_id в качестве ключа map и 
        // unordered_map
        struct hash
        {
            std::size_t operator()(const ntdec_smb2_file_id& file_id) const
            {
                std::string s_file_id = file_id;
                std::hash<std::string> hasher;
                return hasher(s_file_id);
            }
        };
    
        bool operator == (const ntdec_smb2_file_id& other)
        {
            return std::string(*this) == std::string(other);
        }
    
        bool operator < (const ntdec_smb2_file_id& other)
        {
            return std::string(*this) < std::string(other);
        }
    
        bool operator > (const ntdec_smb2_file_id& other)
        {
            return std::string(*this) > std::string(other);
        }
    };

    operator std::string тоже UB?

    YpaHeLI_, 24 Августа 2021

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #include <iostream>
    #include <map>
    
    int main()
    {
      std::string name;
      std::map<int, int> m = { {1, 1}, {2, 2} };
      m.erase(m.end());
      std::cout << "Kokoko " << m[1] << std::endl;
    }

    На моем проекте уходит в бесконечный цикл.

    YpaHeLI_, 08 Июня 2021

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

    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
    // Приведение численного типа к структуре с битовыми полями
    template <class STRUCT_T, typename T>
    STRUCT_T struct_cast(const T n)
    {
        static_assert(std::is_integral<T>::value, "Integral type required as T");
        static_assert(std::is_class<STRUCT_T>::value, "class or struct type required as STRUCT_T");
        static_assert(sizeof(T) == sizeof(STRUCT_T), "Incompatible types passed");
    
        return *(reinterpret_cast<const STRUCT_T*>(&n));
    }
    
    // Приведение структур с битовыми полями к численному типу
    template <typename T, class STRUCT_T>
    T integral_cast(const STRUCT_T& s)
    {
        static_assert(std::is_integral<T>::value, "Integral type required as T");
        static_assert(std::is_class<STRUCT_T>::value, "class or struct type required as STRUCT_T");
        static_assert(sizeof(T) == sizeof(STRUCT_T), "Incompatible types passed");
    
        return *(reinterpret_cast<const T*>(&s));
    }

    Почему это UB?

    YpaHeLI_, 12 Мая 2021

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Скорость SSD - ~450 мбайт/сек.
    Скорость RAM - ~6000 мбайт/сек.
    
    Так и не пойму тогда, зачем юзать SSD, когда можно поставить много оперативки и минимизировать обращения к свопу, тем самым минимизировать тормознутость системы?
    Я именно про рабочую станцию, ясно что на сервере будет выигрыш.

    YpaHeLI_, 15 Февраля 2021

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