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

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

    +119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    private int Age(string startDate)
    {
         int now = int.Parse(DateTime.Today.ToString("yyyyMMdd"));
         var born = int.Parse(startDate);
         int age = ((now - born) / 10000);
         return age;
    }

    Пытаемся посчитать возраст персонажа :o)

    agilizt, 14 Марта 2012

    Комментарии (0)
  3. Куча / Говнокод #9567

    +119

    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
    package simplecms
    import auth.*
    
    class AuthFilters {
    
    	private checkPermission(def controller, def p, def session, def params) {
    		if (p) {
    			boolean result = session.user?.profile?.permissions?.contains(p)
    			if (p.delegate) {
    				result |=  controller.checkDelegation[p.name](session, params)
    			} else if (p.controllerChecked) {
    				result &= controller.checkPermission[p.name](session, params)
    			}
    			if (!result && p.parent) {
    				result = checkPermission(controller, p.parent, session, params)
    			}
    			return result
    		}
    		return true
    	}
    
    	def filters = {
    		main(controller:'*', action:'*') {
    			before = {
    				def mappings = PermissionMapping.findAllByControllerAndMethodInList(controllerName, [actionName, '*'])
    				boolean denied = mappings?.size() > 0
    				if (denied) {
    					def permissions = []
    					session.user?.attach()
    					mappings.each { mapping ->
    						if (mapping.permission?.guest) {
    							denied = false
    						} else if (permission.parent == null){
    							permissions << mapping.permission
    						}
    					}
    					if (denied) {
    						denied = !permissions.any { checkPermission(grailsApplication.mainContext.getBean(controllerName), it, session, params) }
    					}
    				}
    				return !denied
    			}
    		}
    	}
    }

    Нашёл у себя в проекте. Иерархия разрешений? ну так будем проверять только корневые, что заморачиваться?!

    0rt, 29 Февраля 2012

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

    +119

    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
    ApiException(final ResourceException cause, final Representation repr,
    			final Class<? extends ErrorResponse> responseClass) {
    		super(cause);
    		this.cause = cause;
    		
    		ErrorResponse response = null;
    		
    		try {
    			response = new ObjectMapper().readValue(repr.getText(), responseClass);
    		} catch (final Exception e) {
    			log.error("Error attempting to parse the error response", e);
    		} finally {
    			this.response = response;
    		}
    	}

    Возникла ошибка при возникновении ошибки...

    someone, 28 Февраля 2012

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

    +119

    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
    public  static  string      LoadGridDT          (TObjects pList, out DataTable Dt, params object[] pArgs)
    ...              
                    switch (pList)
                    {
                        case TObjects.Radio                 :
                            if (pArgs.Length == 1 && pArgs[0] is int)
                                vLoadResult = Protocol.Radionuclide.Load((int)pArgs[0], out Dt);
                            else if (pArgs.Length > 1 && pArgs[0] is int && pArgs[1] is bool)
                                vLoadResult = Part2.Radionuclide.Load((int)pArgs[0], out Dt);
                            else vLoadResult = Radionuclide.Load(out Dt);
                            break;
                        case TObjects.Protocol              :
                            // [0](int): Тип протокола; [1](int): Очередь; [2](bool): Активность; [3](int): Объект
                    if (pArgs.Length > 3 && pArgs[0] is int && pArgs[1] is int && pArgs[2] is bool && pArgs[3] is int)
                        if (pArgs.Length > 4 && pArgs[4] is int)
                            vLoadResult = Protocol.LoadList((int)pArgs[0], (int)pArgs[1], (int)pArgs[3], (bool)pArgs[2], out Dt, (int)pArgs[4]);
                        else
                        {
                            if (pArgs.Length > 4 && pArgs[4] is bool && (bool)pArgs[4] == true) // 5-й аргумент для загрузки детализированного списка протоколов с учетом объекта отбора
                                vLoadResult = Protocol.Load((int)pArgs[0], (int)pArgs[1], (int)pArgs[3], (bool)pArgs[2], out Dt);
                            else // недетализированный список протоколов с учетом объекта отбора
                                vLoadResult = Protocol.LoadList((int)pArgs[0], (int)pArgs[1], (int)pArgs[3], (bool)pArgs[2], out Dt);
                        }
                    else
                    // [0](List<int>): Типы протокола; [1](int): Очередь; [2](int): Id место отбора; [3](bool): Активность
                    if (pArgs.Length > 3 && pArgs[0] is List<int> && pArgs[1] is int && pArgs[2] is int && pArgs[3] is bool)
                        if (pArgs.Length > 4 && pArgs[4] is int)
                            vLoadResult = Protocol.LoadList((List<int>)pArgs[0], (int)pArgs[1], (int)pArgs[2], (bool)pArgs[3], out Dt, (int)pArgs[4]);
                        else
                            vLoadResult = Protocol.Load((List<int>)pArgs[0], (int)pArgs[1], (int)pArgs[2], (bool)pArgs[3], out Dt);
                    else
                    // [0](List<int>): Типы протокола; [1](int): Очередь; [2](bool): Активность
                    if (pArgs.Length > 2 && pArgs[0] is List<int> && pArgs[1] is int && pArgs[2] is bool)
                        if (pArgs.Length > 3 && pArgs[3] is int)
                            vLoadResult = Protocol.LoadList((List<int>)pArgs[0], (int)pArgs[1], (bool)pArgs[2], out Dt, (int)pArgs[3]);
                        else
                            vLoadResult = Protocol.LoadList((List<int>)pArgs[0], (int)pArgs[1], (bool)pArgs[2], out Dt);
                    else
                    // [0](int): Тип протокола; [1](int): Очередь; [2](bool): Активность;
                    if (pArgs.Length > 2 && pArgs[0] is int && pArgs[1] is int && pArgs[2] is bool)
                        if (pArgs.Length > 4 && pArgs[3] is bool && pArgs[4] is int)
                            vLoadResult = Protocol.LoadList((int)pArgs[0], (int)pArgs[1], (bool)pArgs[2], out Dt, (int)pArgs[4]);
                        else
                            vLoadResult = Protocol.Load((int)pArgs[0], (int)pArgs[1], (bool)pArgs[2], out Dt);
                    else
                    // [0](int): Тип протокола; [1](int): Очередь
                    if (pArgs.Length > 1 && pArgs[0] is int && pArgs[1] is int)
                        if (pArgs.Length > 2 && pArgs[2] is int)
                            vLoadResult = Protocol.LoadList((int)pArgs[0], (int)pArgs[1], out Dt, (int)pArgs[2]);
                        else
                            vLoadResult = Protocol.LoadList((int)pArgs[0], (int)pArgs[1], out Dt);
                    else
    ...

    Метод 500+ вот такого рода строк...

    gcoder, 08 Февраля 2012

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

    +119

    1. 1
    & = &amp; = &amp;&amp; = &amp;&amp;&amp;&amp; = ...

    ReckO, 04 Февраля 2012

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

    +119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    FROM: Glype 1.2
    SITE: http://www.glype.com/download.php
    FILE: themes/default/framedForm.inc.php
    LINE: 23
    
    #include script {
      display:none;
    }

    truekenny, 20 Января 2012

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

    +119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    static int getCheckNumber(int n)
    {
    return Average(n, 0);                //Сабж
    }
    
    static int Average(int x, int y)   //Функция вычисления среднего арифметического
    {
    return ((x + y) / 2);
    }

    Среднее арифметическое от произвольной переменной и нуля - эквивалентно делению на 2 :)

    vistefan, 09 Января 2012

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

    +119

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    class Greeter {
      static var prefix = 'Hello,';
    
      static greet(name) {
        print('$prefix $name');
      }
    }
    
    main() {
      var greeter = new Greeter();
      greeter.greet("govnokod!");
    }

    Решил потыкать в Dart (http://www.dartlang.org/), а он мне:
    greeter.greet$named is not a function

    rat4, 10 Октября 2011

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

    +119

    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
    // создаём источник для репитера
    
    private DataTable EventsDataTable
            {
                get
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add(
                        new DataColumn("ID", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("day", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("date", typeof(DateTime)));
                    dt.Columns.Add(
                        new DataColumn("title", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("url", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("description", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("location", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("place", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("FileDirRef", typeof(string)));
                    // Добавляем строчки
                    foreach (EventInfo ei in CalendarEvents)
                    {
                        DataRow dr = dt.NewRow();
                        dr["day"] = ei.EventDate.Date.ToString("ddMMyyyy");
                        dr["date"] = ei.EventDate;
                        dr["title"] = ei.Title;
                        dr["location"] = ei.Location;
                        dr["ID"] = ei.ID;
                        dr["FileDirRef"] = ei.FileDirRef;
                        dt.Rows.Add(dr);
                    }
                    return dt;
                }
            }
    
    
    protected void repeaterItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e != null
                        && e.Item != null
                        && e.Item.DataItem != null
                        && e.Item.DataItem is DataRow)
                    {
                        DataRow dataItem = (DataRow)e.Item.DataItem;
    
                        Label date = (Label)(e.Item.FindControl("date"));
                        date.Text = 
                            dataItem["date"] != null
                            ? Convert.ToDateTime(dataItem["date"].ToString()).ToString()
                            : Convert.ToDateTime(dataItem["Created"].ToString()).ToString();
                        date.Text = date.Text.Substring(0, date.Text.Length - 3);
    
                        HyperLink title = (HyperLink)(e.Item.FindControl("title"));
                        title.Text = dataItem["title"].ToString();
                        Label location = (Label)(e.Item.FindControl("location"));
                        location.Text = "Расположение: " + dataItem["location"].ToString();
                    }
    }

    Современный способ привязки данных в asp.net Repeater

    Gnet, 22 Июня 2011

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

    +119

    1. 1
    2. 2
    3. 3
    4. 4
    foreach (var list in Distances.ConvertToList())
    {
         dt.Rows.Add(ConvertToObject(list.ToArray()));
    }

    dotnetdeveloper, 12 Мая 2011

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