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

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

    +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
    struct S { struct Inner { }; };
    template<int N> struct X;
    auto refl = ˆS;
    auto tmpl = ˆX;
    void f() {
    typename [:refl:] * x; // OK: declares x to be a pointer-to-S
    [:refl:] * x; // error: attempt to multiply int by x
    [:refl:]::Inner i; // OK: splice as part of a nested-name-specifier
    typename [:refl:]{}; // OK: default-constructs an S temporary
    using T = [:refl:]; // OK: operand must be a type
    struct C : [:refl:] {}; // OK: base classes are types
    template [:tmpl:]<0>; // OK: names the specialization
    [:tmpl:] < 0 > x; // error: attempt to compare X with 0
    }

    и да, это приняли.
    https://lists.isocpp.org/sg7/2021/04/0226.php
    http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2320r0.pdf

    digitalEugene, 07 Января 2022

    Комментарии (242)
  3. SQL / Говнокод #27925

    +2

    1. 1
    select sum(sma) as ism from Jur_7.ss2022_1 where ch=1 and gd*100+ms<2022*100+1

    Нашел БД с ОТДЕЛЬНОЙ таблицей на каждый месяц (начиная с 2008 года). А тут еще и дата определяется....

    Baiumka, 06 Января 2022

    Комментарии (1)
  4. Java / Говнокод #27903

    +2

    1. 1
    2. 2
    - null, null, null, null, null, null, null, null, null, null, null, null, null, null))
    + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null))

    Это реальный коммит с работы
    (не мой, я к jawa не притрагиваюсь)

    3_dar, 30 Декабря 2021

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

    +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
    Новогодний оффтоп #2
    ░░░░░░░░░░░░░░░░░▐▌░░░░░░░░░░░░░░░░░
    ░░░░░░░░░░░░░░░▀████▀░░░░░░░░░░░░░░░
    ░░░░░░░░░░░░░░░▄█▀▀█▄░░░░░░░░░░░░░░░
    ░░░░░░░░░░░░░░░░░▄▄░░░░░░░░░░░░░░░░░
    ░░░░░░░░░░░░░░░▄████▄░░░░░░░░░░░░░░░
    ░░░░░░░░░░░▄▄██╬██╬████▄▄░░░░░░░░░░░
    ░░░░░░░░▀███████╬███╬██████▀░░░░░░░░
    ░░░░░░░░░░▄▄█╬████╬█████▄▄░░░░░░░░░░
    ░░░░▄▄▄▄██╬████╬█████╬███╬██▄▄▄▄░░░░
    ░░░░░░▀▀████╬█████╬█████████▀▀░░░░░░
    ░░░░░░░░░▄█████╬██████╬███▄░░░░░░░░░
    ░░▄▄▄▄██████╬█████╬███████╬███▄▄▄▄░░
    ░░▀▀▀████╬█████╬████╬███╬██████▀▀▀░░
    ░░░░░░░░████╬████████╬██████░░░░░░░░
    ░░▄▄▄█████╬██████╬█████╬███╬███▄▄▄░░
    ▀▀▀████╬█████╬█████╬████╬███╬████▀▀▀
    ░░░░░░▀▀▀██████████████████▀▀▀░░░░░░
    ░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░
    ░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░

    #1: https://govnokod.ru/27188 https://govnokod.xyz/_27188

    bormandinho, 24 Декабря 2021

    Комментарии (536)
  6. bash / Говнокод #27876

    +2

    1. 1
    2. 2
    3. 3
    export $(grep PROJECT_NAME .env | xargs)
    export $(grep USERID .env | xargs)
    docker exec -it -u ${USERID} ${PROJECT_NAME}_application bash -l

    На минуточку в проекте написанный лично разрабом до меня docker-compose.

    TrueGameover, 15 Декабря 2021

    Комментарии (24)
  7. Python / Говнокод #27865

    +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
    def export_to_csv(model, fields=None, related_models=[]):
        def export(request):
            meta = model._meta
            queryset = model.objects.all()
            
            if fields is not None:
                field_names = fields
            elif 'Shops' in related_models and 'Spots' in related_models:
                field_names = [field.name for field in Shops._meta.fields] +\
                    [field.name for field in Spots._meta.fields]
            elif 'Products' in related_models and 'Spots' in related_models:
                field_names = [field.name for field in Products._meta.fields] +\
                    [field.name for field in Spots._meta.fields]
            else:
                field_names = []
                for field in meta.fields:
                    if not field.name in FORBIDDEN_FIELDS:
                        field_names.append(field.name)
    
            response = HttpResponse(content_type='text/csv')
            response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
            response.write(u'\ufeff'.encode('utf8'))
    
            writer = csv.writer(response, delimiter=',', lineterminator='\n', quoting=csv.QUOTE_ALL, dialect='excel')
            writer.writerow(field_names)
    
            if len(related_models) == 0:
                for obj in queryset:
                    row = writer.writerow([getattr(obj, field) for field in field_names])
    
            elif 'Shops' in related_models and 'Spots' in related_models:
                shops_fields = [field.name for field in Shops._meta.fields]
                contact_fields = [field.name for field in Spots._meta.fields]
    
                for obj in queryset:
                    row = []
    
                    if obj.Shops is not None:
                        row += [getattr(obj.Shops, field) for field in shops_fields]
                    else:
                        row += ['' for field in shops_fields]
    
                    if obj.Contact is not None:
                        row += [getattr(obj.Contact, field) for field in contact_fields]
                    else:
                        row += ['' for field in contact_fields]
    
                    writer.writerow(row)
                
            elif 'Products' in related_models and 'Spots' in related_models:
                products_fields = [field.name for field in Products._meta.fields]
                contact_fields = [field.name for field in Spots._meta.fields]
                
                for obj in queryset:
                    row = []
                    
                    if obj.Products is not None:
                        row += [getattr(obj.Products, field) for field in products_fields]
                    else:
                        row += ['' for field in products_fields]
    
                    if obj.Contact is not None:
                        row += [getattr(obj.Contact, field) for field in contact_fields]
                    else:
                        row += ['' for field in contact_fields]
                    
                    writer.writerow(row)
    
            return response
    
        return export

    В юности нагородила вот такую портянку для экспорта в csv связных между собой таблиц. Связка данных на уровне DAO-шки (в терминологии Джанго - Managers)? Пфф... Только инжект if-else с копипастой связки данных, только хардкор!

    JaneBurt, 11 Декабря 2021

    Комментарии (331)
  8. Куча / Говнокод #27861

    +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
    RUN apt install -y apache2
    RUN apt install -y php
    RUN apt install -y php-mysql
    RUN apt install -y libapache2-mod-php
    RUN apt install -y curl
    RUN apt install -y php-mbstring
    RUN apt install -y php-mysql
    RUN apt install -y php7.4-sqlite3
    RUN apt install -y php-gd
    RUN apt install -y php-intl
    RUN apt install -y php-xml
    RUN apt install -y php-curl
    
    #RUN apt install -y php7.0-ffmpeg
    
    RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.4/apache2/php.ini
    RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.4/cli/php.ini
    
    RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
    RUN echo "IncludeOptional /var/www/*.conf" >> /etc/apache2/apache2.conf
    #RUN sed -i "s/<\/VirtualHost>/Проверка\n<\/VirtualHost>" /etc/apache2/apache2.conf
    RUN sed -i "s/<\/VirtualHost>/\n\t<Directory \/var\/www\/html>\n\t<\/Directory>\n<\/VirtualHost>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tOptions Indexes FollowSymLinks MultiViews\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tAllowOverride All\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tOrder allow,deny\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tAllow from all\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tRequire all granted\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN mv /etc/apache2/sites-enabled/000-default.conf /tmp
    RUN cd /etc/apache2/sites-enabled/; ln -s ../sites-available/000-default.conf 000-default.conf
    RUN a2enmod php7.4
    RUN a2enmod rewrite
    #RUM apt install -y certbot
    #RUN a2enmod python-certbot-apache
    #RUN a2enmod ssl
    EXPOSE 80
    EXPOSE 22
    
    #        <Directory /var/www/html>
    #                Options Indexes FollowSymLinks MultiViews
    #                AllowOverride All
    #                Order allow,deny
    #                Allow from all
    #                Require all granted
    #        </Directory>
    
    RUN wget -O /var/www/html/index.phar https://github.com/mpak2/mpak.su/raw/master/phar/index.phar
    RUN wget -O /var/www/html/.htaccess https://github.com/mpak2/mpak.su/raw/master/.htaccess
    RUN wget -O /var/www/html/.htdb https://github.com/mpak2/mpak.su/raw/master/.htdb
    RUN chown www-data /var/www/html/.htdb
    RUN chown www-data /var/www/html
    RUN mkdir /var/www/html/include
    RUN mkdir /var/www/html/include/images
    RUN chmod 0777 /var/www/html/include/images
    RUN rm /var/www/html/index.html

    https://github.com/mpak2/mpak.su/blob/654b7daf0b7d4f3c83385c0ca35fcab6a1ec45f7/phar/docker/www/Dockerfile

    ISO, 07 Декабря 2021

    Комментарии (21)
  9. Куча / Говнокод #27851

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    Ltac2 make_match fields :=
      destruct x;
      iter (fun a => focus 1 1 (fun () =>
                               let a := a ()
                               in refine (fun () => '((w_rep $a) _)))
             ) fields.

    Итерация по конструкторам индуктивного типа данных.

    CHayT, 03 Декабря 2021

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

    +2

    1. 1
    2. 2
    3. 3
    // Create a Version 4 UUID, panicking on error.
    // Use this form to initialize package-level variables.
    var u1 = uuid.Must(uuid.NewV4())

    https://github.com/gofrs/uuid

    Питули запилили функцию, которая никогда error не возвращает, и запилили обёртку вокруг неё для "игнорирования" этой "ошибки".
    Пиздец

    3_dar, 02 Декабря 2021

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

    +2

    1. 1
    IT Оффтоп #135

    #105: https://govnokod.ru/27544 https://govnokod.xyz/_27544
    #106: https://govnokod.ru/27552 https://govnokod.xyz/_27552
    #107: https://govnokod.ru/27554 https://govnokod.xyz/_27554
    #108: https://govnokod.ru/27557 https://govnokod.xyz/_27557
    #109: https://govnokod.ru/27581 https://govnokod.xyz/_27581
    #110: https://govnokod.ru/27610 https://govnokod.xyz/_27610
    #111: https://govnokod.ru/27644 https://govnokod.xyz/_27644
    #112: https://govnokod.ru/27648 https://govnokod.xyz/_27648
    #113: https://govnokod.ru/27652 https://govnokod.xyz/_27652
    #114: https://govnokod.ru/27659 https://govnokod.xyz/_27659
    #115: https://govnokod.ru/27665 https://govnokod.xyz/_27665
    #116: https://govnokod.ru/27671 https://govnokod.xyz/_27671
    #117: https://govnokod.ru/27675 https://govnokod.xyz/_27675
    #118: https://govnokod.ru/27685 https://govnokod.xyz/_27685
    #119: https://govnokod.ru/27701 https://govnokod.xyz/_27701
    #120: https://govnokod.ru/27703 https://govnokod.xyz/_27703
    #121: https://govnokod.ru/27710 https://govnokod.xyz/_27710
    #122: https://govnokod.ru/27728 https://govnokod.xyz/_27728
    #123: https://govnokod.ru/27729 https://govnokod.xyz/_27729
    #124: https://govnokod.ru/27730 https://govnokod.xyz/_27730
    #125: https://govnokod.ru/27732 https://govnokod.xyz/_27732
    #126: https://govnokod.ru/27733 https://govnokod.xyz/_27733
    #127: https://govnokod.ru/27737 https://govnokod.xyz/_27737
    #128: https://govnokod.ru/27742 https://govnokod.xyz/_27742
    #129: https://govnokod.ru/27747 https://govnokod.xyz/_27747
    #130: https://govnokod.ru/27755 https://govnokod.xyz/_27755
    #131: https://govnokod.ru/27766 https://govnokod.xyz/_27766
    #132: https://govnokod.ru/27790 https://govnokod.xyz/_27790
    #133: https://govnokod.ru/27828 https://govnokod.xyz/_27828
    #134: https://govnokod.ru/27834 https://govnokod.xyz/_27834

    nepeKamHblu_nemyx, 25 Ноября 2021

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