1. C# / Говнокод #11362

    +112

    1. 1
    int cutPosition = sb.ToString().IndexOf("                                          \r\n                                          ");

    Коммерческий проект :)

    ddv_demon, 05 Июля 2012

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

    +15

    1. 1
    system("PAUSE")

    Красивое, оптимальное, и самое главное, кроссплатформенное решение для ожидания нажатия клавиши.
    http://habrahabr.ru/post/147104/

    Предупреждая вопрос "где здесь с++", отвечу - автор считал, что он пишет на с++, и даже использовал пару конструкций оттуда - перегрузку функций и new/delete.

    bormand, 05 Июля 2012

    Комментарии (50)
  3. C++ / Говнокод #11360

    +15

    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
    #pragma once
    #include <assert.h>
     
    template<typename T>
    inline T notNull(T arg)
    {
            assert(arg!=NULL);
            return arg;
    }
     
    /*
    //example:
    class AnotherClass;
    
    class SomeClass
    {
    AnotherClass * m_another;
    //...
            SomeClass(AnotherClass * another, /*skipped*/) : m_another(notNull(another)), /*skipped*/;
    }
    */

    Мелочь, конечно же, но всё-таки чушь, несмотря на пользу.

    Xom94ok, 04 Июля 2012

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

    +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
    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
    // хелпер чтобы конвертить типы строк
    template <class S1, class S2>
    struct str_convert {
    	static S1 conv(S2 const & s2) { return str_convert<S2, S1>::conv(s2); }		// по умолчанию ищет специализацию для пары S2, S1
    	static S2 conv(S1 const & s1) { return str_convert<S2, S1>::conv(s1); }
    };
    
    // специализация, чтобы не конвертить одно в одно
    template <class S>
    struct str_convert<S, S> {
    	static S const & conv(S const & s) { return s; };
    };
    
    // специализация, чтобы конвертить std::string <-> std::wstring
    template <>
    struct str_convert<std::string, std::wstring> {
    	static std::string conv(std::wstring const & ws) { return boost::locale::conv::utf_to_utf<char>(ws); }
    	static std::wstring conv(std::string const & s)  { return boost::locale::conv::utf_to_utf<wchar_t>(s); }
    };
    
    // специализация QString <-> std::string
    // skipped
    
    template <class StringType = std::string>
    struct some 
    {
    	typedef StringType		string_type;
    	typedef std::string		utf8_string_type;
    
    	some(string_type const & s = string_type())
    		: inner_string_(s)
    	{}
    
    	template <class S>
    	some(S const & s)
    		: inner_string_(str_convert<S, string_type>::conv(s))
    	{}
    
    	string_type inner_string_;
    };
    
    int main()
    {
    	std::string s = "hello!";
    	some<> test0(s);		  // ok
    	some<> test2("hello!"); // ха-ха, вот еще, пытаться самостоятельно привести к std::string, пиши специализацию для массивов, сука!
    	return 0;
    }

    сегодня ради красоты передачи "literal" в конструктор писал говноспециализации для PodType[N]

    defecate-plusplus, 04 Июля 2012

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

    +58

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $arrNotViewDeathWindow = array(
    			'/reklama/press/index.php' => '1',
    			'/reklama/press/' => '1',
    			'/reklama/product/index.php' => '1',
    			'/reklama/product/' => '1',
    			'/about/poll/' => '1',
    			'/about/poll/index.php' => '1',
    			'/about/poll/result.php' => '1',
    			'/reklama/product/orders_list.php' => '1',
    		);
    
    if(!$arrNotViewDeathWindow[$_SERVER['SCRIPT_NAME']]) ...

    Кусок кода из отображения всплывающего окна на сайте на всех страницах кроме...

    Cool-Di, 04 Июля 2012

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

    +23

    1. 1
    2. 2
    if(this==NULL)
      return;

    HaskellGovno, 04 Июля 2012

    Комментарии (10)
  7. JavaScript / Говнокод #11356

    +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
    18. 18
    19. 19
    20. 20
    21. 21
    switch(navigator.appName) {
       case "Microsoft Internet Explorer":
          Key = "event.ctrlKey && event.keyCode == 13";
          document.onkeydown = get_key;
          break;
       case "Netscape":
          Key = "(e.modifiers == 2 && e.which == 10) || (e.ctrlKey && e.which == 13)";
          document.captureEvents(Event.KEYDOWN);
          document.onkeydown = get_key;
          break;
    }
    }
    
    function get_key(e) {
    if (eval(Key)) {
    	if (check_postform()){
    		check_submit();
    		document.postform.submit();
    		submit_once(document.postform);
    	} else {return false}
    }

    http://forum.ixbt.com/

    jQuery, 03 Июля 2012

    Комментарии (10)
  8. Java / Говнокод #11355

    +77

    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
    /**
         * Returns the an array (length 1) containing the checkbox menu item
         * label or null if the checkbox is not selected.
         * @see ItemSelectable
         */
        public synchronized Object[] getSelectedObjects() {
            if (state) {
                Object[] items = new Object[1];
                items[0] = label;
                return items;
            }
            return null;
        }

    java.awt.CheckboxMenuItem

    Lure Of Chaos, 03 Июля 2012

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    reader = new BufferedReader(new FileReader(file));
    //null means file end
    while ((tempString = reader.readLine()) != null) {
        if(tempString !=null && tempString.indexOf('=')>0){
            sheet.addCell(new Label(KEY_COLUMN,++ROW, tempString.substring(0,tempString.indexOf('='))));
            sheet.addCell(new Label(ENGLISH_COLUMN,ROW, tempString.substring(tempString.indexOf('=')+1)));
        }
    }
    reader.close();

    Вот так мы парсим файл *.properties в Java.

    roman-kashitsyn, 03 Июля 2012

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

    +54

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    /**
         * Грабли - наше всьо
         * @return string
         */
        function toPage()
        {
            ...
        }

    прекрасно задокументированная функция

    shmaltorhbooks, 03 Июля 2012

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