1. C++ / Говнокод #12104

    +19

    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
    //generate the new objects
        EnterCriticalSection(&csWinEvent);
        value arr = alloc_array(windowStates.size());
        int i=0;
        for(
            std::tr1::unordered_map<int,windowState>::const_iterator it = windowStates.begin();
            it!=windowStates.end();
            ++it )
        {
            value o = alloc_empty_object();
            //int hwnd
            //int x,y,w,h
            //int minimized,maximized,restored,closed
            alloc_field(o, val_id("hwnd"), alloc_int(it->first));
            alloc_field(o, val_id("window"), *(value*)GetWindowLongPtr((HWND)it->first,GWLP_USERDATA)  );
            alloc_field(o, val_id("x"), alloc_int(it->second.x));
            alloc_field(o, val_id("y"), alloc_int(it->second.y));
            alloc_field(o, val_id("w"), alloc_int(it->second.w));
            alloc_field(o, val_id("h"), alloc_int(it->second.h));
            alloc_field(o, val_id("minimized"), alloc_int(it->second.minimized));
            alloc_field(o, val_id("maximized"), alloc_int(it->second.maximized));
            alloc_field(o, val_id("restored"), alloc_int(it->second.restored));
            alloc_field(o, val_id("closed"), alloc_int(it->second.closed));
            val_array_set_i(arr,i,o);
            ++i;
        }
        windowStates.clear();
        LeaveCriticalSection(&csWinEvent);

    Casts ;]

    petersvp, 12 Ноября 2012

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

    +65

    1. 1
    $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");

    Opencart, catalog/model/catalog/product.php

    Они что издеваются? А я-то думаю что у меня ложит mysql сервер на колени...

    fooser, 12 Ноября 2012

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

    +71

    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
    class ........... {
        BigDecimal t;
    ...
        public boolean t_is_zero(){
            BigDecimal zero = new BigDecimal(0);
    
            if(this.t == zero)
                return true;
            else
                return false;
        }
    ...
    }

    для операции сравнения была создана новая переменная как эквивалент )

    azv, 12 Ноября 2012

    Комментарии (39)
  4. C++ / Говнокод #12101

    +13

    1. 1
    class TSettingGrouperator

    Говногость, 12 Ноября 2012

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

    +49

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if($model->validate(array('code')))
    {
    	$model->addError('code', 'Введен неверный код купона. Купон с таким кодом уже существует.');
    }
    else
    {
    	if($model->save())
    	{
    		$this->redirect(array('view','id'=>$model->id));
    	}
    }

    sleeper, 12 Ноября 2012

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

    +20

    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 <functional>
     
    using namespace std;
     
    template<class TReceiver, class TResult>
    struct TMessage
    {
        virtual const TResult sendTo(const TReceiver&) const = 0;
        virtual const TResult sendTo(TReceiver&) const = 0;
        virtual ~TMessage(void){}
    };
     
    template<class TReceiver, class T, class TResult=void>
    struct TTypedMessage : public TMessage<TReceiver, TResult>
    {
            T _data;
            explicit TTypedMessage(const T& data):_data(data)
            {}
     
            const TResult sendTo(const TReceiver& functor) const
            {
                    return functor(_data);
            }
     
            const TResult sendTo(TReceiver& functor) const
            {
                    return functor(_data);
            }
    };
     
    class T1
    {
            typedef T1 TThis;
    public:
            void operator()(const int& i)const{cout <<"int"<< i<<endl;}
            void operator()(const double& i)const{cout <<"double"<< i<<endl;}
            void operator()(const std::reference_wrapper<double>& i)const{cout <<"double&"<< i.get()<<endl;}
            template<class T>
            void operator()(const T& i)const{cout << "UnknowenMesage"<<endl;}
    };
     
    class T2
    {
            typedef T2 TThis;
    public:
            void operator()(int i)const{cout <<"int"<< i<<endl;}
            void operator()(double i)const{cout <<"doble"<< i<<endl;}
            void operator()(std::reference_wrapper<double> i)const{cout <<"double&"<< i.get()<<endl;}
    };
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(TReceiver& Receiver, TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(const TReceiver& Receiver, TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(TReceiver& Receiver, const TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    template<class TMessage, class TReceiver, class TResult=void>
    TResult sendMessage(const TReceiver& Receiver, const TMessage& Message)
    {
            TTypedMessage<TReceiver, TMessage, TResult> TypedMessage(Message);
            return TypedMessage.sendTo(Receiver);
    }
     
    int main() {
            T1 a;
            T2 b;
            sendMessage(a, 10);
            sendMessage(a, 10.0);
            double d=0;
            sendMessage(a, std::ref(d));
     
            sendMessage(b, 10);
            sendMessage(b, 10.0);
            sendMessage(b, std::ref(d));
            sendMessage(a, string("kokoko"));
            int aa=6;
            sendMessage(a, aa);
            return 0;
    }

    Найдено на просторах Интранета:
    http://ideone.com/pMSA1p
    В чем смысл? Так получается больше кода?

    LispGovno, 11 Ноября 2012

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

    +18

    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
    bool isRightTriangle(int a, int b, int c)
    {
        int przeciw=a;
    	if (b>przeciw) przeciw = b;
    	if (c>przeciw) przeciw = c;
    
    	if (przeciw=a)
    		if (a*a==b*b+c*c) return true;
    	else if (przeciw=b)
    		if (b*b==a*a+c*c) return true;
    	else if (przeciw=c)
    		if (c*c==a*a+b*b) return true;
                
        return false;
    }

    Fai, 11 Ноября 2012

    Комментарии (78)
  8. Pascal / Говнокод #12097

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Если ты имеешь в виду, что появляются полосы прокрутки и 
    уродуют окно или stringgrid, то просто оставляй "запас" в
    несколько пикселей, т.к. на разных системах может быть разная
    ширина краев формы и прочих элементов.
    А что, я еще и код писать должен чтобы какие-то экзотичные
    темы винды поддерживать? Нет уж, я лучше несколько
    пикселей оставлю запаса.

    Вся суть дельфинов
    http://www.gamedev.ru/code/forum/?id=168899

    Topacer, 11 Ноября 2012

    Комментарии (43)
  9. Куча / Говнокод #12096

    +125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    happy_numbers = [ tos (a,b,c,d,e,f a b c d e) | a <- [0..9], b <- [0..9], c <- [0..9], d <- [0..9], e <- [0..9], f a b c d e <= 9, f a b c d e >= 0 ]
    	where 
    		tos (a,b,c,d,e,f) = show a ++ show b ++ show c ++ show d ++ show e ++ show f
    		f a b c d e = a + b + c - d - e
    
    main = mapM print $ happy_numbers

    Fai, 11 Ноября 2012

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

    +17

    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
    #include <iostream>
     
    template< class Val >struct SwithClass
    {
        SwithClass( const Val & v ):val(v){}
        void operator() (){}
        template < class E, class F, class ... Args > void operator() ( E e, F f, Args ... args )
        {
           if( e==val )  f(); 
           else  (*this)( args... );
        }
    private:
        Val val;
    };
     
    template< class Val > SwithClass<Val> Swith( const Val& v ){  return SwithClass<Val>(v);}
     
    int main()
    {
        int x = 8;
        Swith( x )
        (
           1,  [](){  std::cout <<"x=1" << std::endl;  },
           8,  [](){  std::cout <<"x=8" << std::endl;  } 
        );
       return 0;
    }

    http://ideone.com/Xbj46U

    LispGovno, 11 Ноября 2012

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