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

    Всего: 24

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

    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
    template<typename T>
    struct method_traits;
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...)> {
        using this_type = T;
        using ret_type = RetT;
    
        template<size_t ArgIdx>
        using arg_type = typename std::tuple_element<ArgIdx, std::tuple<Args...>>::type;
    
        static constexpr size_t args_count = sizeof...(Args);
        static constexpr bool is_const = false;
        static constexpr bool is_lvalue = false;
        static constexpr bool is_rvalue = false;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) const> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_const = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) &> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_lvalue = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) &&> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_rvalue = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) const &> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_const = true;
        static constexpr bool is_lvalue = true;
    };
    
    template<typename T, typename RetT, typename... Args>
    struct method_traits<RetT(T::*)(Args...) const &&> : public method_traits<RetT(T::*)(Args...)> {
        static constexpr bool is_const = true;
        static constexpr bool is_rvalue = true;
    };

    А вдруг в новом стандарте ещё модификаторов в тип завезут? Страшня стало...

    PolinaAksenova, 07 Мая 2021

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // Since C++20
    
    struct A {
      int&& r;
    };
    A a1{7}; // OK, lifetime is extended
    A a2(7); // well-formed, but dangling reference

    Удачной отладки!

    PolinaAksenova, 06 Мая 2021

    Комментарии (57)
  4. Python / Говнокод #27387

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    def main():
        pipe(int(input('Введите неотрицательное целое число: ')),   
             lambda n: (n, reduce(lambda x, y: x * y, range(1, n + 1))),   
             lambda tup: print(f'Факториал числа {tup[0]} равняется {tup[1]}'))

    Из https://habr.com/ru/post/555370/ (Функциональное ядро на Python).

    PolinaAksenova, 01 Мая 2021

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

    +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
    var proto = $new(null);
    proto.foo = function() { 
      $print(this.msg) 
    }
    
    var o = $new(null);
    o.msg = "hello";
    $objsetproto(o,proto);
    o.foo(); // print "hello"
    
    $objsetproto(o,null); // remove proto
    o.foo(); // exception

    Давайте писать ня Neko!
    https://nekovm.org

    PolinaAksenova, 29 Апреля 2021

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

    +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
    int main()
    {
        using Human = NamedTuple<
            Field<"name", std::string>,
            Field<"age", int>
        >;
        using User = NamedTuple<
            Field<"login", std::string>,
            Field<"password", std::string>
        >;
    
        Human vasya{ "Vasya", 16 };
        vasya.get<"age">() = 17;
    
        User user{ "xXxBaCRHxXx", "p4ssword" };
    
        auto vasyaMerged = mergeNamedTuples(vasya, user);
    
        std::cout << vasyaMerged.get<"name">() << " is " << vasyaMerged.get<"age">() << " years old!" << std::endl;
        std::cout << "Login is " << vasyaMerged.get<"login">() << " and password is " << vasyaMerged.get<"password">() << std::endl;
    }

    Как похорошел C++ при C++20!

    https://wandbox.org/permlink/llpXuy7IOSugtxHo

    PolinaAksenova, 18 Апреля 2021

    Комментарии (72)
  7. Java / Говнокод #27360

    +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
    package org.trishinfotech.builder;
    
    public class Car {
    
        private String chassis;
        private String body;
        private String paint;
        private String interior;
        
        public Car() {
            super();
        }
    
        public Car(String chassis, String body, String paint, String interior) {
            this();
            this.chassis = chassis;
            this.body = body;
            this.paint = paint;
            this.interior = interior;
        }
    
        public String getChassis() {
            return chassis;
        }
    
    	public void setChassis(String chassis) {
            this.chassis = chassis;
    
        }
    
        public String getBody() {
            return body;
        }
    
        public void setBody(String body) {
            this.body = body;
        }
    
        public String getPaint() {
            return paint;
        }
    
        public void setPaint(String paint) {
            this.paint = paint;
        }
    		public String getInterior() {
            return interior;
        }
    
        public void setInterior(String interior) {
            this.interior = interior;
        }
    
        public boolean doQualityCheck() {
            return (chassis != null && !chassis.trim().isEmpty()) && (body != null && !body.trim().isEmpty())
                    && (paint != null && !paint.trim().isEmpty()) && (interior != null && !interior.trim().isEmpty());
        }
    
        @Override
        public String toString() {
            // StringBuilder class also uses Builder Design Pattern with implementation of java.lang.Appendable interface
            StringBuilder builder = new StringBuilder();
            builder.append("Car [chassis=").append(chassis).append(", body=").append(body).append(", paint=").append(paint)
            return builder.toString();
        }
    
    }

    https://habr.com/ru/company/otus/blog/552412/
    Паттерн проектирования Builder (Строитель) в Java

    PolinaAksenova, 15 Апреля 2021

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

    +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
    std::cout << "Creating ptr1!" << std::endl;
    auto ptr1 = make_nft<Cow>();
    std::cout << "ptr1(" << &ptr1 << "): " << ptr1.get() << std::endl;
    ptr1->MakeSound();
    
    std::cout << "Creating ptr2!" << std::endl;
    nft_ptr<Animal> ptr2;
    std::cout << "ptr2(" << &ptr2 << "): " << ptr2.get() << std::endl;
    std::cout << "Moving: ptr2 = std::move(ptr1)" << std::endl;
    ptr2 = std::move(ptr1);
    std::cout << "Moved: ptr1 = " << ptr1.get() << " ptr2 = " << ptr2.get()
              << std::endl;

    https://github.com/zhuowei/nft_ptr

    "C++ std::unique_ptr that represents each object as an NFT on the Ethereum blockchain."

    PolinaAksenova, 13 Апреля 2021

    Комментарии (23)
  9. Python / Говнокод #27339

    +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
    def ForQueryInAddr(query, addr):
    	global listed, primalsource
    	print("Searcing in: "+addr)
    	html = requests.get(addr,proxies=proxies).text
    	if (query.lower() in html.lower()):
    		print("==============================================")
    		print("Query found in: "+addr)
    		print("==============================================")
    	if ("<html>" in html or "<head>" in html):
    		data = PyQuery(html)
    		links = data('a')
    		for link in links:
    			ahref = link.attrib['href']
    			#print("Found: "+ahref)
    			if (ahref not in listed):
    				if (ahref[0].lower() == "h"):
    					if (primalsource in ahref):
    						if (ahref[-3:].lower() not in filetypes and ahref[-4:].lower() not in filetypes and ahref[-5:].lower() not in filetypes):
    							listed.append(ahref)
    							ForQueryInAddr(query, ahref)

    https://github.com/Dev1lroot/OnionSearch/blob/master/main.py

    PolinaAksenova, 06 Апреля 2021

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

    +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
    using System.Device.Gpio;
    using System;
    using System.Threading;
    
    namespace Blinky
    {
    	public class Program
        {
            private static GpioController s_GpioController;
            public static void Main()
            {
                s_GpioController = new GpioController();
    
                // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
                GpioPin led = s_GpioController.OpenPin(4,PinMode.Output);
                led.Write(PinValue.Low);
    
                while (true)
                {
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(525);
                }
            }        
        }
    }

    https://habr.com/ru/post/549012/: «.NET nanoFramework — платформа для разработки приложений на C# для микроконтроллеров».

    Ну все, последний оплот сишки пал, можно ее закапывать.

    PolinaAksenova, 25 Марта 2021

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

    +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
    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
    #include <array>
    #include <iostream>
    #include <string_view>
    #include <type_traits>
    
    std::string_view getMaxMargin();
    
    template<int bit_num>
    struct flag {
        friend constexpr int adl_flag(flag<bit_num>);
    };
    
    template<int bit_num>
    struct writer {
        friend constexpr int adl_flag(flag<bit_num>)
        {
            return bit_num;
        }
    
        static constexpr int value = bit_num;
    };
    
    template<int bit_num, int = adl_flag(flag<bit_num>{})>
    constexpr bool is_flag_set(int, flag<bit_num>)
    {
        return bit_num >= 0;
    }
    
    template<int bit_num>
    constexpr bool is_flag_set(float, flag<bit_num>)
    {
        return false;
    }
    
    template<size_t number, size_t bit_num>
    constexpr bool get_bit()
    {
        return (number & (1 << bit_num)) != 0;
    }
    
    #define flags_to_size()                     \
         ((is_flag_set<0>(0, flag<0>{}) << 0)   \
        | (is_flag_set<1>(0, flag<1>{}) << 1)   \
        | (is_flag_set<2>(0, flag<2>{}) << 2)   \
        | (is_flag_set<3>(0, flag<3>{}) << 3))
    
    template<bool test, typename T_true, typename T_false>
    struct meta_if {
        using type = T_true;
    };
    
    template<typename T_true, typename T_false>
    struct meta_if<false, T_true, T_false> {
        using type = T_false;
    };
    
    template<bool test, typename T_true, typename T_false>
    using meta_if_t = typename meta_if<test, T_true, T_false>::type;
    
    template<
        size_t desired_size,
        int = (0 +
               sizeof(meta_if_t<get_bit<desired_size, 0>(), writer<0>, int>) +
               sizeof(meta_if_t<get_bit<desired_size, 1>(), writer<1>, int>) +
               sizeof(meta_if_t<get_bit<desired_size, 2>(), writer<2>, int>) +
               sizeof(meta_if_t<get_bit<desired_size, 3>(), writer<3>, int>)
        )
    >
    constexpr size_t f()
    {
        return desired_size;
    }
    
    int main()
    {
        constexpr size_t a = f<1>();
        constexpr size_t b = f<6>();
        std::cout << "Max margin size: " << getMaxMargin().size() << std::endl;
    }
    
    constexpr size_t MARGIN_SIZE = flags_to_size();
    constexpr char MARGIN_CHAR = 'x';
    
    template<typename T, T... Args>
    constexpr auto getMarginStorageImpl(std::integer_sequence<T, Args...>)
    {
        return std::array<char, sizeof...(Args)>{(static_cast<void>(Args), MARGIN_CHAR)...};
    }
    constexpr auto getMarginStorage()
    {
        return getMarginStorageImpl(std::make_integer_sequence<int, MARGIN_SIZE>());
    }
    constexpr static auto marginStorage = getMarginStorage();;
    
    std::string_view getMaxMargin()
    {
        return std::string_view(marginStorage.data(), MARGIN_SIZE);
    }

    "Интересно, можно ли насфиначить такой шаблон, чтобы в пределах TU сгенерированные литералы были слайсами одного статического массива, длина которого выводилась бы автоматически."

    PolinaAksenova, 25 Марта 2021

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