1. 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)
  2. Java / Говнокод #16255

    +76

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

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

    kostoprav, 30 Июня 2014

    Комментарии (52)
  3. 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)
  4. 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)
  5. C++ / Говнокод #16252

    +25

    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
    unsigned char ToChar(const char& c1, const char& c2)
    {
        static map<char,int> mapping;
        mapping['0'] = 0;
        mapping['1'] = 1;
        mapping['2'] = 2;
        mapping['3'] = 3;
        mapping['4'] = 4;
        mapping['5'] = 5;
        mapping['6'] = 6;
        mapping['7'] = 7;
        mapping['8'] = 8;
        mapping['9'] = 9;
        mapping['A'] = 10;
        mapping['B'] = 11;
        mapping['C'] = 12;
        mapping['D'] = 13;
        mapping['E'] = 14;
        mapping['F'] = 15;
        return (unsigned char)(mapping[c2] + mapping[c1] * 16);
    }
    
    int main()
    {
        // Assuming "vector<unsigned char> content" stores the data in Hex format, one Hex character per cell.
        for(size_t i=0, j=0; i < content.size(); i+=2, j++)
        {
            content[j] = ToChar(content[i], content[i+1]);  // one unsigned char => 2 Hex characters 
        }
    }

    Индусы на СО. Я даже не знаю, что тут самое нелепое.
    http://stackoverflow.com/a/24470147/2489083

    javahutt, 28 Июня 2014

    Комментарии (31)
  6. Си / Говнокод #16251

    +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
    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
    switch(event->touch_point) {
          case 5:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x5);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y5);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 4:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x4);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y4);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 3:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x3);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y3);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 2:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x2);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y2);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
    //         printk("===x2 = %d,y2 = %d ====\n",event->x2,event->y2);
          case 1:
             input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
             input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->x1);
             input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->y1);
             input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
             input_mt_sync(data->input_dev);
             printk("===x1 = %d,y1 = %d ====\n",event->x1,event->y1);
    
          default:
    //         printk("==touch_point default =\n");
             break;
       }

    Автору платили за строки?
    Из драйвера тачскрина ft5x0x

    Pythoner, 28 Июня 2014

    Комментарии (28)
  7. Python / Говнокод #16250

    −96

    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
    import random
    
    while 0<1:
        inn_d=str(random.randint(100000000,999999999))
        a=int(inn_d[:1])*2
        b=int(inn_d[1:2])*4
        c=int(inn_d[2:3])*10
        d=int(inn_d[3:4])*3
        e=int(inn_d[4:5])*5
        f=int(inn_d[5:6])*9
        g=int(inn_d[6:7])*4
        l=int(inn_d[7:8])*6
        m=int(inn_d[8:9])*8
        x=a+b+c+d+e+f+g+l+m
        y=x%11
        if y%11==10:
            y=0
        print str(inn_d)+str(y)

    Такой вот генератор ИННов

    pl7ofit, 28 Июня 2014

    Комментарии (11)
  8. JavaScript / Говнокод #16249

    +160

    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
    $(document).ready(function()
    	{
    		$(".link-tab").click(function()
    		{
    		$(".div-tab").slideToggle();
    		});
    		$(".link-tab1").click(function()
    		{
    		$(".div-tab1").slideToggle();
    		});
    		$(".link-tab2").click(function()
    		{
    		$(".div-tab2").slideToggle();
    		});
    		$(".link-tab3").click(function()
    		{
    		$(".div-tab3").slideToggle();
    		});
    		$(".link-tab4").click(function()
    		{
    		$(".div-tab4").slideToggle();
    		});
    		$(".link-tab5").click(function()
    		{
    		$(".div-tab5").slideToggle();
    		});
    		$(".link-tab6").click(function()
    		{
    		$(".div-tab6").slideToggle();
    		});
    		$(".link-tab7").click(function()
    		{
    		$(".div-tab7").slideToggle();
    		});
    		$(".link-tab8").click(function()
    		{
    		$(".div-tab8").slideToggle();
    		});		
    	});

    Источник: http://www.mojaslovenia.ru/js/user.js

    grishko, 28 Июня 2014

    Комментарии (0)
  9. JavaScript / Говнокод #16248

    +164

    1. 1
    if( [ 'someString' ].indexOf( someVar ) !== -1 ) return;

    Предлагаю объявить конкурс на самую дурацкую замену конструкции if (someVar === 'someString') return;

    oshibka404, 27 Июня 2014

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

    +143

    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
    using System;
    using System.Text;
    public class Test
    {
    	public static void Main()
    	{
    		object obj = "Suck my balls";
    		string str1 = "Suck my balls";
    		string str2 = new StringBuilder().Append("Suck my ").Append("balls").ToString();
    		Console.WriteLine(obj==str1);//True
    		Console.WriteLine(str2==str1);//True
    		Console.WriteLine(obj==str2);//False
    	}
    }

    Нетранзитивный дотнет или головоломка на ночь

    kegdan, 27 Июня 2014

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