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

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. Си / Говнокод #17635

    +142

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

    прикольное legacy

    cerevra, 13 Февраля 2015

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

    −109

    1. 1
    2. 2
    3. 3
    def self.get_fio(l_name, f_name, s_name)
      "#{l_name} #{f_name} #{s_name}"
    end

    В модели User

    rezerbit, 12 Февраля 2015

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int main(void)
    {
    	int a=0,b=1000;
    	int * p;
    	p=malloc(sizeof(int)*b-7); // уменьшаем выделяемую память на 7 байт, а почему оно не падает?
    	for(;a<b;a++) p[a]=a;
    	printf("%lu",sizeof(int)*b);
    	free(p);
    }

    а если убрать 8 байт то уже падает,что-то где-то округляется что-ли?

    pl7ofit, 10 Февраля 2015

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

    +160

    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
    'idate' => 
            array (
              'UNIX' => '1346688000',
              'datetime' => '03.09.2012 19:00',
              'time' => '19:00',
              'hour' => '19',
              'second' => '00',
              'date' => '03.09.2012',
              'datename' => '03 September 2012',
              'year' => '2012',
              'y' => '12',
              'd' => '03',
              'd0' => '3',
              'm' => '09',
              'm0' => '9',
              'month' => 'September',
              'day' => 'Monday',
              'monthr' => 'сентября',
              'datenamer' => '03 сентября 2012',
              'ago' => '2 года назад',
            ),

    Правильное хранение даты. Работаю недавно и сам рак еще тот - но это слишком. Переношу БД из в свой проект и встречаю это...

    VladDelec, 28 Января 2015

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

    +54

    1. 1
    2. 2
    _defaultLog
    #include "stdafx.h"

    Это первые две строчки в C++ файле. Сам файл включен файл проекта. Ошибок компиляции нет. Сегодня удалю эту первую строку. В комментариях к комиту с этим изменением в свн написано: "Исправление дидлока".

    laMer007, 27 Января 2015

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

    +56

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    bool XIsEmptyString( LPCTSTR str )
    {
    	CString s(str);
    	s.TrimLeft();
    	s.TrimRight();
    
    	return ( s.IsEmpty() || s == _T("") );
    }

    Кажется разработчика настиг приступ паранойи.

    Взято из библиотека XMLite

    German_1984, 23 Января 2015

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