1. bash / Говнокод #15390

    −122

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

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

    Dummy00001, 07 Марта 2014

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

    −126

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

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

    Dummy00001, 07 Марта 2014

    Комментарии (8)
  3. 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)
  4. 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)
  5. 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)
  6. bash / Говнокод #15381

    −123

    1. 1
    2. 2
    3. 3
    # remove whole directory to avoid bugs like rm -rf ""/*
    rm -rf "$CHROOT_DIR"
    mkdir -p "$CHROOT_DIR"

    Вспомнилось bumblebee

    Elvenfighter, 07 Марта 2014

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

    +127

    1. 1
    unfoldr (\b -> fmap (const . (second $ drop 1) . break (==' ') $ b) . listToMaybe $ b)

    LispGovno, 07 Марта 2014

    Комментарии (11)
  8. Куча / Говнокод #15377

    +126

    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
    check =: 3 : 0
    a=.>;:y
    b=.|:(6,#y) $,'(){}[]'=/a
    b=.(-1 3 5{"(1)b) (1 3 5)}"(1) b
    c=.|:(3 2$i.6)([:+/[{[:|:])"(1 _) b
    no=._1
    n=.#c
    p=. 13 : 'I.*./"(1)(1 _1)="(1)(2+\(x{y))'
    while. n~:no do.
    no=.n
    cc =. |:c
    d=.~.(0 p cc),(1 p cc),(2 p cc)
    c=.((i.#c)-.(d,>:d)){c
    n=.#c
    end.
    n=0
    )
    
    samples =: '({[{}]{}[]})';'({}}{[{}]{}[]})';'({[{}]{}[]}';'({[{}]{}]})';'({[{}{}[]})';'';'{}'
    
    test =: 13 : 'check >y{samples'
    
    test"(0) i.7

    По мотивам http://govnokod.ru/15363

    Abbath, 06 Марта 2014

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

    +84

    1. 1
    // TODO: Add comment here to explain what we do

    нашёл на прасторах праектуса %))

    Pepper-X, 06 Марта 2014

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

    −117

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    (
       if [ ! -z "$UNIX95" ] ; then
          unset UNIX95
       fi
       ...
    )

    Продолжение темы "Java программисты пишут на шелле": в подшелле, убрать переменную, если поставлена.
    А то вдруг шелл какой NullPointerException бросит.

    Dummy00001, 06 Марта 2014

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