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

    +135

    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
    if (parameter == null)//если ведомость доков...
                    {
                        cmd.Connection = dbc;
                        cmd.CommandText =
                            "SELECT RTRIM(n.Element) + ' '+ RTRIM(e.Naim) " +
                            "FROM tb_Element e, tb_ElementName n " +
                            "WHERE n.id = e.id " +
                            "AND e.GostTU ='" + head.Text.Substring(0, head.Text.IndexOf(" ")) + "'";
                        dbc.Open();
                        naim = cmd.ExecuteScalar().ToString();
                        dbc.Close();
                        cmd.CommandText =
                        "SELECT " +
                        " LTRIM(RTRIM(s.NameProject)) " +
                        ",LTRIM(RTRIM(n.Element)) + ' '+ LTRIM(RTRIM(e.Naim)) " +
                        ",LTRIM(RTRIM(d.Obozn)) " +
                        "FROM " +
                        " tb_document d " +
                        ",tb_specificationproject s " +
                        ",tb_element e " +
                        ",tb_elementname n " +
                        "WHERE " +
                        "d.pinsp = s.pinsp " +
                        "AND e.pin = s.pinsp " +
                        "AND n.id = e.id " +
                        "AND s.NameProject IN  " +
                        "( " +
                        namelist +
                        ") " +
                        "ORDER BY d.Pinsp ";
                        dbc.Open();
                        dbr = cmd.ExecuteReader();
                        counter = 0;
                        template = File.ReadAllLines(System.Windows.Forms.Application.StartupPath + "\\doclist.xml");
                        while (template[counter].Trim() != "</Table>")
                        {
                            if (template[counter].Trim() != "<Cell ss:MergeAcross=\"4\" ss:StyleID=\"s67\"><Data ss:Type=\"String\">%name%</Data></Cell>")
                            {
                                filedata.Add(template[counter]);
                            }
                            else
                            {
                                filedata.Add("<Cell ss:MergeAcross=\"4\" ss:StyleID=\"s67\"><Data ss:Type=\"String\">" + naim + "</Data></Cell>");
                            }
                            counter++;
    
                        }
                        tail_start = counter;
                        counter = 8;
                        tmp = "";
                        while (dbr.Read())
                        {
                            if (tmp != dbr[0].ToString())
                            {
                                tmp = dbr[0].ToString();
                                //Определяю высоту строки
                                CalcHeight = " ss:Height = " + '"' + Convert.ToString(rowHeight * (1 + dbr[1].ToString().Length / 10)) + '"';
                                filedata.Add("<Row" + CalcHeight.Replace(',', '.') + ">");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"Number\">" + (counter - 7).ToString() + "</Data></Cell>");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\">" + dbr[1].ToString().TrimEnd() + "</Data></Cell>");
                            }
                            else
                            {
                                filedata.Add("<Row ss:Height = \"" + Convert.ToString(rowHeight).Replace(',', '.') + "\">");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"Number\">" + (counter - 7).ToString() + "</Data></Cell>");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            }
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\">" + dbr[2].ToString().TrimEnd() + "</Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("</Row>");
                            counter++;
                        }
                        counter = tail_start;
                        while (counter < template.GetLength(0))
                        {
                            filedata.Add(template[counter]);
                            counter++;
                        }
                    }

    Суровый промышленный код. Выгружаем в эксель данные из БД.

    Grover, 03 Декабря 2012

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

    −120

    1. 1
    Мутабелен ли 1С.Овощи.Банан?

    Коллега считает что мутабелен.

    serpinski, 03 Декабря 2012

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

    +141

    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
    <?php
    
    function createOperator($a = [])
    {
    	$IOperator = [
    		'index' => 1,
    		'iteration' => "",
    		'f' => 'print_r($a);if(++$a["index"] < $a["count"])
    				return eval($a["iteration"]);
    			else
    				return $a["result"];',
    		'run' => 'return eval',
    	];
    	if(!empty($a))
    	{
    		$IOperator['run'] = '$a = $'.$a['title'] . '; ' . $IOperator['run'] . '($a["iteration"]);';
    		$IOperator['iteration'] = '$a = array_merge($a, ' . $a['operation'] . ');' . "\n" . $IOperator['f'];
    		$IOperator = array_merge($a, $IOperator);
    	}
    	return $IOperator;
    }
    
    $fib = createOperator([
    	'first' => 1,
    	'result' => 1,
    	'count' => 5,
    	'title' => 'fib',
    	'operation' => '["first" => $a["result"], "result" => $a["first"]+$a["result"]]'
    ]);
    echo eval($fib['run']);
    
    
    $fac = createOperator([
    	'result' => 1,
    	'count' => 5,
    	'title' => 'fac',
    	'operation' => '["result" => $a["result"]*$a["index"]]',
    ]);
    echo eval($fac['run']);

    Меня потянуло сделать какую-то фигню. Встречайте, рефлексивное программирование.

    mkusher, 02 Декабря 2012

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

    +141

    1. 1
    1/-0 == 42

    Внезапно.

    serpinski, 02 Декабря 2012

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

    +121

    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
    This awesome yet simple and pragmatic PHP library performs an addition of two numbers.
    
    In early stages of Internet, developers were forced to work with poor, dry, functional, horrific languages. Everything had to be done through austere functions and operators. There was no objects. No interfaces. No dependency injection.
    
    For example, to make something as simple as an addition, our dads had to write: 1+1. Yeah, really.
    
    Hopefuly now, we have PHP 5.3 and its solid OOP implementation. SimplePHPEasyPlus lets you make this addition in a more fashionable way, using real OOP. It is fast, simple, flexible and tested. To add 1 to 1, all you have to do is:
    
    use SimplePHPEasyPlus\Number\NumberCollection;
    use SimplePHPEasyPlus\Number\SimpleNumber;
    use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
    use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
    use SimplePHPEasyPlus\Iterator\CallbackIterator;
    use SimplePHPEasyPlus\Operator\AdditionOperator;
    use SimplePHPEasyPlus\Operation\ArithmeticOperation;
    use SimplePHPEasyPlus\Operation\OperationStream;
    use SimplePHPEasyPlus\Engine;
    use SimplePHPEasyPlus\Calcul\Calcul;
    use SimplePHPEasyPlus\Calcul\CalculRunner;
    
    
    $numberCollection = new NumberCollection();
    
    $numberParser = new SimpleNumberStringParser();
    
    $firstParsedNumber = $numberParser->parse('1');
    $firstNumber = new SimpleNumber($firstParsedNumber);
    $firstNumberProxy = new CollectionItemNumberProxy($firstNumber);
    
    $numberCollection->add($firstNumberProxy);
    
    $secondParsedNumber = $numberParser->parse('1');
    $secondNumber = new SimpleNumber($secondParsedNumber);
    $secondNumberProxy = new CollectionItemNumberProxy($secondNumber);
    
    $numberCollection->add($secondNumberProxy);
    
    $addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');
    
    $operation = new ArithmeticOperation($addition);
    
    $engine = new Engine($operation);
    
    $calcul = new Calcul($engine, $numberCollection);
    
    $runner = new CalculRunner();
    
    $runner->run($calcul);
    
    $result = $calcul->getResult();
    $numericResult = $result->getValue(); // 2
    This library is now available for production purposes. Enjoy!

    [КО]Складывает 2 числа[/КО]

    Vasiliy, 01 Декабря 2012

    Комментарии (8)
  6. Куча / Говнокод #12235

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    val arr = new Array[Int](3)
    val arr2 = arr
    
    arr(0) = 100
    arr(1) = 200
    arr(2) = 300
    
    //arr2 == Array(100, 200, 300)

    Не говнокод конечно, хотя как посмотреть.

    Это нормально, учитывая, что val предполагает неизменяемость значения, или в данном случае считается, что только присвоить новое значение нельзя, а изменять внутреннюю структуру массива можно как захочешь?

    Ведь наже в C++ нельзя изменить значения const std::vector.

    Fai, 01 Декабря 2012

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

    +51

    1. 1
    2. 2
    #101 Check PHP configuration in console
    $ php -r "phpinfo\(\);"

    Вот такой скрипт нашёл в дебрях локального битрикса под NDA.

    serpinski, 01 Декабря 2012

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

    +50

    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
    public function getFilename($filename) {
            $string = ereg_replace("ж", "zh", $filename);
            $string = ereg_replace("ё","yo",$string);
            $string = ereg_replace("и", "i",$string);
            ......
    
            $string = ereg_replace("Т","T",$string);
            $string = ereg_replace("Б","B",$string);
            
            $string = ereg_replace(" ","_",$string);
            $filename = preg_replace("/[^\w\.\-_]/","",$string);
            
            return strtolower($filename);
        }

    UnnamedUser, 01 Декабря 2012

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

    +6

    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
    template <typename T, size_t rows, size_t cols>
    class Matrix {
    public:
        Matrix() :
            m_matrix(reinterpret_cast<T*>(new char[sizeof(T) * rows * cols]))
        {
            memset(m_matrix, 0, sizeof(T) * rows * cols);
            new (m_matrix) T[rows * cols];
    
            if ( rows == cols ) {
                for ( size_t i = 0; i < rows; i++ )
                    m_matrix[i * cols + i] = 1; // FIXME: this is hack
            }
    
        }
    
        // ...
    private:
        T *m_matrix;
    };

    Из прошлого куска.

    Инициализируем память нулями. А вдруг тип скалярный? :)

    Elvenfighter, 01 Декабря 2012

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

    +10

    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
    template <typename T, size_t rows, size_t cols>
    class Matrix {
    public:
        Matrix() :
            m_matrix(new T[rows * cols])
        {
            // Make identity matrix, if possible
            if ( rows == cols ) {
                for ( size_t i = 0; i < rows; i++ )
                    m_matrix[i * cols + i] = 1; // FIXME: this is hack
            }
    
        }
    
        // ...
    
        Matrix<T, rows, cols>& operator =(Matrix<T, rows, cols> &&other) {
            if ( this != &other ) {
                delete [] m_matrix;
                m_matrix = other.m_matrix;
    
                other.m_matrix = new T[cols * rows];
                other = static_cast<const Matrix&>(Matrix());
            }
    
            return *this;
        }
    
        // ...
    };

    Издержки move construtor :)

    Прошу внимания к строчкам 19-23

    Elvenfighter, 30 Ноября 2012

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