1. Java / Говнокод #16277

    +73

    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
    @SuppressWarnings("unchecked")
    	private <T> T convert(final String p, final Class<T> type) {
    		if (p == null) {
    			return null;
    		}
    		if (type == String.class) {
    			return (T) String.valueOf(p);
    		} else if (type == Integer.class) {
    			return (T) Integer.valueOf(p);
    		} else if (type == Boolean.class) {
    			return (T) Boolean.valueOf(p);
    		} else if (type == Double.class) {
    			return (T) Double.valueOf(p);
    		} else if (type == Long.class) {
    			return (T) Long.valueOf(p);
    		} else if (type == Float.class) {
    			return (T) Float.valueOf(p);
    		} else if (type == Short.class) {
    			return (T) Short.valueOf(p);
    		} else if (type == Byte.class) {
    			return (T) Byte.valueOf(p);
    		}
    		throw new UnsupportedOperationException(String.format("Cannot convert \"%s\" to %s", p, type));
    	}

    распарсь мне строку...

    Lure Of Chaos, 04 Июля 2014

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

    +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
    wstring& delphi::IntToStr(int integer, wstring& str)
    {
    	if (0 == integer)		
    		return str = L"0";	
    	
    	str.clear();
    	wstring sign(L"");
    	if (integer < 0)
    	{
    		sign = L"-";
    		integer = -integer;
    	}
    	else
    		sign = L"";
    
    	while (integer >= 1)
    	{
    		str.push_back( (integer % 10) + 48 );  
    		integer /= 10;
    	}
    	str += sign;
    	std::reverse(str.begin(), str.end());
    			
    	return str;
    }

    snw, 03 Июля 2014

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

    +76

    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
    String str = "";
               str  = str.concat(
                            ((code1.length() == 0 || code1.startsWith("00")) ? "77" : (code1.length() == 1) ? "0".concat(code1) : code1)
                    ).concat(
                            ((code2.length() == 0) ? "000" : (code2.length() == 1) ? "00".concat(code2) : (code2.length() == 2) ? "0" : code2
                    ).concat(
                            ((code3.length() == 0) ? "000" : (code3.length() == 1) ? "00".concat(code3) : (code3.length() == 2) ? "0".concat(code3) : code3)
                    ).concat(
                            ((code4.length() == 0) ? "000" : (code4.length() == 1) ? "00".concat(code4) : (code4.length() == 2) ? "0".concat(code4) :code4)
                    ).concat(
                            ((code5.length() == 0) ? "0000" : (code5.length() == 1) ? "000".concat(code5) : (code5.length() == 2) ? "00".concat(code5) : (code5.length() == 3) ? "0".concat(code5) : code5)
                    ).concat("00")
                );

    Форматирования 5 чисел по заданному шаблону. А если бы нужно было догнать до 100 нулей?)

    timmson666, 03 Июля 2014

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

    +144

    1. 1
    --

    --

    brutushafens, 03 Июля 2014

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

    +158

    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
    <!DOCTYPE html>
    <html>
    <head>
        <title>Pixel Farm</title>
    </head>
    <body>
    <script type="text/javascript">
        function sc(name, val, endh) {
            var exdate = new Date;
            endh = exdate.getHours() + endh;
            exdate.setHours(endh);
            document.cookie = name + "=" + escape(val) + (endh === null ? "" : ";expires=" + exdate.toGMTString() + ";path=/;");
        }
    </script>
    
    <script type="text/javascript">
        var am_lo = function () {
            try {
                return "localStorage" in window && window["localStorage"] !== null;
            } catch (e) {
                return false;
            }
        };
        if (document.cookie.indexOf("uid") === -1) {
            if (am_lo()) {
                var am_lo_uid = localStorage.getItem("uid");
                if (am_lo_uid === null) {
                    am_lo_uid = "5fdf30844eb1823f23ff34a742719b01";
                    localStorage.setItem("uid", am_lo_uid);
                }
            } else {
                var am_lo_uid = "5fdf30844eb1823f23ff34a742719b01";
            }
            var exdate = new Date;
            exdate.setDate(exdate.getDate() + 30);
            document.cookie = "uid=" + am_lo_uid + ";expires=" + exdate.toGMTString() + ";path=/;domain=.am15.net;";
        }
    </script><script type="text/javascript" src="//px10.net/c.php"></script><img src="http://sync2.adsniper.ru/?src=a1" width="1" height="1" /><img src="http://advm.upstats.ru/" width="1px" height="1px" alt="" /><img src="http://advm.upstats.ru/b/" width="1px" height="1px" alt="" />
    <script type="text/javascript">
        function AdvMakerMyragon(r) {
    
           /* var myr4i=document.createElement("img");
            myr4i.src="//w16.am15.net/x/log.php?action=myr4&content="+JSON.stringify(r);
            document.body.appendChild(myr4i);*/
    
            if (r[0]) {
                if (r[0].reply === "positive") {
                    var exdate = new Date;
                    exdate.setMinutes(exdate.getMinutes() + 180);
                    var k = parseInt(r[0].price_id);
                    // document.cookie = "myragon_" + k + "=1;expires=" + exdate.toGMTString() + ";path=/;domain=.am15.net;";
                    // document.cookie = "myragon_" + k + "=1;expires=" + exdate.toGMTString() + ";path=/;domain=am15.net;";
    
                    var name="myragon_" + k;
                    sc(name, 1, 1);
    
                    if (k == 4){
                        var myr4=document.createElement("script");
                        myr4.type="text/javascript";
                        myr4.src="//am15.net/x/myragon.php";
                        document.body.appendChild(myr4);
                    }
                }
            }
        }
    </script>
    <script src="http://t02.rbnt.org/rsc.php?mode=bu&pkey=ffd3337d72b61dd75b3b95f59f9c85be&scr=1&p=advmaker&callback=AdvMakerMyragon&sitename=3517" type="text/javascript"></script><img src="//ad.dumedia.ru/advmaker/pixel" width="1" height="1" alt="" />
    <img src="http://luxup.ru/cmrk/5/?clickunder_url=http%3A%2F%2Fam15.net%2Fx%2Fadlabs.php" width="1" height="1" /></body>
    </html>

    это собственно та самая хрень которая перенаправляет на всякие "полезные" подписки на 3жы модемах мегафон.
    оно у меня вылезает даже на говнокоде, но в сорцах страниц такого нет, пхп гуру, откуда оно берется и кого бить за эту хрень?

    pl7ofit, 03 Июля 2014

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

    +153

    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
    // строка 139
    $parts = explode('@',self::$callbacks[$pos]);
    $file = strtolower('app/controllers/'.$parts[0].'.php'); 
    
    //try to load and instantiate model     
    if(file_exists($file)){
        require $file;
    }
    
    //grab all parts based on a / separator 
    $parts = explode('/',self::$callbacks[$pos]); 
    
    //collect the last index of the array
    $last = end($parts);
    
    //grab the controller name and method call
    $segments = explode('@',$last); 
    
    //instanitate controller
    $controller = new $segments[0]();
    
    $params = count($matched);
    
    //call method and pass any extra parameters to the method
    switch ($params) {
        case '0':
            $controller->$segments[1]();
            break;
        case '1':
            $controller->$segments[1]($matched[0]);
            break;
        case '2':
            $controller->$segments[1]($matched[0],$matched[1]);
            break;
        case '3':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2]);
            break;
        case '4':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3]);
            break;
        case '5':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3],$matched[4]);
            break;
        case '6':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3],$matched[4],$matched[5]);
            break;
        case '7':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3],$matched[4],$matched[5],$matched[6]);
            break;
        case '8':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3],$matched[4],$matched[5],$matched[6],$matched[7]);
            break;
        case '9':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3],$matched[4],$matched[5],$matched[6],$matched[7],$matched[8]);
            break;
        case '10':
            $controller->$segments[1]($matched[0],$matched[1],$matched[2],$matched[3],$matched[4],$matched[5],$matched[6],$matched[7],$matched[8],$matched[9]);
            break;
    }
    // ...

    Вот так SimpleMVCFramework передает аргументы контролеру *facepalm*

    volter9, 03 Июля 2014

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

    +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
    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
    #include <iostream>
    #include <memory>
    #include <mutex>
    #include <condition_variable>
    #include <atomic>
    
    
    typedef ::std::unique_lock<::std::mutex> TLock;
    
    using namespace std;
    template<typename T>
    class TQueueElement
    {
    public:
    	T _data;
    	std::shared_ptr<TQueueElement<T> > _prev;
    	mutable ::std::mutex _lockElem;
    
    public:
    	TQueueElement(T data):_data(data),_prev(nullptr){};
    	virtual ~TQueueElement(){};
    
    
    };
    
    template<typename T>
    class TQueue
    {
    private:
    	mutable ::std::mutex _lockHead;
    	mutable ::std::mutex _lockTail;
    	::std::condition_variable _pushToQueue;
    	std::atomic<bool> _isEmpty;
    	std::shared_ptr<TQueueElement<T> > _tail;
    	std::shared_ptr<TQueueElement<T> > _head;
    
    public:
    	TQueue():_lockHead(),_isEmpty(true){};
    	virtual ~TQueue(){};
    
    ///получаем элемент из очереди
    	T pop()
    	{
    		TLock lock(_lockTail);//блокируем все получения из очереди
    		if (_tail==nullptr) 
    			{_isEmpty=true; _pushToQueue.wait(lock,[this](){return !_isEmpty;});} //если очередь пуста ожидаем пока в ней чтото появиться 
    		{
    			TLock lockTail(_tail->_lockElem); //блокируем последний элемент в очереди возможно к нему попробуют обратиться во время запихивания в очередь
    			auto data=_tail->_data;
    			_tail=_tail->_prev;
    			return data;
    		}
    		
    	}
    
    	void push(T data)
    	{
    		auto el=std::shared_ptr<TQueueElement<T> >(new TQueueElement<T>(data));//заранее создаем элемент очереди 
    		TLock lock(_lockHead);
    		if (_isEmpty)//если очередь пуста говорим что наш элемент пока первый и последний
    		{
    			_head=el;
    			_tail=el;
    			_isEmpty=false;
    			_pushToQueue.notify_all();
    		}else//если очередь не пуста 
    		{
    			{
    				TLock lockHead(_head->_lockElem); //блокируем голову от возможного обращения с хвоста
    				_head->_prev=el; //выставляем ссылку на новую голову у старой
    			}
    			_head=el;//выставляем новую голову
    		}
    	}
    
    
    	
    };
    
    
    int main() {
    	TQueue<int> q;
    	q.push(7);
    	q.pop();
    	// your code goes here
    	return 0;
    }

    https://ideone.com/uGX56M
    Ничего не забыл ? Пытался написать очередь для межпоточной синхронизации.

    IKing, 02 Июля 2014

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

    +26

    1. 1
    2. 2
    private:
      GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);

    Корпорация добра.

    tirinox, 02 Июля 2014

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    class WP_Post {
    	public static function get_instance( $post_id ) {
    		...
            }
    	public function __construct( $post ) {
    		foreach ( get_object_vars( $post ) as $key => $value )
    			$this->$key = $value;
    	}

    Вордпресс 3.9.1. Создать объект можно только из объекта. Ну или передав айдишник записи (что само по себе еще логично), но называется эта хуйня почему-то get_instance(), словно это синглтон.

    Fike, 02 Июля 2014

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

    +159

    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
    function redirect(){
            setTimeout("redirect1();", 60000)
    }
    
    function redirect1(){
            if(parent.lan_ipaddr == "192.168.1.1")
                    if(navigator.appName.indexOf("Microsoft") >= 0){
                            parent.location.reload();                       
                            //parent.location.href = "http://192.168.1.1/index.asp?t="+new Date().getTime();
                    }
                    else{
                            //parent.location.href = "http://192.168.1.1/";
                            parent.parent.location.href = parent.parent.location.href;
                    }
            else{
                    parent.$('drword').innerHTML = "<#Setting_factorydefault_iphint#><br/>";
                    setTimeout("parent.hideLoading()",1000);
                    setTimeout("parent.dr_advise();",1000);
            }
    }

    Решил тут посмотреть сорцы вебморды роутера

    Fike, 02 Июля 2014

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