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

    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
    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
    class Program
        {
            static void Main(string[] args)
            {
                Cell[] cells = new Cell[15];
                cells[1] = new Cell(); //и ещё 14 подобных строк
                cells[1].AddAdjacentCell(cells[2], 1);
                cells[1].AddAdjacentCell(cells[5], 2); //и так для всех 15 ячеек
                Spore spore01 = new Spore(true, false, true, true, false, true);
                Spore spore02 = new Spore(true, true, true, true, true, true);
                for(Int16 i = 1; i <= 14; i++)
                    for (Int16 k = 1; k <= 14; k++)
                    {
                        if (i != k)
                        {
                            Console.Write("Trying " + i + " " + k + "... ");
                            cells[i].AddSpore(spore01);
                            cells[k].AddSpore(spore02);
                            bool badAttempt = false;
                            for(Int16 c = 1; c <= 14; c++)
                            {
                                if (cells[c].state == CellState.Empty)
                                {
                                    badAttempt = true;
                                    break;
                                }
                            }
                            Console.WriteLine(badAttempt.ToString());
                        }
                    }
    Console.ReadLine();
            }
        }
        class Cell
        {
            public CellState state;
            private Cell[] adjacentCells = new Cell[6];
            private Spore currentSpore = null;
            public Cell()
            {
                this.state = CellState.Empty;
                for (Int16 i = 0; i <= 5; i++)
                {
                    this.adjacentCells[i] = null;
                }
            }
            public void AddAdjacentCell(Cell cell, Int16 direction)
            {
                if (direction >= 6)
                    return;
    
                this.adjacentCells[direction] = cell;
            }
            public void Ray(Int16 direction)
            {
                if (this.adjacentCells[direction] == null)
                    return;
                if (this.adjacentCells[direction].state == CellState.Spore)
                    return;
                this.state = CellState.Light;
                this.adjacentCells[direction].Ray(direction);
            }
            public void AddSpore(Spore spore)
            {
                this.state = CellState.Spore;
                this.currentSpore = spore;
                for (Int16 i = 0; i <= 5; i++)
                {
                    if (this.currentSpore.directions[i] == true)
                        this.Ray(i);
                }
            }
            public void Reset()
            {
                this.state = CellState.Empty;
                this.currentSpore = null;
                for (Int16 i = 0; i <= 5; i++)
                {
                    this.adjacentCells[i] = null;
                }
            }
        }
        enum CellState
        {
            Empty,
            Light,
            Spore
        }
        class Spore
        {
            public bool[] directions = new bool[6];
            public Spore(params bool[] rays)
            {
                for (Int16 i = 0; i <= 5; i++)
                    this.directions[i] = rays[i];
            }
        }
    }

    (обсуждение программы для поиска решений для одной головоломки под Андроид)
    - Да щас напишем, хуль там делать то?
    (через 5 минут)
    - Ой, переполнение стека...
    - ...

    A1mighty, 11 Февраля 2016

    Комментарии (14)
  2. Куча / Говнокод #19426

    −2

    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
    type Speaker interface {
        SayHello()
    }
    
    type Human struct {
        Greeting string
    }
    
    func (Human) SayHello() {
        fmt.Println("Hello")
    }
    ...
    var s Speaker
    s = Human{Greeting: "Hello"}
    s.SayHello()

    Отсюда: https://habrahabr.ru/post/276981/

    Abbath, 10 Февраля 2016

    Комментарии (14)
  3. JavaScript / Говнокод #19425

    +2

    1. 1
    2. 2
    3. 3
    setInterval(function() {
    		jQuery('#thsp-sticky-header').find('.ya-site-form__submit').removeClass('ya-site-form__submit').addClass('ya-site-form__submit2');
    	}, 500)

    Undefined_one, 10 Февраля 2016

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

    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
    class ConnectDB {
      protected static $_instance; 
      
      private function __construct() {
        $this->DB = new DBConnector();
      }
    
      private function __clone() {}
    
      private function __wakeup() {}
    
      public static function getInstance() {
        
        if (empty(self::$instance)) {
          self::$_instance = new self;   
        }
        return self::$_instance;
      }
    
    }

    Синглтон, который каждый рас создает новый объект

    Nemesys, 10 Февраля 2016

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

    +5

    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
    var pts = new Vector3[vCount];
    var r = new Random();
    
    for (var i = 0; i < pts.Length; i++)
    pts[i] = new Vector3(r.Next(-10000, 10000), r.Next(-600, 600), r.Next(-10000, 10000)) * 0.05f;
    /*for (var i = 0; i < pts.Length; i++)
    for (var j = 0; j < pts.Length; j++)
    if (pts[i].X > pts[j].X)
    {
    var tmp = pts[i];
    pts[i] = pts[j];
    pts[j] = tmp;
    }*/
    var vertices = new VertexPositionColor[vCount];
    var indices = new int[vCount * 6];
    //*
    for (var i = 0; i < vCount; i++)
    {
    vertices[i] = new VertexPositionColor(pts[i], new Color(new Vector3(r.Next(-100000, 100000), r.Next(-100000, 100000), r.Next(-100000, 100000)) * 0.00001f));
    indices[i * 6] = i;
    indices[i * 6 + 3] = i;
    var minDist = new float[] { 100000000, 100000000, 100000000 };
    var minId = new int[] { 0, 0, 0 };
    for (var j = 0; j < vCount; j++)
    {
    if (j == i) continue;
    var dist = Vector3.DistanceSquared(pts[i], pts[j]);
    if (dist < minDist[0])
    {
    minDist[2] = minDist[1]; minId[2] = minId[1];
    minDist[1] = minDist[0]; minId[1] = minId[0];
    minDist[0] = dist; minId[0] = j;
    }
    else if (dist < minDist[1])
    {
    minDist[2] = minDist[1]; minId[2] = minId[1];
    minDist[1] = dist; minId[1] = j;
    }
    else if (dist < minDist[2])
    {
    minDist[2] = dist;
    minId[2] = j;
    }
    }
    indices[i * 6 + 1] = minId[0];
    indices[i * 6 + 2] = minId[1];
    indices[i * 6 + 4] = minId[1];
    indices[i * 6 + 5] = minId[2];
    }//*/

    Антон, 20 лет.

    Особенно вставило

    indices[i * 6 + 1] = minId[0];
    indices[i * 6 + 2] = minId[1];
    indices[i * 6 + 4] = minId[1];
    indices[i * 6 + 5] = minId[2];

    d_fomenok, 09 Февраля 2016

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

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public void SaveModels(IEnumerable<Activity> models)
     {
                if (models == null && models.Count() == 0) return;
                // step 1/3: remove empty models
                var empty = models.Where(m => !m.ForecastedValue.HasValue && !m.ActualValue.HasValue).ToList();
                if (empty != null)
                {
                    models = models.Except(empty);
                }
               .....
    }

    Зачем такая конструкция, если можно просто
    models = models.Where(m => m.ForecastedValue.HasValue && m.ActualValue.HasValue).ToList()
    К тому же проверка на null бесполезна - ни Where, ни ToList не могут вернуть null. Даже если в коллекции ничего не останется.

    sans, 08 Февраля 2016

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

    +4

    1. 1
    if(($ID+0)<1)

    Оригинальное приведение типов

    proweb, 08 Февраля 2016

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

    −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
    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
    var up = document.getElementById('upload'),
        text1 = document.getElementById('text1'),
        text2 = document.getElementById('text2'),
        sliderSize = document.getElementById('sliderSize'),
        sliderImage = document.getElementById('sliderImage'),
        file  = document.getElementById('image'),
        canvas = document.getElementById('canvas'),
        uploaded = document.getElementById('uploaded'),
        placeholder_image = document.getElementById('placeholder_image');
    
    up.addEventListener('click', uploadToImgur);
    
    text1.addEventListener('keyup', updateImage);
    text2.addEventListener('keyup', updateImage);
    sliderSize.addEventListener('change', updateImage);
    sliderImage.addEventListener('change', updateImage);
    file.addEventListener('change', changeAndUpdateImage);
    
    function readFile(fileInput, callback) {
        var f = fileInput.files[0];
        var reader = new FileReader();
        reader.onload = (function(theFile) {
            return function(e) {
                callback(e.target.result);
            };
        })(f);
        reader.readAsDataURL(f);
    }
    
    var curImg = null;
    
    placeholder_image.onload = function() {
        curImg = placeholder_image;
        updateImage();
    }
    
    function changeAndUpdateImage() {
        var img = new Image();
        readFile(file, function(dataURL) {
            img.onload = function() {
                curImg = img;
                sliderImage.value = Math.max(img.width, img.height);
                canvas.width = img.width;
                canvas.height = img.height;
                //canvas.style.height = img.height + 'px';
                //canvas.style.width = img.width + 'px';
                updateImage();
            }
            img.src = dataURL;
    
        });
           
    }
    
    function drawLines(ctx, lines, x, y, yStep) {
        lines = lines.split('\n');
        if (yStep < 0) lines = lines.reverse();
        lines.forEach(function(l, k) {
            ctx.strokeText(l, x, y + yStep * k);
            ctx.fillText(l,   x, y + yStep * k);
     
        });
    }
    
    
    
    function updateImage() {
        var LINE_HEIGHT = 1.1;
        var PARAGRAPH_HEIGHT = 1.5;
        
        var imgSizeLimit = parseFloat(sliderImage.value);
    
        var canvasSize = autoScale({
            w: curImg.width, 
            h: curImg.height
        }, imgSizeLimit);
    
        canvas.width = canvasSize.w;
        canvas.height = canvasSize.h;
    
        var ctx = canvas.getContext("2d");
        var txtSize = parseFloat(sliderSize.value) || 24;
    
        if (!curImg) return;
        
        ctx.strokeStyle = '#000000';
        ctx.fillStyle = '#ffffff';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        ctx.drawImage(curImg, 0, 0, canvas.width, canvas.height);
    
        ctx.font = txtSize + "px Impact";
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        ctx.lineWidth = Math.round(Math.max(1, txtSize / 12));
    
        drawLines(ctx, text1.value, canvas.width / 2, 
                  txtSize * PARAGRAPH_HEIGHT / 2, LINE_HEIGHT * txtSize);
        drawLines(ctx, text2.value, canvas.width / 2, 
                  canvas.height - txtSize * PARAGRAPH_HEIGHT / 2, -1 * LINE_HEIGHT * txtSize );

    partybreaker, 07 Февраля 2016

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

    −1

    1. 1
    http://i.imgur.com/xzte9cX.png

    Я.. я не могу просто взять и скопировать этот код сюда. Посмотрите сами...

    mikamika83, 06 Февраля 2016

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

    +1

    1. 1
    bool isNoGoodCommentText = String.IsNullOrEmpty(this.txbxCommentCtrl.Text) || String.IsNullOrWhiteSpace(this.txbxCommentCtrl.Text);

    И действительно, is not good

    pipjaka, 05 Февраля 2016

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