1. Лучший говнокод

    В номинации:
    За время:
  2. C# / Говнокод #8167

    +113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public List<ReducedPayer> red_pay_list
            {
                get
                {
                    if (Session["red_pay_list"] == null)
                        Session["red_pay_list"] = new List<ReducedPayer>();
    
                    return (List<ReducedPayer>)Session["red_pay_list"];
                }
    
                set { Session["red_pay_list"] = value; }
            }

    без коментариев

    bercerker, 12 Октября 2011

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

    +113

    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
    //чОткая функция которая возвращает количество отображаемых узлов
    //в дереве без скролла
    int GetcountVisibleNodesInList()
    {
        int res = 0;
    
        if (FormGUI.c_MainWorkSpaseTree.Nodes.Count == 0)
        {
            this.FormGUI.c_MainWorkSpaseTree.Nodes.Add(new TreeNode());
            res = this.FormGUI.c_MainWorkSpaseTree.Height / FormGUI.c_MainWorkSpaseTree.getNodeRectangle(this.FormGUI.c_MainWorkSpaseTree.Nodes[0]).Height;
            this.FormGUI.c_MainWorkSpaseTree.Nodes[0].Remove();
        }
        else
        {
            res = this.FormGUI.c_MainWorkSpaseTree.Height / FormGUI.c_MainWorkSpaseTree.getNodeRectangle(this.FormGUI.c_MainWorkSpaseTree.Nodes[0]).Height;
        }
    
        //и незабываем воткнуть вычисленное значение в комбобокс
        this.FormGUI.c_cmb_countRowsInPage.Text = (res - 4).ToString();
        return res;
    }
    
    //пример использования функции
    void FormGUI_Load(object sender, EventArgs e)
    {
        //возвращается интовое значение и ложится в комбобокс
        GetcountVisibleNodesInList();
    
        int CountRows = 0;
        if (int.TryParse(FormGUI.c_cmb_countRowsInPage.Text, out CountRows))
        {
            _LastShowedRowNumber = 0;
            GoToNextPage(); //там же комбобокс опять парсится
        }
    }

    обратите внимание на обработчик загрузки формы.
    Из нужного кода там только вызов GoToNextPage() в котором опять же парсим комбобокс

    UgayNick, 04 Июля 2011

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

    +113

    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
    public string GetNormalImage(int newWidth, int newHeight, string sufix = "normal") {
                String[] tmp = _originalImagePath.Split('.');
                String newImagePath = "";
                for (int i = 0; i < tmp.Length - 1; i++)
                {
                    newImagePath += tmp[i];
                    newImagePath += "_";
                }
                newImagePath += sufix + ".";
                newImagePath += tmp[tmp.Length - 1];
    
                
                Image oldImage = Image.FromFile(_originalImagePath);
                if (oldImage.Height >= oldImage.Width) {
                    Image newImage;
                    newImage = FixedSize(oldImage, newWidth, newHeight);
                    newImage.Save(newImagePath);
                } else {
    
                    float heightRatio = (float)newHeight / (float)oldImage.Height;
                    float widthRatio = (float)newWidth / (float)oldImage.Width;
    
                    float bestRatio = 1;
                    if (heightRatio < widthRatio) {
                        bestRatio = heightRatio;
                    } else {
                        bestRatio = widthRatio;
                    }
    
                    var result = new System.Drawing.Bitmap((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio));
                    using (var graphics = Graphics.FromImage(result))
                    {
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                        graphics.SmoothingMode = SmoothingMode.HighQuality;
                        graphics.DrawImage(oldImage, new Rectangle(Point.Empty, new Size((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio))));
                    }
                    result.Save(newImagePath);
                }
    
                return newImagePath;
            }

    ресайз изображения

    tuxcod, 30 Июня 2011

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

    +113

    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
    public bool Read_XMl_File (XDocument Xml_Document, ref game_data Game_Data) { 
                bool Is_Success=false;          /* Captures this function's result */
    
                try { 
                    this.Xml_Data = (game_data)Game_Data;
    /*              Recursively read through entire XML Document */ 
                    Xml_Document.Root.RecursivelyProcess ( 
                        Process_Child_Element,
                        Process_Parent_Element_Open,
                        Process_Parent_Element_Close);
                    Is_Success = true;
                    }
    
                catch (Exception ex) { throw ex; }
    
                Game_Data = this.Xml_Data;    /* Pass the data back to Xml_Data */
                return Is_Success;
                }
     public static void RecursivelyProcess (
                    this XElement element,
                    Action<XElement, int> childAction,
                    Action<XElement, int> parentOpenAction,
                    Action<XElement, int> parentCloseAction) {  
                if (element == null) { throw new ArgumentNullException ("element"); } 
                element.RecursivelyProcess (0, childAction, parentOpenAction, parentCloseAction);  
                }  
    
     private static void RecursivelyProcess (  
                this XElement element,  
                int depth,  
                Action<XElement, int> childAction,  
                Action<XElement, int> parentOpenAction,  
                Action<XElement, int> parentCloseAction)  { 
     
                if (element == null)  { throw new ArgumentNullException ("element"); } 
                if (!element.HasElements) {         /* Reached the deepest child */
                    if (childAction != null) { childAction (element, depth); }  
                    }  
                else  {                             /* element has children */
                    if (parentOpenAction != null)  { parentOpenAction (element, depth); }  
                    depth++;  
                   
                    foreach (XElement child in element.Elements ())  {  
                        child.RecursivelyProcess ( depth,  childAction,  parentOpenAction,  parentCloseAction );  
                        }     
                    depth--;  
                    
                    if (parentCloseAction != null)  {  parentCloseAction (element, depth);  }
                    }  
                }
            }

    Avance, 29 Апреля 2011

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

    +113

    1. 1
    Говнокод поломался. Гуесты теперь везде.

    Vasiliy, 01 Апреля 2011

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

    +113

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    int main(int argv,char *argc[]){
      ...
      if(fork() != 0)goto _EXIT;
      ...
      return 0;
    _EXIT:
      return 0;
    }

    Ну как ???

    Mooncrafter, 24 Марта 2011

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

    +113

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                string[] exit_program = { "1", "2", "3", "4", "5", "6" };
                bool flag = true;
                while(flag)
                {
                    Console.WriteLine("Введите команду");
                    string ss = Console.ReadLine();
    
                    for (int i = 0; i < exit_program.Length&&flag;i++)
                    {
                        
                        if (ss == exit_program[i])
                        {
                            Console.WriteLine("Вы ввели {0} и теперь можете выйти из цикла",ss);
                            flag = false;
                            break;
                        }
                                  
                    }
                    
                    
    
                   
                }
    
                Console.ReadLine();
              
            }
        }
    }

    Говнокод, позволяющий выйти из консольного приложение по нажатию цифр 1,2....6

    user12, 15 Февраля 2011

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

    +113

    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
    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
    	
        //Новый массив матриц размером, соответствующим количеству костей в скелете модели
        Matrix[] absoluteTransformations = new Matrix[pen.Bones.Count];
    	
        //Скопировать матрицы трансформации костей в массив матриц
        pen.CopyAbsoluteBoneTransformsTo(absoluteTransformations);
    
        foreach (ModelMesh mesh in pen.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.LightingEnabled = true;
                effect.EnableDefaultLighting();
                effect.Projection = projMatrix;
                effect.View = viewMatrix;
    
                //Установим новую мировую матрицу для родительской кости текущей сети
                //Так же здесь мы уменьшаем модель, применяя коэффициент масштабирования 0,13
                effect.World = absoluteTransformations[mesh.ParentBone.Index] * Matrix.CreateScale(0.13f);
            }
            //Выводим подготовленную сеть
            mesh.Draw();
        }
        base.Draw(gameTime);
    }

    костная анимация в XNA

    Kornew, 24 Января 2011

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

    +113

    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
    let rnd = System.Random()
     
    // создаём строку, содержащую 10 случайных чисел, разделённых пробелами
    let sourceString = System.String.Join (" ", [1..10] |> List.map (fun x -> rnd.Next(1, 10).ToString()))
     
    // функция, удаляющая повторяющиеся числа из строки
    let removeDuplicate str =
        // разбиваем строку на отдельные числа
        let sourceList = sourceString.Split ([|' '|]) |> Array.toList |> List.map (fun x -> System.Int32.Parse (x))
        
        // список, в который будем ложить неповторяющиеся элементы
        let newList = ref []
     
        // проходим по всем элементам исходного списка
        List.iter
            (fun x -> 
                // если элемента в новом списке ещё нет, кладём его туда
                if (List.exists (fun y -> y = x) !newList) = false 
                then (newList := List.append !newList [x]))
            sourceList
     
        // получаем строку из списка с неповторяющимися элементами
        System.String.Join (" ", !newList |> List.map (fun x -> x.ToString()))
     
    // получаем новую строку
    let resultString = removeDuplicate sourceString
     
    // выводим старую и новую строку
    printfn "%s" sourceString
    printfn "%s" resultString

    qbasic, 01 Января 2011

    Комментарии (37)
  11. C# / Говнокод #5125

    +113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    open System
     
    let mutable str = "1234455566667778888"
     
    for i = str.Length - 1 downto 1 do
        if str.[i] = str.[i-1] && Char.IsDigit(str.Chars(i)) then
            str <- str.Remove(i, 1);
     
    printfn "%s" str
    Console.ReadKey() |> ignore

    qbasic, 01 Января 2011

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