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

    Всего: 33

  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. Си / Говнокод #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)
  4. Си / Говнокод #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)
  5. Си / Говнокод #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)
  6. C++ / Говнокод #28326

    +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
    99. 99
    #include <stddef.h>
    #include <stdio.h>
    #include <utility>
    #define PLACEHOLDER char x[0];
    
    #define FORCEINLINE 
    template <typename T, typename... Ts> struct MyTuple : MyTuple<Ts...>
    {
    	FORCEINLINE constexpr MyTuple(T&& t, Ts&&... ts)
    		: value(std::move(t))
    		, MyTuple<Ts...> (std::forward<Ts>(ts)...){}
    	FORCEINLINE explicit MyTuple(const MyTuple<T,Ts...> &other) = default;
    	FORCEINLINE MyTuple(MyTuple<T,Ts...> &&other)
    		: MyTuple<Ts...>(std::forward<MyTuple<Ts...>>(other)),
    		value(std::move(other.value)){}
    
    	FORCEINLINE constexpr int size() const { return 1 + MyTuple<Ts...>::size(); }
    	constexpr static int sz = 1 + MyTuple<Ts...>::sz;
    	FORCEINLINE MyTuple<Ts...> &next(){return *static_cast<MyTuple<Ts...>*>(this);}
    	using tnext = MyTuple<Ts...>;
    	T value;
    	FORCEINLINE ~MyTuple() {}
    	constexpr static bool isitem = false;
    };
    struct MyTupleEmpty
    {
    	PLACEHOLDER
    	FORCEINLINE constexpr int size() const { return 0; }
    	static constexpr int sz = 0;
    	~MyTupleEmpty() {}
    	constexpr static bool isitem = false;
    };
    
    template <typename T> struct MyTuple<T> {
    	FORCEINLINE MyTuple(T&& t) : value(std::move(t)){}
    	FORCEINLINE explicit MyTuple(const MyTuple<T> &other) = default;
    	FORCEINLINE MyTuple(MyTuple<T> &&other): value(std::move(other.value)){}
    
    	FORCEINLINE MyTupleEmpty &next() const{
    		static MyTupleEmpty empty;
    		return empty;
    	}
    	FORCEINLINE constexpr int size() const { return 1; }
    	constexpr static int sz = 1;
    	using tnext =MyTupleEmpty;
    	T value;
    	FORCEINLINE ~MyTuple() {}
    	constexpr static bool isitem = false;
    };
    template <class T>struct unwrap_refwrapper{using type = T;};
    template <class T>struct unwrap_refwrapper<std::reference_wrapper<T>>{using type = T&;};
     template <class T> using unwrap_decay_t = typename unwrap_refwrapper<typename std::decay<T>::type>::type;
    template<typename... Ts>
    static FORCEINLINE MyTuple<unwrap_decay_t<Ts>...> MakeTuple(Ts&&... args)
    {
    	return MyTuple<unwrap_decay_t<Ts>...>(std::forward<Ts>(args)...);
    }
    struct i3{
        auto setProp(auto x, i3 t = *(i3*)0)
        {
            typename decltype(x(*this))::tp c;
            return c;
        }
        using tp = i3;
    };
    
    
    #define s(x,y) setProp([](auto c){struct xxx: decltype(c)::tp{decltype(y) x = y;using tp = xxx;    decltype([] (auto xx, xxx &t = *(xxx*)0)\
        {\
            typename decltype(xx(t))::tp c;\
            return c;\
        }) setProp;auto BeginChildren(){return *this;}} d;return d;})
    
    #define c(...) BeginChildren(),MakeTuple(__VA_ARGS__)
    #define i(...) i3()
    
    
    
    
    void func2()
    {
        auto tp = MakeTuple(
        i(Window)
            .s(width,10)
            .s(height,20)
            .c(
                i(Item),
                i(Item2)
                    .s(property1,10.0f)
    
            )
        );
        printf("%d %d %f\n",tp.value.height,tp.value.width, tp.next().value.next().value.property1);
    }
    
    int main()
    {
        func2();
    }

    qml-like структура в compile time
    Стандартизаторы всё пытались запретить шаблоны в локальных классах, да не вышло - понаоставляли дыр в лямбдах и decltype.
    Если добавить -fpermissive, то gcc сожрёт даже с constexpr

    mittorn, 09 Августа 2022

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

    +1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include <stdio.h>
    #include <memory>
    #define Property(type,name) type name;auto &set_##name(type val){name = val; return *this;}
    #define Set(x,y) set_##x(y)
    
    //#define Create(type, ...) (*(new type(__VA_ARGS__)))
    
    template <typename T>
    static inline T& Create_(const char *name)
    {
        return *(new T(name));
    }
    #define Create(type, ...)  Create_<type>(__VA_ARGS__)
    
    template <typename T>
    static inline T CreateNoAlloc_(const char *name)
    {
        return T(name);
    }
    #define CreateNoAlloc(type, ...)  CreateNoAlloc_<type>(__VA_ARGS__)
    
    struct BaseItem
    {
        const char *Name;
        BaseItem(const char *n): Name(n) {}
        Property(int, Width);
        Property(int, Height);
    };
    #include <vector>
    struct Markup
    {
        std::vector<BaseItem*> Children;
        template <typename T>
        Markup &Add(T &item)
        {
            Children.push_back(&item);
            return *this;
        }
    };
    
    static inline Markup CreateMarkup(const char *n)
    {
        return Markup();
    }
    /*
    struct Markup2
    {
        std::vector<std::shared_ptr<BaseItem>> Children;
        template <typename T>
        Markup2 &Add(T item)
        {
            Children.push_back(std::shared_ptr(&item));
            return *this;
        }
    };
    */
    
    template<std::size_t I = 0, typename... Tp>
    inline typename std::enable_if<I == sizeof...(Tp), void>::type
      print(std::tuple<Tp...>& t)
      { }
    
    template<std::size_t I = 0, typename... Tp>
    inline typename std::enable_if<I < sizeof...(Tp), void>::type
      print(std::tuple<Tp...>& t)
      {
        printf("%s\n",std::get<I>(t).Name);
        print<I + 1, Tp...>(t);
      }
    
    #include <string.h>
    
    static BaseItem NOT_FOUND("NOT_FOUND");
    
    template<typename T, std::size_t I = 0, typename... Tp>
    inline typename std::enable_if<I == sizeof...(Tp), void>::type
      print1(std::tuple<Tp...>& t, const char *n)
      { }
    
    template<typename T, std::size_t I = 0, typename... Tp>
    inline typename std::enable_if<I < sizeof...(Tp), T&>::type
      print1(std::tuple<Tp...>& t, const char *n)
      {
        if( !strcmp(std::get<I>(t).Name, n))
        return std::get<I>(t);
        print1<T, I + 1, Tp...>(t,n);
        return NOT_FOUND;
      }
    
    
    #define CreateMarkup(...) std::make_tuple(__VA_ARGS__)
    #define AppendMarkup(src, ...) std::tuple_cat(src, std::make_tuple(__VA_ARGS__))
    #define MarkupItem(markup,type,name,action) namespace {type &i = print1<type>(markup,name).action; }
    
    auto markup1 = CreateMarkup(BaseItem("test").Set(Width,14), BaseItem("test2"));
    auto markup2 = AppendMarkup(markup1,BaseItem("test3").Set(Width,15));
    auto markup3 = markup1;
    MarkupItem(markup3,BaseItem,"test2",Set(Width,16));
    
    template <typename T>

    Т.к юзается препроцессор, запощу в C

    mittorn, 29 Сентября 2021

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

    +5

    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
    #include <unistd.h>
    #include <stdio.h>
    #include <limits.h>
    
    template<size_t Size> struct static_string {char data[Size];};
    template<size_t ... Indexes>struct index_sequence {};
    template<size_t Size, size_t ... Indexes>
    constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const static_string<Size>& str,index_sequence<Indexes ...>) {return {str.data[Indexes] ..., '\0'};}
    constexpr static_string<1> make_static_string() {return {'\0'};}
    template<size_t Size, size_t ... Indexes>
    struct make_index_sequence : make_index_sequence<Size - 1, Size - 1, Indexes ...> {};
    template<size_t Size>
    constexpr static_string<Size> make_static_string(const char (& str)[Size]) {return make_static_string(str, make_index_sequence<Size - 1>{});}
    template<size_t ... Indexes>
    struct make_index_sequence<0, Indexes ...> : index_sequence<Indexes ...> {};
    template<size_t Size, size_t ... Indexes>
    constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const char (& str)[Size],index_sequence<Indexes ...>) {return {str[Indexes] ..., '\0'};}
    template<size_t Size>
    constexpr size_t static_string_find(const static_string<Size>& str, char ch, size_t from, size_t nth) {return Size < 2 || from >= Size - 1 ? UINT_MAX :str.data[from] != ch ? static_string_find(str, ch, from + 1, nth) :nth > 0 ? static_string_find(str, ch, from + 1, nth - 1) : from;}
    template<size_t Size>
    constexpr size_t static_string_find_0(const static_string<Size>& str, char ch, size_t from, size_t nth) {return Size < 2 || from >= Size - 1 ? 0 : str.data[from] != ch ? static_string_find_0(str, ch, from + 1, nth) :nth > 0 ? static_string_find(str, ch, from + 1, nth - 1) : from;}
    template<size_t Size1, size_t ... Indexes1, size_t Size2, size_t ... Indexes2>
    constexpr static_string<Size1 + Size2 - 1> static_string_concat_2(const static_string<Size1>& str1, index_sequence<Indexes1 ...>,const static_string<Size2>& str2, index_sequence<Indexes2 ...>) {return {str1.data[Indexes1] ..., str2.data[Indexes2] ..., '\0'};}
    template<size_t Size1, size_t Size2>
    constexpr static_string<Size1 + Size2 - 1> static_string_concat_2(const static_string<Size1>& str1, const static_string<Size2>& str2) {return static_string_concat_2(str1, make_index_sequence<Size1 - 1>{},str2, make_index_sequence<Size2 - 1>{});}
    template<size_t Begin, size_t End, size_t ... Indexes>
    struct make_index_subsequence : make_index_subsequence<Begin, End - 1, End - 1, Indexes ...> {};
    template<size_t Pos, size_t ... Indexes>
    struct make_index_subsequence<Pos, Pos, Indexes ...> : index_sequence<Indexes ...> {};
    template<size_t Begin, size_t End, size_t Size>
    constexpr static_string<End - Begin + 1> static_string_substring(const static_string<Size>& str) {return make_static_string(str, make_index_subsequence<Begin, End>{});}
    template<size_t Begin, size_t Size>
    constexpr static_string<Size - Begin> static_string_suffix(const static_string<Size>& str) {return static_string_substring<Begin, Size - 1>(str);}
    #define remove_underscore(arg) ([] () __attribute__((always_inline)) {constexpr auto a = static_string_find(make_static_string(arg),'_',0,0) == UINT_MAX? make_static_string(arg):static_string_concat_2(static_string_concat_2(static_string_substring<0,static_string_find_0(make_static_string(arg),'_',0,0)>(make_static_string(arg)),static_string_suffix<static_string_find_0(make_static_string(arg),'_',0,0)+1>(make_static_string(arg))),make_static_string("\0"));return a;}().data)
    
    int main()
    {
        puts(remove_underscore("_testtest"));
        puts(remove_underscore("test_test"));
        puts(remove_underscore("testtest_"));
    }

    Убогий constexpr в c++11

    mittorn, 25 Июня 2021

    Комментарии (46)
  9. bash / Говнокод #25122

    −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
    names="com.termux io.twaik.lorie rubberbigpepper.Orientator"
    if test ! -e /realproc/cmdline
    then
    echo Mounting realproc
    mount -o remount,rw none /
    mkdir /realproc
    mount -t proc none /realproc
    fi
    
    tail -f /dev/null|am monitor| while read line
    do
    echo "$line"
    for n in $names
    do
    for p in `pidof $n`
    do
    if test -e /proc/$p/oom_adj
    then
    echo Masking pid $p
    mount -t tmpfs -o size=4k none /proc/$p/
    for f in /realproc/$p/*
    do ln -s $f /proc/$p
    done
    rm /proc/$p/oom_*
    fi
    echo Setting oom adj for $n $p, was $(cat /realproc/$p/oom_adj)
    echo -17 > /realproc/$p/oom_adj
    done
    done
    done

    достал oom killer.

    Где тут shell в языках?

    mittorn, 27 Ноября 2018

    Комментарии (1)
  10. bash / Говнокод #24281

    −2

    1. 1
    echo $(printf '1\xff0.0.0.0:0\0\\gamedir\\valve' |nc -u ms.xash.su 27010 -w 1 | od -j6 -t x1 -An -w6 |sed -s 's/\ /\ 0x/g'|while read line; do printf '%d.%d.%d.%d' $(echo $line|cut -d ' ' -f1-4) ; echo \ $(( $(printf %d $(echo $line|cut -d ' ' -f5))*256 + $(printf %d $(echo $line|cut -d ' ' -f6)) )); done| while read line1; do printf \\xff\\xff\\xff\\xffinfo\ 48|nc -w 1 -u $line1 |sed -e s/\\\\/\\\ /g -e "s/\xff\xff\xff\xffinfo/_br_$line1/g" & done;sleep 2s;echo)|sed -e s/_br_/\\n/g

    Работаем с бинарными протоколами однострочно

    mittorn, 17 Мая 2018

    Комментарии (12)
  11. Си / Говнокод #23192

    +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
    /* 
    ================== 
    CL_ScreenshotGetName
    ================== 
    */  
    void CL_ScreenshotGetName( int lastnum, char *filename )
    {
    	int	a, b, c, d;
    
    	if( lastnum < 0 || lastnum > 9999 )
    	{
    		// bound
    		Q_sprintf( filename, "scrshots/%s/!error.bmp", clgame.mapname );
    		return;
    	}
    
    	a = lastnum / 1000;
    	lastnum -= a * 1000;
    	b = lastnum / 100;
    	lastnum -= b * 100;
    	c = lastnum / 10;
    	lastnum -= c * 10;
    	d = lastnum;
    
    	Q_sprintf( filename, "scrshots/%s_shot%i%i%i%i.bmp", clgame.mapname, a, b, c, d );
    }

    один вопрос: НАХУЯ???

    mittorn, 18 Июля 2017

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