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

    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
    if "=" in cell_content:
                command["relation"] = "eq"
            elif "≠" in cell_content or "!=" in cell_content:
                command["relation"] = "ne"
            elif "<" in cell_content or "<" in cell_content:
                command["relation"] = "lt"
            elif "≤" in cell_content:
                command["relation"] = "le"
            elif ">" in cell_content or ">" in cell_content:
                command["relation"] = "gt"
            elif "≥" in cell_content:
                command["relation"] = "ge"

    Не, ну а как еще-то

    youjin1985, 14 Марта 2024

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for(int i = 0; i < p.mDict.TblSize; i++)
    		for(auto *node = p.mDict.table[i]; node; node = node->n)
    			for(int j = 0; j < node->v.TblSize; j++)
    				for(int k = 0; k < node->v.table[j].count; k++ )
    					if(node->v.table[j][k].v)
    						Log("Section %s: unused config key %s = %s\n", node->k, node->v.table[j][k].k, node->v.table[j][k].v);

    mittorn, 14 Марта 2024

    Комментарии (2)
  3. Python / Говнокод #28927

    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
    def razmer(arr):
     b = len (arr) - 1
     return (array_prov(arr,b))
    
    def array_prov (arr,b):
     if b == 0:
         return arr[b]
     else:
         return (arr[b]+array_prov (arr, b-1))
    
    a = [10,12,14,15,18]
    print (razmer (a))

    1004w, 12 Марта 2024

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    def print_message(num_of_times) {
        for i in range(num_of_times) {
            print("Bython is awesome!");
        }
    }
    
    if __name__ == "__main__" {
        print_message(10);
    }

    Python with braces. Because Python is awesome, but whitespace is awful.

    https://pypi.org/project/Bython/

    nemyx, 11 Марта 2024

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

    0

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

    #166: https://govnokod.ru/28574 https://govnokod.xyz/_28574
    #167: https://govnokod.ru/28588 https://govnokod.xyz/_28588
    #168: https://govnokod.ru/28607 https://govnokod.xyz/_28607
    #169: https://govnokod.ru/28628 https://govnokod.xyz/_28628
    #170: https://govnokod.ru/28653 https://govnokod.xyz/_28653
    #171: (vanished) https://govnokod.xyz/_28665
    #172: https://govnokod.ru/28675 https://govnokod.xyz/_28675
    #173: https://govnokod.ru/28681 https://govnokod.xyz/_28681
    #174: https://govnokod.ru/28689 https://govnokod.xyz/_28689
    #175: https://govnokod.ru/28696 https://govnokod.xyz/_28696
    #176: https://govnokod.ru/28703 https://govnokod.xyz/_28703
    #177: https://govnokod.ru/28709 https://govnokod.xyz/_28709
    #178: https://govnokod.ru/28716 https://govnokod.xyz/_28716
    #179: https://govnokod.ru/28726 https://govnokod.xyz/_28726
    #180: https://govnokod.ru/28734 https://govnokod.xyz/_28734
    #181: https://govnokod.ru/28739 https://govnokod.xyz/_28739
    #182: https://govnokod.ru/28749 https://govnokod.xyz/_28749
    #183: https://govnokod.ru/28777 https://govnokod.xyz/_28777
    #184: https://govnokod.ru/28790 https://govnokod.xyz/_28790
    #185: https://govnokod.ru/28794 https://govnokod.xyz/_28794
    #186: https://govnokod.ru/28815 https://govnokod.xyz/_28815
    #187: https://govnokod.ru/28833 https://govnokod.xyz/_28833
    #188: https://govnokod.ru/28837 https://govnokod.xyz/_28837
    #189: https://govnokod.ru/28840 https://govnokod.xyz/_28840
    #190: https://govnokod.ru/28875 https://govnokod.xyz/_28875
    #191: https://govnokod.ru/28878 https://govnokod.xyz/_28878
    #192: https://govnokod.ru/28886 https://govnokod.xyz/_28886
    #193: https://govnokod.ru/28911 https://govnokod.xyz/_28911
    #194: https://govnokod.ru/28914 https://govnokod.xyz/_28914
    #195: https://govnokod.ru/28917 https://govnokod.xyz/_28917

    nepeKamHblu_nemyx, 10 Марта 2024

    Комментарии (81)
  6. Куча / Говнокод #28924

    0

    1. 1
    Политота #34

    #4: (vanished) https://govnokod.xyz/_24822
    #5: https://govnokod.ru/24868 https://govnokod.xyz/_24868
    #6: (vanished) https://govnokod.xyz/_26648
    #7: https://govnokod.ru/26673 https://govnokod.xyz/_26673
    #8: https://govnokod.ru/27052 https://govnokod.xyz/_27052
    #9: (vanished) https://govnokod.xyz/_27852
    #10: https://govnokod.ru/28060 https://govnokod.xyz/_28060
    #11: https://govnokod.ru/28091 https://govnokod.xyz/_28091
    #12: https://govnokod.ru/28103 https://govnokod.xyz/_28103
    #13: https://govnokod.ru/28144 https://govnokod.xyz/_28144
    #14: https://govnokod.ru/28270 https://govnokod.xyz/_28270
    #15: https://govnokod.ru/28341 https://govnokod.xyz/_28341
    #16: https://govnokod.ru/28379 https://govnokod.xyz/_28379
    #17: https://govnokod.ru/28394 https://govnokod.xyz/_28394
    #18: https://govnokod.ru/28440 https://govnokod.xyz/_28440
    #19: https://govnokod.ru/28572 https://govnokod.xyz/_28572
    #20: https://govnokod.ru/28656 https://govnokod.xyz/_28656
    #21: (vanished) https://govnokod.xyz/_28666
    #22: https://govnokod.ru/28676 https://govnokod.xyz/_28676
    #23: https://govnokod.ru/28684 https://govnokod.xyz/_28684
    #24: https://govnokod.ru/28691 https://govnokod.xyz/_28691
    #25: https://govnokod.ru/28698 https://govnokod.xyz/_28698
    #26: https://govnokod.ru/28704 https://govnokod.xyz/_28704
    #27: https://govnokod.ru/28711 https://govnokod.xyz/_28711
    #28: https://govnokod.ru/28721 https://govnokod.xyz/_28721
    #29: https://govnokod.ru/28728 https://govnokod.xyz/_28728
    #30: (vanished) https://govnokod.xyz/_28747
    #31: https://govnokod.ru/28757 https://govnokod.xyz/_28757
    #32: https://govnokod.ru/28770 https://govnokod.xyz/_28770
    #33: https://govnokod.ru/28835 https://govnokod.xyz/_28835

    nepeKamHblu_nemyx, 05 Марта 2024

    Комментарии (172)
  7. Си / Говнокод #28923

    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
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    template <typename Key, typename Value, size_t TblPower = 2>
    struct HashMap {
    	struct Node
    	{
    		Key k;
    		Value v;
    		Node *n;
    
    		Node(const Key &key, const Value &value) :
    			k(key), v(value), n(NULL) {}
    
    		Node(const Key &key) :
    			k(key), v(), n(NULL) {}
    	};
    
    	constexpr static size_t TblSize = 1U << TblPower;
    	Node *table[TblSize] = {nullptr};
    
    	HashMap() {
    	}
    
    	~HashMap() {
    		for(size_t i = 0; i < TblSize; i++)
    		{
    			Node *entry = table[i];
    			while(entry)
    			{
    				Node *prev = entry;
    				entry = entry->n;
    				delete prev;
    			}
    			table[i] = NULL;
    		}
    	}
    
    	size_t HashFunc(const Key &key) const
    	{
    		/// TODO: string hash?
    		// handle hash: handle pointers usually aligned
    		return (((size_t) key) >> 8)  & (TblSize - 1);
    	}
    
    	// just in case: check existance or constant access
    	forceinline Value *GetPtr(const Key &key) const
    	{
    		size_t hashValue = HashFunc(key);
    		Node *entry = table[hashValue];
    		while(likely(entry))
    		{
    			if(entry->k == key)
    				return &entry->v;
    			entry = entry->n;
    		}
    		return nullptr;
    	}
    
    	Value &operator [] (const Key &key)
    	{
    		return GetOrAllocate(key);
    	}
    
    #define HASHFIND(key) \
    		size_t hashValue = HashFunc(key); \
    		Node *prev = NULL; \
    		Node *entry = table[hashValue]; \
    	\
    		while(entry && entry->k != key) \
    		{ \
    			prev = entry; \
    			entry = entry->n; \
    		}
    
    	Node * noinline _Allocate(Key key, size_t hashValue, Node *prev, Node *entry)
    	{
    		entry = new Node(key);
    		if(unlikely(!entry))
    		{
    			static Node error(key);
    			return &error;
    		}
    
    		if(prev == NULL)
    			table[hashValue] = entry;
    		else
    			prev->n = entry;
    		return entry;
    	}
    
    	Value& GetOrAllocate(const Key &key)
    	{
    		HASHFIND(key);
    
    		if(unlikely(!entry))
    			entry = _Allocate(key,hashValue, prev, entry);
    
    		return entry->v;
    	}
    // тут был ещё один метод, но в говнокод не влез
    }

    когда СГОРЕЛО от STL

    mittorn, 04 Марта 2024

    Комментарии (0)
  8. Си / Говнокод #28922

    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
    struct HashArrayMap {
    
    	struct Node
    	{
    		Key k;
    		Value v;
    
    		Node(const Key &key, const Value &value) :
    			k(key), v(value){}
    		Node(const Key &key) :
    			k(key), v(){}
    	};
    
    	constexpr static size_t TblSize = 1U << TblPower;
    	GrowArray<Node> table[TblSize];
    
    	HashArrayMap() {
    	}
    
    	~HashArrayMap() {
    	}
    
    	size_t HashFunc(const Key &key) const
    	{
    		/// TODO: string hash?
    		// handle hash: handle pointers usually aligned
    		return (((size_t) key) >> 8)  & (TblSize - 1);
    	}
    
    	// just in case: check existance or constant access
    	Value *GetPtr(const Key &key) const
    	{
    		size_t hashValue = HashFunc(key);
    		const GrowArray<Node> &entry = table[hashValue];
    		for(int i = 0; i < entry.count; i++)
    		{
    			if(entry[i].k == key)
    				return &entry[i].v;
    		}
    		return nullptr;
    	}
    
    	Value &operator [] (const Key &key)
    	{
    		return GetOrAllocate(key);
    	}
    
    #define HASHFIND(key) \
    	GrowArray<Node> &entry = table[HashFunc(key)]; \
    	int i; \
    	for(i = 0; i < entry.count; i++) \
    		if( entry[i].k == key ) \
    			break;
    
    	Value& GetOrAllocate(const Key &key)
    	{
    		HASHFIND(key);
    		if(i == entry.count )
    			entry.Add(Node(key));
    
    		return entry[i].v;
    	}
    
    	bool Remove(const Key &key)
    	{
    		HASHFIND(key);
    		if(i != entry.count)
    		{
    			entry.RemoveAt(i);
    			return true;
    		}
    		return false;
    	}
    #undef HASHFIND
    };

    когда СГОРЕЛО от STL

    mittorn, 04 Марта 2024

    Комментарии (0)
  9. Си / Говнокод #28921

    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
    template<class T>
    struct GrowArray
    {
    	T *mem = nullptr;
    	size_t count = 0;
    	size_t alloc = 0;
    
    	GrowArray(size_t init = 0)
    	{
    		if(init)
    			Grow(init);
    	}
    	~GrowArray()
    	{
    		if(mem)
    			free(mem);
    		mem = nullptr;
    		count = 0;
    		alloc = 0;
    	}
    
    	// non-copyable
    	GrowArray(const GrowArray &) = delete;
    	GrowArray &operator = (const GrowArray &) = delete;
    
    	void noinline Grow(size_t size)
    	{
    		if(!size)
    			size = 32;
    		T *newMem = (T*)(mem? realloc(mem, sizeof(T) * size): malloc(sizeof(T)*size));
    
    		if(!newMem)
    			return;
    
    		alloc = size;
    		mem = newMem;
    	}
    
    	// TODO: insert/append
    	bool Add(const T& newVal)
    	{
    		size_t newIdx = count + 1;
    		if(unlikely(newIdx > alloc))
    			Grow(alloc * 2);
    		if(unlikely(newIdx > alloc))
    			return false;
    		mem[count] = newVal;
    		count = newIdx;
    		return true;
    	}
    
    	// TODO: test
    	bool RemoveAt(size_t idx)
    	{
    		if(idx < count)
    			memmove(&mem[idx], &mem[idx+1], sizeof(T) * (count - idx - 1));
    		if(idx <= count)
    		{
    			count--;
    			return true;
    		}
    		return false;
    	}
    	T& operator[](size_t i) const
    	{
    		return mem[i];
    	}
    };

    mittorn, 04 Марта 2024

    Комментарии (0)
  10. JavaScript / Говнокод #28920

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    export type ReplaceNullToUndefined<T> = T extends (infer R)[]
    	? ReplaceNullToUndefined<R>[]
    	: T extends object
    		? {
    				[K in keyof T]: T[K] extends object
    					? ReplaceNullToUndefined<T[K]>
    					: null extends T[K]
    						? Exclude<T[K], null> | undefined
    						: T[K];
    			}
    		: T;

    Заменяет все `null` на `undefined`

    Maligosus, 04 Марта 2024

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