1. PHP / Говнокод #16262

    +159

    1. 1
    2. 2
    3. 3
    if ($_POST['category']===1){ //Визначаємо яку категорію вибрав користувач ...
        "INSERT INTO `advertisement` (category) VALUES ('Квартира')";
    }

    Пришло время выполнить запрос. Запрос сам не выполнится...

    Взято отсюда: http://govnokod.ru/16259

    bormand, 30 Июня 2014

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

    +155

    1. 1
    (isset($presetFilters)) ? ((in_array($object->id,$presetFilters)) ? $object->avatar('-s') : $object->avatar('-gs-s')) : $object->avatar('-gs-s')

    код для получение префикса аватарки

    v1m, 30 Июня 2014

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    $exp_date=$item['expiration_date'];
    list($date,$time)=explode(' ',$exp_date);
    list($day,$month,$year)=explode('/',$date);
    echo $day.'.'.$month.'.'.$year.' '.$time;

    работа с датой
    преобразования из
    05/12/2013 11:12:00
    в
    05.12.2013 11:12:00

    icevic1, 30 Июня 2014

    Комментарии (17)
  4. PHP / Говнокод #16259

    +150

    1. 1
    http://pastebin.com/8Ym0mX6G вот здесь смотрите.

    Webius, 30 Июня 2014

    Комментарии (27)
  5. JavaScript / Говнокод #16258

    +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
    function toJData(
                                r_name_short_row,
                                r_name_full_row,
                                r_id_row, r_name_short_col,
                                r_name_full_col, r_id_col,
                                r_period,
                                r_year,
                                r_recruit,
                                r_contract,
                                r_recruit_plan,
                                r_contract_plan,
                                index
                    ){
    		var tmp = new Object();
    		tmp.r_name_short_row=r_name_short_row;
    		tmp.r_name_full_row = r_name_full_row;
    		tmp.r_id_row = r_id_row;
    		tmp.r_name_short_col = r_name_short_col;
    		tmp.r_name_full_col = r_name_full_col;
    		tmp.r_id_col = r_id_col;
    		tmp.r_period =r_period;
    		tmp.r_year = r_year;
    		tmp.r_recruit = r_recruit;
    		tmp.r_contract = r_contract;
    		tmp.r_recruit_plan = r_recruit_plan;
    		tmp.r_contract_plan = r_contract_plan;
    		tmp.index = index;
    		return tmp;
    		
    	}

    Разбираю код сотрудника, отчалившего в отпуск.
    Внезапно до меня доходит, что я вижу: это же пресловутое клонирование!

    torbasow, 30 Июня 2014

    Комментарии (12)
  6. JavaScript / Говнокод #16257

    +157

    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
    $('.send_message').click(function(e){
    	e.preventDefault();
    
    	var error = false;
    	var name = $('#contact_form_holder'+this.id).find('#name').val();
    	var email = $('#contact_form_holder'+this.id).find('#email').val();
    	var phone = $('#contact_form_holder'+this.id).find('#phone').val();
    	var subject = $('#contact_form_holder'+this.id).find('#subject').val();
    	var message = $('#contact_form_holder'+this.id).find('#message').val();
    
    	if(name.length == 0){
    		var error = true;
    		$('#contact_form_holder'+this.id).find(".name_field").addClass('error1');
    	}else{
    		$('#contact_form_holder'+this.id).find(".name_field").addClass('success');
    	}
    	if(email.length == 0 || email.indexOf('@') == '-1'){
    		var error = true;
    		$('#contact_form_holder'+this.id).find(".email_field").addClass('error1');
    	}else{
    		$('#contact_form_holder'+this.id).find(".email_field").addClass('success');
    	}
    	if(phone.length == 0){
    		var error = true;
    		$('#contact_form_holder'+this.id).find(".phone_field").addClass('error1');
    	}else{
    		$('#contact_form_holder'+this.id).find(".phone_field").addClass('success');
    	}
    		if(subject.length == 0){
    			var error = true;
    			$('#contact_form_holder'+this.id).find(".subject_field").addClass('error1');
                }else{
    				$('#contact_form_holder'+this.id).find(".subject_field").addClass('success');
                }
    	   if(message.length == 0){
                    var error = true;
    				$('#contact_form_holder'+this.id).find(".message_field").addClass('error1');
                }else{
    				$('#contact_form_holder'+this.id).find(".message_field").addClass('success');
                }
    				if(error == false){
    					$('#contact_form_holder'+this.id).find('.send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });
    					$formVar = this.id;
    
    					 $.post('send_email.php', $('#contact_form_holder'+$formVar).find('#contact_form').serialize(),function(result){
    						 if(result == 'sent'){
    							$('#contact_form_holder'+$formVar).find(".cf_submit_p").remove();
    							$('#contact_form_holder'+$formVar).find('#mail_success').fadeIn(500);
    						}else{
    							$('#contact_form_holder'+$formVar).find('#mail_fail').fadeIn(500);
    							$('#contact_form_holder'+$formVar).find('.send_message').removeAttr('disabled').attr('value', 'Send The Message');
    						}
    					});
    
    				if(error == false){
    				$('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });
    					$.post("send_email.php", $("#contact_form").serialize(),function(result){
    						if(result == 'sent'){
    							$('#cf_submit_p').remove();
    							$('#mail_success').fadeIn(500);
    						}else{
    							$('#mail_fail').fadeIn(500);
    							$('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
    						}
    					});
    				}
    				}
            });
    });

    Форма обратной связи, сайт веб-студии:
    http://medialine.by/job/js/script.js

    grishko, 30 Июня 2014

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

    +161

    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
    //! Массив типов пользователей
    $UserTypes = array();
    
    $result = $db->Query("SELECT 'Физ.лицо' AS type_user_rus, 'human' AS type_user FROM DUAL
    UNION ALL
    SELECT 'Юр.лицо' AS type_user_rus, 'firm' AS type_user FROM DUAL");
    
    if( $db->isError( $result ) ){
            die( $result->getMessage() . " at line " . __LINE__ . " in file " . __FILE__ );
    }
    
    while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) )
    {
        $UserTypes[$row['TYPE_USER']] = $row['TYPE_USER_RUS'];
    }

    Формирование массива с типами клиентов

    psrustik, 30 Июня 2014

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

    +76

    1. 1
    return new Double(Math.ceil(weight)).intValue();

    И снова autoboxing не в почете

    kostoprav, 30 Июня 2014

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

    +16

    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
    /*
        Дана последовательность, содержащая от 2 до 50 слов, в каждом из которых от 1 до 8 строчных
        латинских букв; между соседними словами - не менее одного пробела, за последним словом - точка.
        Напечатать те слова последовательности, которые отличны от первого слова и
        удовлетворяют следующему свойству: в слове нет повторяющихся букв.
    */
    #include <iostream>
    #include <cstring>
    using namespace std;
    
    void strComparsion(const char *str1, const char *str2, const int beginStr2, const int endStr2);
    int main()
    {
    
        char arrWord[50*8+50+1] = "spros na java programmistov"
                                                " rastet i v etom vinovat chertov android.";
        int counterSpace = 0; //Счетчик пробелов
        char strOneBuffer[9]; //Массив для первого слова
    
        cout << "Na vhode: \n" << arrWord << endl;
        cout << "Na vyhode: \n";
    
        //Копируем первое слов  в отдельный массив
        for(int i = 0; arrWord[i-2] != ' ';i++)
        {
            strOneBuffer[i] = arrWord[i];
            if(arrWord[i] == ' ')
            {
                strOneBuffer[i] = '\0';
                counterSpace = i;
            }
        }
    
        for(int i = counterSpace + 1, j = counterSpace + 1; arrWord[i] != '\0' ; i++)
            if(arrWord[i] == ' ' || arrWord[i] =='.')
            {
               strComparsion(strOneBuffer, arrWord, j, i);
               j = i +1;
            }
    
        return 0;
    }
    void strComparsion(const char *str1, const char *str2, const int beginStr2, const int endStr2)
    {
        //Флаги
        int countSymbol = 0;
        int repeatSymbol = 0;
    
        //Сравниваем слова с первым словом
        if( strlen(str1) == endStr2 - beginStr2 )
            for(int i = 0, j = beginStr2; j < endStr2; i++, j++)
                if(str2[j] == str1[i])
                    countSymbol++;
    
        //Ищем повторяющийся буквы в слове
        for(int i = beginStr2; i < endStr2; i++)
            for(int j = beginStr2; j < endStr2; j++)
            {
                if(i == j)
                    continue;
                if(str2[i] == str2[j])
                    repeatSymbol++;
            }
    
        //Выводим слово по требуеиым критериям
        if(countSymbol < strlen(str1) && repeatSymbol == 0)
            for(int i = beginStr2; i < endStr2; i++)
            {
                cout << str2[i];
                if(i == endStr2 - 1)
                    cout << " ";
            }
    }

    Это я писал после 6 месяцев изучения кодинга

    ConstantineVL, 29 Июня 2014

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

    +130

    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
    class ProducerConsumer
        {
            private static Semaphore semaphore = new Semaphore(1, 2);
            static object locker = new object();
            static int product = 0;
            private static bool work = true;
            private static bool valueSet = false; // why??
    
            private static void Producer() // производитель
            {
                while (work)
                {
                    Console.WriteLine("Thread Producer start");
                    int sqr = 0;
                    semaphore.WaitOne(); // декрементируем счётчик семафора
                    for (int i = 0; i < 15; i++)
                    {
                        sqr = i * i;
                    }
                    lock (locker) // error
                    {
    
                        while (valueSet)
                        {
                            Thread.Yield();
                        }
                        product += sqr;
                        valueSet = true;
                        Console.WriteLine("Product put: " + sqr);
                        Console.WriteLine("Product now: " + product);
                    }
                    semaphore.Release(); // выход из семафора
                    Thread.Sleep(5000);
                }
            }
    
            private static void Consumer() // потребитель
            {
                const int MAX = 5;
                int[] arr = new int[MAX];
                int result = 0;
                Random rand = new Random();
    
                while (work)
                {
                    Console.WriteLine("Thread Consumer start");
                    semaphore.WaitOne(); 
                    for (int i = 0; i < 5; i++)
                    {
                        arr[i] = rand.Next(0, 1024);
                    }
                    for (int i = 0; i < 5; i++)
                    {
                        result += arr[i];
                    }
                    result /= 5;
                    while (!valueSet)
                    {
                        Thread.Yield();
                    }
                    lock (locker)
                    {
                        if (product - result > 0) // исключаем отриц.кол-ва продуктов
                        {
                            product -= result;
                            Console.WriteLine("Product get: " + result);
                        }
                        else 
                        {
                            Console.WriteLine("Product < 0");
                        }
                        valueSet = false;
                        Console.WriteLine("Product now: " + product);
                    }
                    semaphore.Release();
                    Thread.Sleep(5000);
                }
            }
    
            public static void Main()
            {
                Thread threadProducer = new Thread(Producer);
                threadProducer.Start();
    
                Thread threadConsumer = new Thread(Consumer);
                threadConsumer.Start();
    
                Thread.Sleep(5000);
    
                Console.WriteLine("Main thread start.");
                String str = System.Console.ReadLine();
                Console.ReadKey();
            } 
    }

    Корявый пример решения задачи "Producer-Consumer".

    qstd, 29 Июня 2014

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