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

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // Отправная точка новых изысканий
    uint16_t Mask = 0x0000;
    uint8_t i = 0;
    for(i=0; i<255; i++)
    	Mask |= (1 << i);
    
    ResponseBuf = (VirtualMemory & (Mask << RequestedAddr)) >> RequestedAddr;

    Из кода firmware одного девайса.

    Sushev, 14 Июня 2015

    Комментарии (14)
  3. Java / Говнокод #18281

    +142

    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
    public int func_175687_A(BlockPos p_175687_1_)
        {
            int var2 = 0;
            EnumFacing[] var3 = EnumFacing.values();
            int var4 = var3.length;
    
            for (int var5 = 0; var5 < var4; ++var5)
            {
                EnumFacing var6 = var3[var5];
                int var7 = this.getRedstonePower(p_175687_1_.offset(var6), var6);
    
                if (var7 >= 15)
                {
                    return 15;
                }
    
                if (var7 > var2)
                {
                    var2 = var7;
                }
            }
    
            return var2;
        }

    Notch видимо не слышал про Math.Max

    GameLoper, 03 Июня 2015

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

    −123

    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
    def run(code):
        
        def func(operator):
            from functools import reduce
            
            add    = lambda a, b: float(a) + float(b)
            mul    = lambda a, b: float(a) * float(b)
            div    = lambda a, b: float(a) / float(b)
            deduct = lambda a, b: float(a) - float(b)
            
            d = {
                '+': lambda arr: reduce(add,    arr),
                '*': lambda arr: reduce(mul,    arr),
                '/': lambda arr: reduce(div,    arr),
                '-': lambda arr: reduce(deduct, arr)
            }
            
            return d[operator]
        
        def lex(token):
            if token in ('+', '-', '/', '*', '%'):
                return "operator"
            elif token == '(':
                return "lbracket"
            elif token == ')':
                return "rbracket"
            elif token[0].isalpha():
                return "name"
            elif token[0] == token[-1] and token[0] in ('"', "'"):
                return "string"
            else:
                try:
                    float(token)
                    return "number"
                except:
                    raise ValueError
                
        def getArgs(words):
            args = []
            arg = []
            i = 0
            for word in words[2:]:
                if word == '(':
                    i += 1
                    arg.append(word)
                elif word == ')':
                    i -= 1
                    arg.append(word)
                    if i == 0:
                        args.append(arg)
                        arg = []
                elif i == 0:
                    arg.append(word)
                    args.append(arg)
                    arg = []
                else:
                    arg.append(word)
            return args
        
        def expr(words):
            args = getArgs(words)
            args_ = []
            for arg in args:
                if len(arg) == 1:
                    args_.append(arg)
                else:
                    args_.append(expr(arg))
            
            if lex(words[1]) == "operator":
                return func(words[1])(list(map(lambda a: (type(a) in (list, tuple) and a[0]) or a, args_)))
    
        lines = code.split("\n")
        for line in lines:
            word = ''
            words = []
            chars = tuple(line)
            
            for i in tuple(line):
                
                if i in ('(', ')'):
                    if word: words.append((word, lex(word)))
                    words.append((i, lex(i)))
                    word = ''
                
                elif i == ' ':
                    if word: words.append((word, lex(word)))
                    word = ''
                    
                else:
                    word += i
                    
            if word: words.append((word, lex(word)))
        words_ = list(map(lambda arr: arr[0], words))
        print(expr(words_))

    функция считает лиспоподобные арифметические выражения, например так:

    run("(+ 2 (* 3 4))") # 14

    в своё оправдание могу лишь сказать, что писал это в электричке на планшете

    KolesnichenkoDS, 27 Мая 2015

    Комментарии (14)
  5. PHP / Говнокод #18150

    +142

    1. 1
    Как-то долго на PHP говнокода не появляется, все научились писать что ли?

    proweber1, 12 Мая 2015

    Комментарии (14)
  6. Си / Говнокод #18128

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static int card_open(struct inode *inode, struct file *f)
    {
        unsigned int		minor = MINOR(inode->i_rdev);
    
        DEBUG(KERN_CRIT "Driver: card_open()\n");
        f->private_data = (void *)(unsigned long long)minor;
    
        return 0;
    }

    А вместо минора надобно захуярить указатель на struct some_idiot_wrote_this *asshole в f->private_data.

    codemonkey, 07 Мая 2015

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

    +146

    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
    #ifndef FILTER_H
    #define FILTER_H
    
    #include <cassert>
    #include <vector>
    #include <algorithm>
    
    template<typename T>
    class filter_container;
    namespace detail {
    	template<typename Iter, typename Pred>
    	class filter {
    	public:
    		filter(Iter begin, Iter end, Pred pred) :_begin(begin), _end(end), _pred(pred) { }
    		filter(const filter & f) : _begin(f._begin), _end(f._end), _pred(f._pred) { }
    		filter & operator = (const filter & f) {
    			if(this != &f) {
    				_begin = f._begin;
    				_end = f._end;
    				_pred = f._pred;
    			}
    			return *this;
    		}
    		~filter() { }
    
    		class const_iterator {
    		public:
    			typedef typename Iter::reference reference;
    			typedef typename Iter::pointer pointer;
    			const_iterator(Iter iter, const filter & cont) :_iter(iter), _cont(&cont) { advance_until_pred(); }
    			const_iterator(const const_iterator & i) :_iter(i._iter), _cont(i._cont) { }
    			const_iterator & operator = (const const_iterator & i) {
    				if(this != &i) {
    					_iter = i._iter;
    					_cont = i._cont
    				}
    				return *this;
    			}
    			~const_iterator() { }
    			const_iterator & operator++() { advance_until_pred(); return *this; }
    			const_iterator operator++(int) {
    				const_iterator ret = *this;
    				advance_until_pred();
    				return ret;
    			}
    			const reference operator*() const { return *_iter; }
    			const pointer operator->() const { return &*_iter; }
    			bool operator == (const const_iterator & i) const {
    				assert(_cont == i._cont);
    				return _iter == i._iter;
    			}
    			bool operator != (const const_iterator & i) const { return !(*this == i); }
    		protected:
    			Iter _iter;
    			const filter * _cont;
    		private:
    			void advance_until_pred() {
    				if(_iter != _cont->_end) {
    					std::advance(_iter, 1);
    				}
    				_iter = std::find_if(_iter, _cont->_end, _cont->_pred);
    			}
    		private:
    			const_iterator();
    		};
    
    		class iterator : public const_iterator {
    		public:
    			iterator(Iter iter, const filter & cont) :const_iterator(iter, cont) { }
    			iterator(const iterator & i) :const_iterator(i) { }
    			iterator & operator = (const iterator & i) { const_iterator::operator=(i); return *this; }
    			~iterator() { }
    			reference operator*() { return *_iter; }
    			pointer operator->() { return &*_iter;  }
    		private:
    			iterator();
    		};
    
    		iterator begin() { return iterator(_begin, *this); }
    		iterator end() { return iterator(_end, *this); }
    		const_iterator cbegin() const { return const_iterator(_begin, *this); }
    		const_iterator cend() const { return const_iterator(_end, *this); }
    	private:
    		Iter _begin, _end;
    		Pred _pred;
    	private:
    		filter();
    	}; 
    }
    
    template<typename Iter, typename Pred> 
    detail::filter<Iter, Pred> filter(Iter begin, Iter end, Pred pred) {
    	return detail::filter<Iter, Pred>(begin, end, pred);
    }
    
    #endif // FILTER_H

    Тривиальная крестовщина, ничего выдающегося. Внезапно подумалось, что подобный контейнер был бы довольно удобен.
    Мне просто любопытно, насколько быстро этот пост будет слит автоминусаторами :)

    Xom94ok, 29 Апреля 2015

    Комментарии (14)
  8. PHP / Говнокод #18068

    +145

    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
    function preg_replace_e_modifier(array $usage_tokens) {
        $tree = PhpCodeFixer::makeFunctionCallTree($usage_tokens);
        $data = PhpCodeFixer::delimByComma($tree[0]);
        $data = PhpCodeFixer::trimSpaces($data[0]);
        // getting delimiter
        if ($data[0][0] == T_CONSTANT_ENCAPSED_STRING) {
            $string = trim($data[0][1], '\'"');
            $delimiter = $string{0};
            if ($data[count($data)-1][0] == T_CONSTANT_ENCAPSED_STRING) {
                $string = trim($data[count($data)-1][1], '\'"');
                if (($modificator = strrchr($string, $delimiter)) !== false) {
                    if (strpos($modificator, 'e') !== false) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
        return false;
    }

    return false; return false; return false; return false; return false;
    https://github.com/wapmorgan/PhpCodeFixer

    27cm, 27 Апреля 2015

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

    +59

    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
    #include <iostream>
    #include <time.h>
    #include <cmath>
    #include <windows.h>
    using namespace std;
    int main()
    {
    Hashtable^ hat = gcnew Hashtable();
    hat->Add(1,"|");
    hat->Add(2,"||");
    hat->Add(3,"|||");
    hat->Add(4,"||||");
    hat->Add(5,"|||||");
    hat->Add(6,"||||||");
    hat->Add(7,"|||||||");
    hat->Add(8,"||||||||");
    hat->Add(9,"|||||||||");
    hat->Add(10,"||||||||||");
    hat->Add(11,"|||||||||||");
    hat->Add(12,"||||||||||||");
    hat->Add(13,"|||||||||||||");
    hat->Add(14,"||||||||||||||");
    hat->Add(15,"|||||||||||||||");
    hat->Add(16,"||||||||||||||||");
    hat->Add(17,"|||||||||||||||||");
    hat->Add(18,"||||||||||||||||||");
    hat->Add(19,"|||||||||||||||||||");
    hat->Add(20,"||||||||||||||||||||");
    hat->Add(21,"|||||||||||||||||||||");
    hat->Add(22,"||||||||||||||||||||||");
    hat->Add(23,"|||||||||||||||||||||||");
    hat->Add(24,"||||||||||||||||||||||||");
    hat->Add(25,"|||||||||||||||||||||||||");
    hat->Add(26,"||||||||||||||||||||||||||");
    hat->Add(27,"|||||||||||||||||||||||||||");
    hat->Add(28,"||||||||||||||||||||||||||||");
    hat->Add(29,"|||||||||||||||||||||||||||||");
    hat->Add(30,"||||||||||||||||||||||||||||||");
    hat->Add(31,"|||||||||||||||||||||||||||||||");
    hat->Add(32,"||||||||||||||||||||||||||||||||");
    hat->Add(33,"|||||||||||||||||||||||||||||||||");
    hat->Add(34,"||||||||||||||||||||||||||||||||||");
    hat->Add(35,"|||||||||||||||||||||||||||||||||||");
    hat->Add(36,"||||||||||||||||||||||||||||||||||||");
    hat->Add(37,"|||||||||||||||||||||||||||||||||||||");
    hat->Add(38,"||||||||||||||||||||||||||||||||||||||");
    hat->Add(39,"|||||||||||||||||||||||||||||||||||||||");
    hat->Add(40,"||||||||||||||||||||||||||||||||||||||||");
    hat->Add(41,"|||||||||||||||||||||||||||||||||||||||||");
    hat->Add(42,"||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(43,"|||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(44,"||||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(45,"|||||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(46,"||||||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(47,"|||||||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(48,"||||||||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(49,"|||||||||||||||||||||||||||||||||||||||||||||||||");
    hat->Add(50,"||||||||||||||||||||||||||||||||||||||||||||||||||");
    srand(time(0));
        for(int i = 1; i<50; i++)    
           {
             int r = rand() % 1000; 
             String^ s = hat[i]->ToString(); 
             Console::WriteLine("\r"+i*2+"% completed:"+s);                
           }    
        cout << endl << "Operation completed successfully.\n" << flush;
    return 0;
    }

    // http://stackoverflow.com/questions/16635787/making-a-console-progress-bar-windows/19589370#19589370
    // Рисуем прогресс бар на С++

    a1g0r, 27 Февраля 2015

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

    +51

    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
    void main() {
    	system("color 04");
    
    	setlocale(LC_ALL, "rus");
    
    
    
    	if (start == false)  {
    		logos();
    		loading();
    		start = true;
    		system("cls");
    	}
    
    
    
    	if (get_hero_s == false)  {
    		get_hero();
    		get_hero_s = true;
    	}
    
    
    
    
    	menu();
    	map();
    	if (go_went_gone == 1) {
    		system("cls");
    		cout << "\nВы напали на оборотня в тёмном лесу\n";
    		loading();
    		Sleep(1400);
    		fight("werewolf");
    
    
    		go_went_gone = 0;
    
    		main();
    	}
    	else if (go_went_gone == 3) {
    		system("cls");
    		cout << "\nВы напали на лучника в мрачном поле\n";
    		loading();
    		Sleep(1400);
    		fight("archer");
    
    
    		go_went_gone = 0;
    
    		main();
    	}
    
    
    	if (go_went_gone == 2) {
    		system("cls");
    		cout << "\nВы напали на гоблина в тёмном лесу\n";
    		loading();
    		Sleep(1400);
    		fight("werewolf");
    
    
    		go_went_gone = 0;
    
    		main();
    	}
    	else if (go_went_gone == 4) {
    		system("cls");
    		cout << "\nВы напали на лучника на костяного лучника в подземелье \n";
    		loading();
    		Sleep(1400);
    		fight("archer");
    
    
    		go_went_gone = 0;
    
    		main();
    	}

    Рекурсия мейна, и это курсовая работа!!

    BoMo, 20 Февраля 2015

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

    +142

    1. 1
    2. 2
    #define PHYSICAL        unsigned long
    #define VIRTUAL         unsigned long

    прикольное legacy

    cerevra, 13 Февраля 2015

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