1. Python / Говнокод #26641

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def f(m, n):
         if m == 0:
              return n + 1
         elif n == 0:
              return f(m - 1, 1)
         else:
              return f(m - 1, f(m, n - 1))

    vvudu, 08 Мая 2020

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

    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
    #define DECLARE_TYPE(Name, Type) \
        using TYPE = Type; \
        ObjectInterface s_##Type##ObjectInterface (Name, []()->ObjectType* { return new Type;
    
    #define DECLARE_METHODS \
            }, {
    
    #define DECLARE_PROPERTIES \
            }, {
    
    #define DECLARE_METHOD(Method) \
            { #Method, reinterpret_cast <_ObjectMethodProc> (&TYPE::Method) },
    
    #define DECLARE_CUSTOM_NAME_METHOD(Name, Method) \
            { Name, reinterpret_cast <_ObjectMethodProc> (&TYPE::Method) },
    
    #define DECLARE_METHOD_MAPPER(_1,_2,DECLARE_METHOD,...) DECLARE_METHOD
    #define METHOD(...) DECLARE_METHOD_MAPPER(__VA_ARGS__, DECLARE_CUSTOM_NAME_METHOD, DECLARE_METHOD)(__VA_ARGS__)
    
    #define PROPERTY(Name, Get, Set) \
            { Name, { reinterpret_cast <_PropertyGettingProc> (&TYPE::Get), reinterpret_cast <_PropertySettingProc> (&TYPE::Set) } },
    
    #define END_DECLARE_TYPE \
            });

    ???

    codemonkey, 07 Мая 2020

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

    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
    #include <iostream>
    #include <chrono> 
    #include <thread>
    #include <fstream>
    #include <string>
    
    using namespace std;
    float Cheking = 0;
    
    void read_file()
    {
        string line;
        ifstream file("text.bin");
        if (file)
        {
            while (getline(file, line))
            {
                file >> Cheking;
            }
            file.close();
        }
    }
    void write_file()
    {
        ofstream myfile("text.bin");
        if (myfile.is_open())
        {
            myfile << "\n";
            myfile << Cheking << "\n";
            myfile.close();
        }
        else 
        {
            cout << "Unable to open file";
            myfile.close();
        }
    }
    
    int main()
    {
        using namespace chrono;
        using namespace this_thread;
        setlocale(LC_ALL, "ukr");
        read_file();
        cout << "Число: " << Cheking << "\t\t";
        cout << endl;
        if (Cheking == 0)
        {
            cin >> Cheking;
        }   
        write_file();
        sleep_for(milliseconds(1000));
        return 0;
    }

    Простой гавнокод для храненния переменных в файле.

    vova09082000, 06 Мая 2020

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

    +1

    1. 1
    https://github.com/oskusalerma/trelby/issues/85

    Сорян за пост-ссылку, но я тут валяюсь под столом просто.

    Есть тулза для написания сценариев (для чего только нет тулзы, правда?). Она опенсурсная и при этом выглядит не как говно. Но, когда начинаешь её щупать, ВНЕЗАПНО оказывается, что буквы кириллицы в ней тупо не набираются. Лезешь в FAQ, там лежит ссылка на issue из поста. А уже там просто сказка!

    Короч, автор примерно в 2007 году сходил почитал спеку пдф, обнаружил, что "PDF spec is oriented towards Latin-1" и решил, что это даёт ему моральное право забить болт на Unicode, а заодно utf-8 и унтерменш, которые не осилили самый тривиальный сабсет латиницы.

    В 2012-ом после, судя по всему, многочисленных недоумённых вопросов автор снова появился на горизонте с тикетом на гитхабе и объяснениями в духе "Unicode нет и не будет, потому что не для тебя моя черешня цвела". Цитата для понимания майндсета чувака: "That's how it was 5 years ago anyway when I last looked at it; maybe the spec has improved since then?"

    В общем, выглядело так, будто дядя устал и решил, что пора бы всю эту хуйню переложить на чужие хрупкие плечи, у нас тут опенсурс тем более и все дела.

    Но, когда в 2015-ом году появился некий анон с предложением все починить и даже какими-то наработками, автор ему сказал, что иди сука гоняй тесты (видимо, руками, потому что CI настроить он тоже не смог) на всех платформах, а то, вишь, "the old "I'll do the fun bits and let others do the boring bits" strategy. Good luck with that."

    Короч чуваки ещё немного поспорили с этим аутистом, после чего съебались в туман, а тулза так кириллицу и не поддерживает.

    Смешно и грустно.

    Desktop, 05 Мая 2020

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template<typename T>
    concept Addable = requires (T x) { x + x; }; // requires-expression
     
    template<typename T> requires Addable<T> // requires-clause, not requires-expression
    T add(T a, T b) { return a + b; }

    все решено.. перехожу писать код на "конецепты"

    ASD_77, 05 Мая 2020

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

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private IDictionary<string, Value> valueIndex;
    ...
    
    var result = this.valueIndex
              .Where(v => v.Key == prefix + hashCode.ToString())
             .Select(v => new
             {
                    path = v.Value.Path,
                    field = v.Value.Field
              })
              .FirstOrDefault();

    Трушный способ достать значение из словаря.
    В словаре 10000 записей, за каждой полезут хотя бы раз

    adoconnection, 05 Мая 2020

    Комментарии (1)
  7. Куча / Говнокод #26635

    0

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

    #11: (vanished) https://govnokod.xyz/_25436
    #12: (vanished) https://govnokod.xyz/_25471
    #13: (vanished) https://govnokod.xyz/_25590
    #14: https://govnokod.ru/25684 https://govnokod.xyz/_25684
    #15: https://govnokod.ru/25694 https://govnokod.xyz/_25694
    #16: https://govnokod.ru/25725 https://govnokod.xyz/_25725
    #17: https://govnokod.ru/25731 https://govnokod.xyz/_25731
    #18: https://govnokod.ru/25762 https://govnokod.xyz/_25762
    #19: https://govnokod.ru/25767 https://govnokod.xyz/_25767
    #20: https://govnokod.ru/25776 https://govnokod.xyz/_25776
    #21: https://govnokod.ru/25798 https://govnokod.xyz/_25798
    #22: https://govnokod.ru/25811 https://govnokod.xyz/_25811
    #23: https://govnokod.ru/25863 https://govnokod.xyz/_25863
    #24: https://govnokod.ru/25941 https://govnokod.xyz/_25941
    #25: https://govnokod.ru/26026 https://govnokod.xyz/_26026
    #26: https://govnokod.ru/26050 https://govnokod.xyz/_26050
    #27: https://govnokod.ru/26340 https://govnokod.xyz/_26340
    #28: https://govnokod.ru/26372 https://govnokod.xyz/_26372
    #29: https://govnokod.ru/26385 https://govnokod.xyz/_26385
    #30: https://govnokod.ru/26413 https://govnokod.xyz/_26413
    #31: https://govnokod.ru/26423 https://govnokod.xyz/_26423
    #32: https://govnokod.ru/26440 https://govnokod.xyz/_26440
    #33: https://govnokod.ru/26449 https://govnokod.xyz/_26449
    #34: https://govnokod.ru/26456 https://govnokod.xyz/_26456
    #35: https://govnokod.ru/26463 https://govnokod.xyz/_26463
    #36: https://govnokod.ru/26508 https://govnokod.xyz/_26508
    #37: https://govnokod.ru/26524 https://govnokod.xyz/_26524
    #38: https://govnokod.ru/26539 https://govnokod.xyz/_26539
    #39: https://govnokod.ru/26556 https://govnokod.xyz/_26556
    #40: https://govnokod.ru/26568 https://govnokod.xyz/_26568
    #41: https://govnokod.ru/26589 https://govnokod.xyz/_26589
    #42: https://govnokod.ru/26600 https://govnokod.xyz/_26600
    #43: https://govnokod.ru/26604 https://govnokod.xyz/_26604
    #44: https://govnokod.ru/26627 https://govnokod.xyz/_26627

    gost, 05 Мая 2020

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

    +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
    class Person {
        protected name: string;
        constructor(name: string) { this.name = name; }
    }
    
    class Employee extends Person {
        private department: string;
    
        constructor(name: string, department: string) {
            super(name);
            this.department = department;
        }
    
        public get ElevatorPitch() {
            return `Hello, my name is ${this.name} and I work in ${this.department}.`;
        }
    }
    
    const howard = new Employee("Howard", "Sales");
    console.log(howard.ElevatorPitch);
    
    //===============================================>>>>>>>>>>>>>>>>>>
    
    #ifndef TEST_H
    #define TEST_H
    #include "core.h"
    
    using namespace js;
    
    class Person;
    class Employee;
    
    class Person : public object, public std::enable_shared_from_this<Person> {
    public:
        string name;
    
        Person(string name);
    };
    
    class Employee : public Person, public std::enable_shared_from_this<Employee> {
    public:
        string department;
    
        Employee(string name, string department);
        virtual any get_ElevatorPitch();
        Employee(string name);
    };
    
    extern std::shared_ptr<Employee> howard;
    #endif
    
    #include "test.h"
    
    using namespace js;
    
    Person::Person(string name) {
        this->name = name;
    }
    
    Employee::Employee(string name, string department) : Person(name) {
        this->department = department;
    }
    
    any Employee::get_ElevatorPitch()
    {
        return "Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S;
    }
    
    Employee::Employee(string name) : Person(name) {
    }
    
    std::shared_ptr<Employee> howard = std::make_shared<Employee>("Howard"_S, "Sales"_S);
    
    void Main(void)
    {
        console->log(howard->get_ElevatorPitch());
    }
    
    int main(int argc, char** argv)
    {
        Main();
        return 0;
    }

    Было делать нехрен в жизни и решил наговнокодить транспайлер с TypeScript в С++

    https://github.com/ASDAlexander77/TypeScript2Cxx

    ASD_77, 05 Мая 2020

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Срочно нужна помощь с засылкой на хабр!
    
    Желательно перед этим почитать от того, что не пропустит анальная модерация и сектанты.
    
    Предложения так же жду в комментах. По тексту и в целом.

    https://tsar1997.blogspot.com/2020/05/blog-post_54.html

    Исходник пасты - просьба кидать патчи. Позже зашлю на хабр.

    https://pastebin.com/raw/haeHPx89

    3.14159265, 03 Мая 2020

    Комментарии (62)
  10. Си / Говнокод #26631

    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
    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
    dev_t name_to_dev_t(const char *name)
    {
    	char s[32];
    	char *p;
    	dev_t res = 0;
    	int part;
    
    #ifdef CONFIG_BLOCK
    	if (strncmp(name, "PARTUUID=", 9) == 0) {
    		name += 9;
    		res = devt_from_partuuid(name);
    		if (!res)
    			goto fail;
    		goto done;
    	} else if (strncmp(name, "PARTLABEL=", 10) == 0) {
    		struct device *dev;
    
    		dev = class_find_device(&block_class, NULL, name + 10,
    					&match_dev_by_label);
    		if (!dev)
    			goto fail;
    
    		res = dev->devt;
    		put_device(dev);
    		goto done;
    	}
    #endif
    
    	if (strncmp(name, "/dev/", 5) != 0) {
    		unsigned maj, min, offset;
    		char dummy;
    
    		if ((sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2) ||
    		    (sscanf(name, "%u:%u:%u:%c", &maj, &min, &offset, &dummy) == 3)) {
    			res = MKDEV(maj, min);
    			if (maj != MAJOR(res) || min != MINOR(res))
    				goto fail;
    		} else {
    			res = new_decode_dev(simple_strtoul(name, &p, 16));
    			if (*p)
    				goto fail;
    		}
    		goto done;
    	}
    
    	name += 5;
    	res = Root_NFS;
    	if (strcmp(name, "nfs") == 0)
    		goto done;
    	res = Root_CIFS;
    	if (strcmp(name, "cifs") == 0)
    		goto done;
    	res = Root_RAM0;
    	if (strcmp(name, "ram") == 0)
    		goto done;
    
    	if (strlen(name) > 31)
    		goto fail;
    	strcpy(s, name);
    	for (p = s; *p; p++)
    		if (*p == '/')
    			*p = '!';
    	res = blk_lookup_devt(s, 0);
    	if (res)
    		goto done;
    
    	/*
    	 * try non-existent, but valid partition, which may only exist
    	 * after revalidating the disk, like partitioned md devices
    	 */
    	while (p > s && isdigit(p[-1]))
    		p--;
    	if (p == s || !*p || *p == '0')
    		goto fail;
    
    	/* try disk name without <part number> */
    	part = simple_strtoul(p, NULL, 10);
    	*p = '\0';
    	res = blk_lookup_devt(s, part);
    	if (res)
    		goto done;
    
    	/* try disk name without p<part number> */
    	if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
    		goto fail;
    	p[-1] = '\0';
    	res = blk_lookup_devt(s, part);
    	if (res)
    		goto done;
    
    fail:
    	return 0;
    done:
    	return res;

    прыщи 32, 10

    MAKAKA, 02 Мая 2020

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