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

    +6

    1. 1
    2. 2
    3. 3
    if (selectedGroup == null)
        return null;
    return selectedGroup;

    зачем if то?

    kontora, 23 Мая 2016

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

    0

    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
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    
    namespace ConsoleApplication2
    {
      [StandardModule]
      internal sealed class Module1
      {
        [STAThread]
        public static void Main()
        {
    label_0:
          int num1;
          int num2;
          try
          {
            ProjectData.ClearProjectError();
            num1 = 1;
    label_1:
            int num3 = 2;
            Test.TTT();
            goto label_8;
    label_3:
            num2 = num3;
            switch (num1)
            {
              case 1:
                int num4 = num2 + 1;
                num2 = 0;
                switch (num4)
                {
                  case 1:
                    goto label_0;
                  case 2:
                    goto label_1;
                  case 3:
                  case 4:
                    goto label_8;
                }
            }
          }
          catch (Exception ex) when (ex is Exception & (uint) num1 > 0U & num2 == 0)
          {
            ProjectData.SetProjectError(ex);
            goto label_3;
          }
          throw ProjectData.CreateProjectError(-2146828237);
    label_8:
          if (num2 == 0)
            return;
          ProjectData.ClearProjectError();
        }
      }
    }

    Вот какая жуть получилась при декомпиляции старого доброго On Error Resume Next из VB.
    Исходный код:
    Sub Main()
    On Error Resume Next
    TTT() 'определен в модуле Test
    Exit Sub
    End Sub

    yamamoto, 23 Мая 2016

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

    +4

    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
    string TRASETXT::trace(string &a // получаемая строка ) 
    { 
        string b; // возвращаемая строка 
        stringstream s; // строковый поток 
        // переводит в втооом словосочетании все большие буквы в маленькие 
        for (unsigned int i = 0; i < a.size(); i++) // а - получаемая строка 
        { 
            int key = a[i]; 
            if ((key <= -33) && (key >= -64)) // от А до Я 
                key += 32; 
            if (key == -88) // только буква Ё 
                key = -72; 
            if ((key >= 65) && (key <= 90)) // от A до Z 
                key += 32; 
            s << (char)key; 
        } 
        getline(s, b); // получаем строку только из маленьких букв во временную переменную 
        s.clear(); // очищаем поток 
        return b; 
    }

    Увидел в курсаче у чувака, лучший метод преобразования строки в lowercase, везде буду использовать теперь и вам рекомендую

    semoro, 23 Мая 2016

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

    +4

    1. 1
    http://надальнийвосток.рф

    ну не всем же напитон...

    defecate-plusplus, 22 Мая 2016

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

    +4

    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
    if ($_REQUEST["date_type"] == 1) {
                    $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($doneStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC) AND t.id NOT IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($doneStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                } else {
                    if ($_REQUEST["date_type"] == 2) {
                        $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE `status_id` AND (DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto'])))."))";
                     } else  {                 
                        if ($_REQUEST["date_type"] == 3) {
                            $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE ((`status_id`=".$DB->F($doneStatus["id"])." OR `status_id`=".$DB->F($failStatus["id"])." OR `status_id`=".$DB->F($failOpStatus["id"]).") AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC) AND t.id NOT IN (SELECT task_id FROM `task_comments` WHERE ((`status_id`=".$DB->F($doneStatus["id"])." OR `status_id`=".$DB->F($failStatus["id"])." OR `status_id`=".$DB->F($failOpStatus["id"]).") AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";                
                        } else {
                            if ($_REQUEST["date_type"] == 4) {
                                // am
                                $filter .= "AND tick.inmoney=1  AND DATE_FORMAT(tick.inmoneydate, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom']))) . " AND DATE_FORMAT(tick.inmoneydate, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto'])));
                            } else {
                                if ($_REQUEST["date_type"] == 5) {
                                    //cl_date
                                    $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($closedStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC) AND t.id NOT IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($closedStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                                } else {
                                    if ($_REQUEST["date_type"] == 6) {
                                        //rep_date
                                        $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($reportStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                                    } else {
                                        if ($_REQUEST["date_type"] == 7) {
                                            //rep_date
                                            $filter .= "AND t.id IN (SELECT task_id FROM `task_comments` WHERE (`status_id`=".$DB->F($accStatus["id"])." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom'])))." AND DATE_FORMAT(`datetime`, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto']))).") ORDER BY `datetime` DESC)";
                                        } else {
                                            $filter .= " AND DATE_FORMAT(t.date_reg, '%Y-%m-%d')>=".$DB->F(date("Y-m-d", strtotime($_POST['datefrom']))) . " AND DATE_FORMAT(t.date_reg, '%Y-%m-%d')<=".$DB->F(date("Y-m-d", strtotime($_POST['dateto'])));
                                        }
                                    }
                                }  
                            }
                            
                        }
                     }
                }

    Запрос для какого-то отчета by ©senior shaurma developer

    pahhan, 22 Мая 2016

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

    0

    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
    u_long thisIp = htonl(this->sockaddr.sin_addr.S_un.S_addr);
        u_long otherIp = htonl(other.sockaddr.sin_addr.S_un.S_addr);
        u_short thisPort = htons(this->sockaddr.sin_port);
        u_short otherPort = htons(other.sockaddr.sin_port);
    
        // ip1 + port1 < ip2 + port2
        if (thisIp < otherIp)
        {
            if (thisPort <= otherPort)
            {
                return true;
            }
            else
            {
                return ((unsigned)(thisPort - otherPort) < (unsigned)(otherIp - thisIp));
            }
        }
        else
        {
            if (thisPort >= otherPort)
            {
                return false;
            }
            else
            {
                return ((unsigned)(thisIp - otherIp) < (unsigned)(otherPort - thisPort));
            }
        }

    Сравнить IPv4 адрес + порт. Т.е., по сути, (thisIP + thisPort) < (otherIP + otherPort).
    unsigned long long, приди!

    gost, 21 Мая 2016

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

    0

    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
    // jquery required
    
    function trim(str){
    	return str.replace(/^\s+/, "").replace(/\s+$/, "");
    }
    
    function round1000(val){
    	return Math.round(parseInt(val)/1000)*1000;
    }
    function floor1000(val){
    	return Math.floor(parseInt(val)/1000)*1000;
    }
    function ceil1000(val){
    	return Math.ceil(parseInt(val)/1000)*1000;
    }
    
    function setCookie(c_name,value,expiredays){
    	var exdate=new Date();
    	exdate.setDate(exdate.getDate()+expiredays);
    	document.cookie=c_name+'='+escape(value)+((expiredays==null)?'':';expires='+exdate.toGMTString())+';path=/';
    }
    
    function resetCookie(c_name){
      var exdate=new Date(0);
    	document.cookie = c_name + '=0;expires=' + exdate.toUTCString() + ';path=/';
    }
    
    function getCookie(name){
    	var cookies=document.cookie.split(";");
    	for(var i=0;i<cookies.length;i++){
    		var params=cookies[i].split("=");
    		if(trim(params[0])==name){
    			return unescape(params[1]);
    		}
    	}
    	return false;
    }
    
    function asyncScriptLoader(scriptUrl){
    	var d=document,
    	h=d.getElementsByTagName('head')[0],
    	s=d.createElement('script');
    	s.type='text/javascript';
    	s.async=true;
    	s.src=scriptUrl;
    	h.appendChild(s);
    }

    http://www.morton.ru/images/js/main.js

    >> // jquery required
    >> function asyncScriptLoader(scriptUrl){

    nik757, 20 Мая 2016

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

    +3

    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
    bool  Object::DeleteDouble(void* data)
        {
            Element* rc = Head;
            BANKCLIENT* asd = (BANKCLIENT*)rc->Data;
            int dbl;
            Element* rc1 = Head;
            BANKCLIENT* asd1 = (BANKCLIENT*)rc1->Data;
            while ((rc != NULL) && (rc->Data != data))
            {
                asd = (BANKCLIENT*)rc->Data;
                dbl = asd->NumScore;
                while ((rc1 != NULL) && (rc1->Data != data))
                {
                    asd1 = (BANKCLIENT*)rc1->Data;
                    if (dbl == asd1->NumScore)
                    {
                        std::cout << "Дублирующийся элемент удалён" << std::endl;
                        Delete(rc1);
                        goto flag;
                    }
                }
            }
        flag:
            system("pause");
            return rc;
        }

    Некая svetlana.kotik раскрывает секреты односвязных списков.

    Fluttie, 20 Мая 2016

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

    −3

    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
    96. 96
    97. 97
    98. 98
    99. 99
    <?php
    namespace AppBundle\Command;
    
    use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    
    class InterpolationLabsCommand extends ContainerAwareCommand
    {
    
        /**
         * nodes for interpolation polynomial
         */
        protected $_nodes;
    
    
        protected function configure()
        {
            $this
                ->setName('app:interpolation:labs')
                ->setDescription('interpolation')
                ->addOption('nodes-count', null, InputOption::VALUE_REQUIRED, 
                    'Sets the number of nodes for interpolation.', null);
        }
    
    
        protected function execute(InputInterface $input, OutputInterface $output)
        {
            $intervalStart = -3;
            $intervalEnd  = 3;
    
            $nodesCount = $input->getOption('nodes-count');
            
            $this->generateSeries($nodesCount, $intervalStart, $intervalEnd, function($x) {
                return sin($x);
            });
    
            foreach (range($intervalStart, $intervalEnd, 0.1) as $value) {
    
                $result = $this->getLagrangeValue($value);
                $output->writeln("$value $result");
            }
        }
    
        /**
         * Find value for lagrange interpolation polynomial at n nodes
         * @throw \Exception
         * 
         * @return 
         */
        protected function getLagrangeValue($x)
        {
    
            $w = function($nodeKey) use ($x) {
    
                if (!array_key_exists($nodeKey, $this->_nodes)) {
                    throw new \Exception("The key is not exists to the array nodes");
                }
    
                $return = 1;
                foreach ($this->_nodes as $key => $node) {
                    if ($key == $nodeKey) {
                        continue;
                    }
    
                    $return *= ($x - $node->x)/($this->getNode($nodeKey)->x - $node->x);
                }
                return $return;
            };
    
            $result = 0;
            foreach ($this->_nodes as $nodeKey => $node) {
                $a = $w($nodeKey);
    
                $result += $w($nodeKey) * $node->fx;
            }
    
            return $result;
    
        }
    
        protected function getNode($i)
        {
            return $this->_nodes[$i];
        }
    
    
        private function generateSeries($num,  $intervalStart, $intervalEnd,  $fun)
        {
            for ($i=0; $i < $num; $i++) { 
    
                $x  = $intervalStart + ($intervalEnd - $intervalStart)/($num-1) * $i;
                $this->_nodes[] = (object) array('x' => $x, 
                    'fx' => $fun($x)); 
            }
        }
    }

    Лаба по методам численного анализа

    konmado, 19 Мая 2016

    Комментарии (13)
  10. Куча / Говнокод #20044

    +6

    1. 1
    2. 2
    Что вообще за херня, почему для каждого язычка(рантайма) делают свой пакетный менеджер? pip, npm, cabal, Quicklisp, opam, nuget, NPMчо там еще?
    И притом все они считают что для языка %LanguageName% всенепременно надо писать пакетный менеджер на нем самом.

    Вот например когда я что-то устанавливл через pip, какая-то там херня требует openssl-devel. И узнаю я это только по ошибкам компиляции, ну т.е. там какая-то поебень криптографическая вызывается из питона, оно при установке компилирует через GCC некое говно которое инклудит какое-то .h говно от openssl, но поскольку этого .h нет, оно обламывается на этапе компиляции. Какого хера я про это должен узнавать только на этапе компиляции блядь? Какого хера я должен вручную разруливать эти говнозависимости? А если например будет программа на руби которая использует программу на лиспе, которая использует программу на хаскеле использующую программу на окамле, то что мне, всю эту поеботу тоже руками разруливать по цепочке?

    https://blog.versioneye.com/2014/01/15/which-programming-language-has-the-best-package-manager/

    какие-то уебни еще сравнивают, какой язык имеет лучший пакетный менеджер... Мудачье! Кто вам сказал что делать для каждого ёбаного языка свой пакетный менеждер это хорошая идея и что среди них может быть "лучший"? Они все говно по определению. Нужно или некое стандартное API для общения между разными пакетными менеджеры разных языков, или один единый пакетный менеджер для всего и под все ОС(а не только Gentoo).

    j123123, 19 Мая 2016

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