1. PHP / Говнокод #15402

    +123

    1. 1
    Mage::run();

    С этого места начинается боль и мучения.

    DrugMan, 09 Марта 2014

    Комментарии (11)
  2. PHP / Говнокод #15401

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    <?php
    
     $dataProvider = new CActiveDataProvider('User', array(
                'criteria'=>array(
                    'condition' => 'id = ' . $id,
                ),
            ));
    
    $regdata = $dataProvider->getData();
    if (is_array($regdata)) $regdata = current($regdata);
    //....
    $this->redirect(Yii::app()->createUrl('user/profile'));

    Как не стоит писать на Yii

    JiLiZART, 09 Марта 2014

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

    +130

    1. 1
    DECLARE (A, B INIT ((5)0,(5)1)) DIM (0:9) FLOAT;

    LispGovno, 08 Марта 2014

    Комментарии (23)
  4. PHP / Говнокод #15395

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php
    function get_md5($filename){
    return md5_file($filename)
    }
    echo "get_md5($_POST)";
    ?>

    Только начал php, посоветуйте литературу Х)

    VityaPW, 08 Марта 2014

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

    +37

    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
    int hamming(int i, int j, vector<state>& net) //returns Hamming distance between i and j nodes
    {
    	int res = 0;
    	if (net[i].nodes[0] != net[j].nodes[0])
    	{
    		res++;
    	}
    	if (net[i].nodes[1] != net[j].nodes[1])
    	{
    		res++;
    	}
    	if (net[i].nodes[2] != net[j].nodes[2])
    	{
    		res++;
    	}
    	if (net[i].nodes[3] != net[j].nodes[3])
    	{
    		res++;
    	}
    	if (net[i].nodes[4] != net[j].nodes[4])
    	{
    		res++;
    	}
    	if (net[i].nodes[5] != net[j].nodes[5])
    	{
    		res++;
    	}
    	if (net[i].nodes[6] != net[j].nodes[6])
    	{
    		res++;
    	}
    	if (net[i].nodes[7] != net[j].nodes[7])
    	{
    		res++;
    	}
    	if (net[i].nodes[8] != net[j].nodes[8])
    	{
    		res++;
    	}
    	if (net[i].nodes[9] != net[j].nodes[9])
    	{
    		res++;
    	}
    	if (net[i].nodes[10] != net[j].nodes[10])
    	{
    		res++;
    	}
    	if (net[i].nodes[11] != net[j].nodes[11])
    	{
    		res++;
    	}
    	if (net[i].nodes[12] != net[j].nodes[12])
    	{
    		res++;
    	}
    	return res;
    }

    Человеку срочно нужно узнать про существование циклов.

    galarr, 08 Марта 2014

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

    −122

    1. 1
    find $WORK/LOG -name "*.log" | grep "^app_"

    и писали же вроде это не в 2 утра...

    Dummy00001, 07 Марта 2014

    Комментарии (0)
  7. bash / Говнокод #15389

    −126

    1. 1
    2. 2
    3. 3
    4. 4
    while [ 1 ]
    do
      # ....
    done

    Прикололо. Не уверен что автор даже знает почему/как именно это работает.

    Dummy00001, 07 Марта 2014

    Комментарии (8)
  8. bash / Говнокод #15387

    −124

    1. 1
    2. 2
    out=`$SOME_PROPRIETARY_TOOL $LOTS_OF_PARAMETERS 2>&1`
    out=`echo $out | awk '{print $23}'`

    из официального скрипта. и мне вот ту $SOME_PROPRIETARY_TOOL надо править. пальцев до 23х считать не хватает.

    Dummy00001, 07 Марта 2014

    Комментарии (8)
  9. JavaScript / Говнокод #15384

    +156

    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
    if($(".picture-column.gallery").size()) {
    		$(".minigal-nav .counter").text("1 из " + $(".picture-column.gallery").find("li").size());
    
    		if (window.isWindowsPhone){
    			$(".minigal-nav li.next").attr("onclick", 'var index = $(".picture-column.gallery li.current").index(); index++; if(index > $(".picture-column.gallery").find("li").size() - 1) {index = 0;};switchImage(index);');
    			$(".picture-column.gallery img").attr("onclick", '$(".minigal-nav li.next").trigger("click");');
    			$(".minigal-nav li.prev").attr("onclick", 'var index = $(".picture-column.gallery li.current").index();index--;if(index < 0) {index = $(".picture-column.gallery").find("li").size() - 1;};switchImage(index);');
    		} else {
    			$(".minigal-nav li.next").on("click", function() {
    				var index = $(".picture-column.gallery li.current").index();
    				index++;
    				if(index > $(".picture-column.gallery").find("li").size() - 1) {
    					index = 0;
    				}
    				switchImage(index);
    			});
    			$(".picture-column.gallery img").on("click", function() {
    				$(".minigal-nav li.next").trigger("click");
    			});
    			$(".minigal-nav li.prev").on("click", function() {
    				var index = $(".picture-column.gallery li.current").index();
    				index--;
    				if(index < 0) {
    					index = $(".picture-column.gallery").find("li").size() - 1;
    				}
    				switchImage(index);
    			});
    		}
    
    		var switchImage = function(index) {
    			$(".picture-column.gallery li.current").fadeOut(function() {
    				$(this).removeClass("current");
    				$(".picture-column.gallery").find("li").eq(index).fadeIn().addClass("current");
    			});
    
    			$(".minigal-texts li.current").fadeOut(function() {
    				$(this).removeClass("current");
    				$(".minigal-texts").find("li").eq(index).fadeIn().addClass("current");
    			});
    
    			$(".minigal-nav .counter").text(index + 1 + " из " + $(".picture-column.gallery").find("li").size());
    		}
    	}

    Это что-то типа адаптивный слайдер))))

    farit_slv, 07 Марта 2014

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

    +27

    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 <iostream>
    #include <iterator>
    #include <algorithm>
    #include <vector>
    #include <utility>
    #include <sstream>
    #include <assert.h>
    using namespace std;
    
    struct PeriodDescription{
    	size_t length, repeat_amount, last_items_amount;
    	/*friend ostream& operator<<(ostream& os, const PeriodDescription& s){
    		os<<" (PeriodDescription){"<<s.length<<", "<<s.repeat_amount<<", "<<s.last_items_amount<<"} ";
    		return os;
    	}*/
    };
    
    /*template<class C>
    string co(C&& c){
    	ostringstream r;
    	r<<" (C) {";
    	copy(c.begin(), c.end(), ostream_iterator<typename C::value_type>(r, ", "));
    	r<<"}; ";
    	return move(r.str());
    }*/
    
    vector<PeriodDescription> find_repeat_sequences_since_begin(const string& sequence){
    	vector<PeriodDescription> result;
    	if(sequence.empty())
    		return result;
    	auto position_at_last_period=sequence.begin();
    	const char first_item = *position_at_last_period;
    	const auto after_last=sequence.end();
    	auto position_at_current_period = position_at_last_period;
    	while(true){
    		position_at_last_period=sequence.begin();
    		position_at_current_period = find(next(position_at_current_period), after_last, first_item);
    		PeriodDescription new_period {size_t(distance(position_at_last_period, position_at_current_period)), 1, 0};
    		while(position_at_current_period!=after_last && *position_at_last_period==*position_at_current_period){
    			++position_at_last_period; ++position_at_current_period;
    			if(++new_period.last_items_amount>=new_period.length){
    				new_period.last_items_amount = 0;
    				++new_period.repeat_amount;
    			}
    		}
    		if(new_period.repeat_amount==1 && new_period.last_items_amount==0)
    			return result;
    		result.push_back(new_period);
    		if(position_at_current_period==after_last)
    			return result;
    	}
    }
    
    vector<size_t> generate_FSM_failJumpIndices(const vector<PeriodDescription>& periodDescriptions, const size_t stringLength){
    	vector<size_t> r(stringLength+1);
    	for(const auto& pd : periodDescriptions){
    		for(size_t periodIndex=1; periodIndex<pd.repeat_amount; ++periodIndex)
    			for(size_t indexAtPeriod=0; indexAtPeriod<pd.length; ++indexAtPeriod)
    				r[(periodIndex*pd.length)+indexAtPeriod]=(periodIndex-1)*pd.length + indexAtPeriod;
    		for(size_t indexAtAfterPeriods=0; indexAtAfterPeriods<pd.last_items_amount; ++indexAtAfterPeriods)
    			r[pd.length*pd.repeat_amount+indexAtAfterPeriods]=pd.length*(pd.repeat_amount-1)+indexAtAfterPeriods;
    	}
    	return r;
    }
    
    vector<size_t> make_FSM_failJumpIndices(const string& sequence){
    	return generate_FSM_failJumpIndices(find_repeat_sequences_since_begin(sequence), sequence.size());
    }
    
    class FSM_for_find_equal_ranges{
    	size_t state;
    	vector<size_t> failJumpIndices;
    	string sequence;
    	string::const_iterator find_next(string::const_iterator checkPosition, const string::const_iterator last){
    		struct atReturn{
    			size_t& state;
    			~atReturn(){state = 0;}
    		}nullify{state};
    		if(checkPosition==last)
    			return last;
    		if(sequence.empty())
    			return next(checkPosition);
    		if(size_t(distance(checkPosition, last))<sequence.size())
    			return last;
    		while(true){
    			if(checkPosition==last)
    				return last;
    			if(*checkPosition==sequence[state])
    				++state;
    			else
    				state=failJumpIndices[state];
    			++checkPosition;
    			if(state>=sequence.size())
    				return prev(checkPosition, sequence.size());
    		}
    	}
    public:
    	template<class T>
    	FSM_for_find_equal_ranges(T&& sequence):

    Очередное собеседование. Пригласили на должность дельфина. Но оп отказался проходить собеседование на дельфи.
    http://ideone.com/zp5CRb

    USB, 07 Марта 2014

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