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

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

    +137

    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
    model.PID = row["PID"].ToString();
    model.Rect = row["RECt"].ToString();
    model.Pubt = row["PUBt"].ToString();
    model.Ex = row["Ex"].ToString();
    model.Prev_Vol = row["Prev_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Prev_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Curr_Vol = row["Curr_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Curr_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Mov_Vol = row["Mov_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Mov_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    decimal tonavgvol = Tools.ParseDecimalValue(row["Mov_Vol"].ToString());
    decimal currentvol = Tools.ParseDecimalValue(row["Curr_Vol"].ToString());
    if (row["Mov_Vol"].ToString() != "" && row["Curr_Vol"].ToString() != "" && tonavgvol != 0)
    	model.VolRat = (currentvol / tonavgvol).FormatAmount();
    model.Open_Vol = row["Open_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Open_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Close_Vol = row["Close_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Close_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.AllTicks = row["AllTicks"].ToString() != "" ? Tools.ParseDecimalValue(row["AllTicks"].ToString()).FormatAmountWithoutDecimal() : "";
    model.ATR = row["ATR14"].ToString() != "" ? Tools.ParseDecimalValue(row["ATR14"].ToString()).FormatAmountFourDecimals() : "";
    decimal open = Tools.ParseDecimalValue(row["Open"].ToString());
    decimal close = Tools.ParseDecimalValue(row["Close"].ToString());
    if (row["Open"].ToString() != "" && row["Close"].ToString() != "" && open != 0)
    	model.PrevDay = (((close - open) / open) * 100).FormatPercent();
    model.PrevClose = row["PrevClose"].ToString() != "" ? Tools.ParseDecimalValue(row["PrevClose"].ToString()).FormatAmount() : "";
    model.DayOpen = row["DayOpen"].ToString() != "" ? Tools.ParseDecimalValue(row["DayOpen"].ToString()).FormatAmount() : "";
    decimal prevclose = Tools.ParseDecimalValue(row["PrevClose"].ToString());
    decimal dayopen = Tools.ParseDecimalValue(row["DayOpen"].ToString());
    if (row["DayOpen"].ToString() != "" && row["PrevClose"].ToString() != "" && prevclose != 0)
    	model.OpenGap = (((dayopen - prevclose) / prevclose) * 100).FormatPercent();
    model.SPYLast = row["TONSPLast"].ToString() != "" ? Tools.ParseDecimalValue(row["TONSPLast"].ToString()).FormatAmount() : "";
    model.TONOpen = row["TONOpen"].ToString() != "" ? Tools.ParseDecimalValue(row["TONOpen"].ToString()).FormatAmount() : "";
    model.TONHigh = row["TONHigh"].ToString() != "" ? Tools.ParseDecimalValue(row["TONHigh"].ToString()).FormatAmount() : "";
    model.TONLow = row["TONLow"].ToString() != "" ? Tools.ParseDecimalValue(row["TONLow"].ToString()).FormatAmount() : "";
    model.TONLast = row["TONLast"].ToString() != "" ? Tools.ParseDecimalValue(row["TONLast"].ToString()).FormatAmount() : "";
    model.EODHigh = row["EODHigh"].ToString() != "" ? Tools.ParseDecimalValue(row["EODHigh"].ToString()).FormatAmount() : "";
    model.EODLow = row["EODLow"].ToString() != "" ? Tools.ParseDecimalValue(row["EODLow"].ToString()).FormatAmount() : "";
    model.EODClose = row["EODClose"].ToString() != "" ? Tools.ParseDecimalValue(row["EODClose"].ToString()).FormatAmount() : "";
    model.SPYClose = row["EODSPClose"].ToString() != "" ? Tools.ParseDecimalValue(row["EODSPClose"].ToString()).FormatAmount() : "";
    model.PostVWAP = row["PostVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["PostVWAP"].ToString()).FormatAmount() : "";
    model.PreVWAP = row["PreVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["PreVWAP"].ToString()).FormatAmount() : "";
    model.MainVWAP = row["MainVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["MainVWAP"].ToString()).FormatAmount() : "";
    model.AllVWAP = row["AllVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["AllVWAP"].ToString()).FormatAmount() : "";
    model.EODVWAP = row["EODVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["EODVWAP"].ToString()).FormatAmount() : "";
    
    decimal tonlast = Tools.ParseDecimalValue(row["TONLast"].ToString());
    decimal eodhigh = Tools.ParseDecimalValue(row["EODHigh"].ToString());
    decimal eodlow = Tools.ParseDecimalValue(row["EODLow"].ToString());
    decimal tonhigh = Tools.ParseDecimalValue(row["TONHigh"].ToString());
    decimal tonlow = Tools.ParseDecimalValue(row["TONLow"].ToString());
    decimal eodclose = Tools.ParseDecimalValue(row["EODClose"].ToString());
    decimal oedspclose = Tools.ParseDecimalValue(row["EODSPClose"].ToString());
    decimal tonsplast = Tools.ParseDecimalValue(row["TONSPLast"].ToString());
    
    // еще где-то 100-150 строчек в таком же духе

    ADO.NET во все поля.
    Бизнес-логика? Что это такое?

    P.S. У класса model все свойства типа string, у всех decimal переменных потом тоже вызывается ToString().

    vertu, 11 Апреля 2014

    Комментарии (15)
  3. PHP / Говнокод #15705

    +155

    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
    //выведет таблицу для отладки
    function ExecSQL_SelectTable($sql)
    {
    	if($data = ExecSQL_Select($sql)->fetchAll(PDO::FETCH_ASSOC)){
    		print '<table border=2>';
    		print '<tr>';
    		foreach(array_keys($data[0]) AS $v) print '<td>'.$v.'</td>';
    		print '</tr>';
    		foreach($data AS $row){
    			print '<tr>';
    			foreach($row AS $v) print '<td>'.$v.'</td>';
    			print '</tr>';
    		}
    		print '</table>';
    	}
    	die;
    }

    Что только люди не предумают чтобы не юзать нормальный debug и не отлаживать код нормально.

    smpl, 08 Апреля 2014

    Комментарии (15)
  4. Pascal / Говнокод #15499

    +101

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function GetBit(numBit,Val: integer):boolean;
    var
      i: integer;
    begin
      i := round(power(2,numBit-1));
      result := (i and Val) >0;
    end;

    Суровые и беспощадные битовые операции в дельфи. Причем коллега, у которого я это нашел неплохие программы пишет, во всяком случае по части удобства интерфейса мне до него далеко. Но иногда такие перлы встречаются.

    kipar, 17 Марта 2014

    Комментарии (15)
  5. Си / Говнокод #15447

    +134

    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 <stdio.h>
    #define max(x,y) ((x>y)?x:y)
    #define N 255
    typedef unsigned char uchar;
    
    uchar s,t,x,y,z,n,S[10000],FO[N+N*(N-1)/2];
    uchar mask[]={1,2,4,8,16,32,64,128};
    int TOP=0;
    unsigned int COUNTER=0,AO[N];
    FILE *in;
    
    int pop(){
    //if the top element in the stack is passed and stack is not empty,
    //find next parent vertex
    while(S[TOP]>128 && TOP>0) TOP-=S[TOP]-128;
    return(TOP);
    }
    
    int push(){		//add new elements to the stack
    int tmp=TOP,i,j,k;		//tmp is a temporary variable 
    x=S[TOP-S[TOP]+1];	//x is a parent vertex
    for(i=1;i<=FO[AO[x]];i++){
       y=FO[AO[x]+i];	//y is a neigbour of x 
       if(!test(y)){	//y is visited? if not keep going
         k=max(y/8+1,S[TOP]-2);	//copy set P(x) to the new set P(y)
         S[++tmp]=y;
         for(j=0;j<k;j++,S[++tmp]=0);
         S[++tmp]=k+2;
         for(j=1;j<=S[TOP]-2;j++) S[tmp-j]=S[TOP-j];
         S[tmp-(y/8+1)]|=mask[y-(y/8)*8];	//add child y to P(y)
       }
    }
    S[TOP]+=128;	//drop flag for the vertex x
    TOP=tmp;	//the last child y become parent
    }
    
    int test(int j){	//does vertex j in the set P(TOP)?
    z=((j/8+1)>S[TOP]-2)?0:(S[TOP-(j/8+1)] & mask[j-(j/8)*8])?1:0;
    return(z);
    }
    
    int inc(){	//the path was found
    COUNTER++;
    S[TOP]+=128;
    }
    
    int main(){
    int i,j,k;
    in=fopen("Data15.txt","r");	//open file
    fscanf(in," %d %d",&i,&n);		//read the number of vertices
    for(k=n,i=0;k>=0;k--){
       fscanf(in,"%d %d",&j,&FO[i]);
       j=FO[i];
       for(AO[n-k]=++i-1;j>0;j--,i++){
          fscanf(in,"%d ",&FO[i]);
       }
    }
    printf("Type first and end nodes: ");	//type s and t separated by space
    scanf("%d %d",&s,&t);
    S[0]=s;
    for(j=1;j<=s/8+1;S[j++]=0);
    S[j]=s/8+3;
    TOP=j;
    S[TOP-(s/8+1)]|=mask[s-(s/8)*8];
    while(pop()>=0) (test(s) && test(t))?inc():push(); //launch breadth-search algorithm
    printf("# of paths in the graph b/w s=%d and t=%d equals %d\n",s,t,COUNTER);
    return(0);
    }

    разбирая старый CD бэкап откопал лабу...(знаю,знаю что продакшн кошернее, и на сях не пишу со студенчества)
    хотел вайпнуть безжалости но вспомнил про говнокодосайт.
    помоему код люто доставляет.

    прога подсчитывает полное число путей в графе между заданными вершинами s и t.
    граф считывается из файла в формате: "номер_вершины степень_вершины {достижимые_вершины_через_пробел}"
    (по коду видно)

    govnyuk, 13 Марта 2014

    Комментарии (15)
  6. C++ / Говнокод #14398

    +9

    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 <iostream>
    #include <iterator>
    #include <algorithm>
    #include <array>
    #include <memory>
    using namespace std;
    
    template<size_t N1, size_t N2, class T1, class T2,
    class T = typename common_type<T1, T2>::type>
    T (*concatCArray(const T1(&arr1)[N1], const T2(&arr2)[N2]))[N1+N2]{
      const auto result = (T(*)[N1+N2]) new T[N1+N2];
      copy(arr2, end(arr2), copy(arr1, end(arr1), *result));
      return result;
    }
    template<std::size_t N, class T>
    void viewCArrayPtr(T (*arr)[N]){
      copy(*arr, end(*arr), ostream_iterator<T>(cout, " "));
    }
    template<size_t N1, size_t N2, class T1, class T2,
    class T = typename remove_const<typename common_type<T1, T2>::type>::type>
    array<T, N1+N2> concatArray(const array<T1, N1> &arr1, const array<T2, N2> &arr2){
      array<T, N1+N2> result;
      copy(begin(arr2), end(arr2), copy(begin(arr1), end(arr1), result.begin()));
      return result;
    }
    template<std::size_t N, class T>
    void viewArray(const array<T, N> arr){
      copy(begin(arr), end(arr), ostream_iterator<T>(cout, " "));
    }
    
    int main() {
      int arr1[]{0,1,2,3}, arr2[]{4,5,6};
      auto ca = concatCArray(arr1, arr2);
      unique_ptr<int[]> safe(*ca);
      viewCArrayPtr(ca);
      cout<<endl;
      array<float, 2> a {1,2.5};
      array<int, 3> b{3, 4, 5};
      viewArray(concatArray(a, b));
      return 0;
    }

    От туда.
    http://ideone.com/3KjycI

    LispGovno, 22 Января 2014

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

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    Sorry! The page could not be loaded.
    
    Unable to connect to MySQL and select database.
    MySQL reported: Access denied for user 'root'@'localhost' (using password: YES)

    http://gvforum.ru/

    эх, vasiliy, кто ж на продакшене базу от рута поднимает? надо же от юзверя с правами insert, delete, update, select

    Lure Of Chaos, 08 Января 2014

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

    +160

    1. 1
    2. 2
    3. 3
    {if $smarty.foreach.categories.iteration == 2 || $smarty.foreach.categories.iteration == 4 || $smarty.foreach.categories.iteration == 6 || $smarty.foreach.categories.iteration == 8 || $smarty.foreach.categories.iteration == 10 || $smarty.foreach.categories.iteration == 12  || $smarty.foreach.categories.iteration == 14  || $smarty.foreach.categories.iteration == 16}
          <div class="clear"></div>
    {/if}

    Smarty

    uadeveloper, 26 Декабря 2013

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

    +10

    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
    #include <iostream>
    #include <list>
    #include <queue>
    #include <memory>
    #include <mutex>
    #include <condition_variable>
    #include <type_traits>
    #include <assert.h>
    using namespace std;
    
    template<class Data>
    class UnboundedQueueForNonThrowMovable
    {
    	static_assert(std::is_nothrow_move_constructible<Data>::value, "Data must be nonthrow movable type.");
    	static_assert(!std::is_array<Data>::value, "Data must not be c-array.");
    	
    public:
    	typedef Data value_type;
    	
    private:
    	typedef std::queue<Data, std::list<Data>> Queue;
    	typedef std::unique_lock<std::mutex> Lock;
    	Queue _queue;
    	std::mutex _lockQueue;
    	std::condition_variable _pushToQueue;
    	
    	UnboundedQueueForNonThrowMovable(const UnboundedQueueForNonThrowMovable&) = delete;
    	UnboundedQueueForNonThrowMovable(UnboundedQueueForNonThrowMovable&&) = delete;
    	UnboundedQueueForNonThrowMovable& operator=(const UnboundedQueueForNonThrowMovable&) = delete;
    	UnboundedQueueForNonThrowMovable& operator=(UnboundedQueueForNonThrowMovable&&) = delete;
    public:
    	UnboundedQueueForNonThrowMovable(void){}
    	
    	void push(Data&& data)
    	{
    		Lock lockerQueue(this->_lockQueue);
    		this->_queue.push(std::move(data));
    		this->_pushToQueue.notify_all();//_condition.notify_one(); most optimal, but can cause deadlock.
    	}
    	
    	void push(Data& data)
    	{
    		this->push(std::move(data));
    	}
    	
    	bool emptyUnstable(void) const
    	{
    		Lock lockerQueue(this->_lockQueue);
    		return this->_queue.empty();
    	}
    	
    	Data pop(void)
    	{
    		Lock lockerQueue(this->_lockQueue);
    		this->_pushToQueue.wait(lockerQueue, [this](void){return !this->_queue.empty();});
    		assert(!this->_queue.empty());
    		Data result = std::move(this->_queue.front());
    		this->_queue.pop();
    		return result;
    	}
    	
    	template< class Rep, class Period>
    	Data pop(const std::chrono::duration<Rep, Period> WaitDuration)
    	{
    		Lock lockerQueue(this->_lockQueue);
    		if(!this->_pushToQueue.wait(lockerQueue, WaitDuration, [this](void){return !this->_queue.empty();}))
    			return Data();
    		assert(!this->_queue.empty());
    		Data result = std::move(this->_queue.front());
    		this->_queue.pop();
    		return result;
    	}
    };
    
    template<class Data>	
    using UnboundedQueueForUniquePtr = UnboundedQueueForNonThrowMovable<std::unique_ptr<Data>>;
    template<class Data>
    using UnboundedQueueForSharedPtr = UnboundedQueueForNonThrowMovable<std::shared_ptr<const Data>>;
    template<class Data>
    using UnboundedQueue = UnboundedQueueForUniquePtr<Data>;
    
    int main() {
    	cout<<"ok"<<endl;
    	{
    		//UnboundedQueueForSharedPtr<int>::value_type == std::shared_ptr<const int>
    		UnboundedQueueForSharedPtr<int> queueSharedPtr;
    		//auto a = std::make_shared<const int>(45);
    		auto a = std::make_shared<int>(45);
    		assert(a);
    		queueSharedPtr.push(a);
    		assert(!a);//Fired if you use "auto a = std::make_shared<int>(45)" below. It is compiler bug, I think, because previus code line must cause compile error.
    		auto b = queueSharedPtr.pop();//std::shared_ptr<const int>
    		assert(b);
    		cout<<*b<<endl;
    		assert(*b==45);

    http://ideone.com/qdsWJi
    Немного глупый вопрос, почему в 90 строчке не получаем ошибку компиляции если закомментировать 87-ую строку и разкомментировать 88-ую?

    laMer007, 16 Декабря 2013

    Комментарии (15)
  10. PHP / Говнокод #14231

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    //надо показать элемент каталога во всей красе
    $_CENTER="show_category_item(".$newParts[0].");";
    eval($_CENTER);
    
    // ...
    $_LEFT='get_main_category($cat_id, $new_path);';
    $_CENTER="show_category_item_list($".'newParts'.");";

    Вот с таким адом мне приходится работать.

    oooZinka, 16 Декабря 2013

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

    +136

    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
    countDigits :: (Integral a) => a -> Int
    {-# INLINE countDigits #-}
    countDigits v0 = go 1 (fromIntegral v0 :: Word64)
      where go !k v
               | v < 10    = k
               | v < 100   = k + 1
               | v < 1000  = k + 2
               | v < 1000000000000 =
                   k + if v < 100000000
                       then if v < 1000000
                            then if v < 10000
                                 then 3
                                 else 4 + fin v 100000
                            else 6 + fin v 10000000
                       else if v < 10000000000
                            then 8 + fin v 1000000000
                            else 10 + fin v 100000000000
               | otherwise = go (k + 12) (v `quot` 1000000000000)
            fin v n = if v >= n then 1 else 0

    Хаскельная магия из исходников Data.Text.

    Yuuri, 12 Декабря 2013

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