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

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

    +69

    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
    String response = HttpLoader.loadString(params[0]);
    Gson gson = new GsonBuilder().registerTypeAdapter(ArrayList.class,
        new JsonCollectionSerializer<ArrayList<MyClass>>()).
        create();
    
    ArrayList<MyClass> items_generic = new ArrayList<MyClass>() { };
    ArrayList<MyClass> items = gson.fromJson(response, items_generic.getClass().getGenericSuperclass());
    return items;
    
    
    public class JsonCollectionSerializer<E> implements
            JsonSerializer<Collection<E>>, JsonDeserializer<Collection<E>> {
    
        @SuppressWarnings("unchecked")
        public Collection<E> deserialize(JsonElement element, Type type,
                                         JsonDeserializationContext context) throws JsonParseException {
            JsonArray items = element.getAsJsonArray();
            ParameterizedType deserializationCollectionType = ((ParameterizedType) type);
            Type collectionItemType = deserializationCollectionType.getActualTypeArguments()[0];
            Collection<E> list = null;
    
            try {
                list = (Collection<E>) ((Class<?>) deserializationCollectionType.getRawType()).newInstance();
                for (JsonElement e : items) {
                    list.add((E) context.deserialize(e, collectionItemType));
                }
            } catch (InstantiationException e) {
                throw new JsonParseException(e);
            } catch (IllegalAccessException e) {
                throw new JsonParseException(e);
            }
    
            return list;
        }
    }

    Жабоблядство и шаблоны и генерики:
    Чтение из json в коллекцию с шаблонным параметризованным типом.

    chtulhu, 23 Января 2014

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

    +155

    1. 1
    2. 2
    $(element).width($(element).width());
    $(element).height($(element).height());

    Просто нет слов.

    Diwms, 10 Января 2014

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

    +71

    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
    @Override
        List search(Long ownerId, Long projectId, String docnumber, String ctr1, String ctr2, Long dateFrom, Long dateTo, String contract,
                    Double amountFrom, Double amountTo, Double vatAmountFrom, Double vatAmountTo, Double withVatAmountFrom,
                    Double withVatAmountTo, Boolean defect, DocumentDefect d, Long vatId, Integer limit, String sortField, String order, String docType) {
    
            // доступные проекты
            List projects = projectDAO.findAll(ownerId)
            
            if(!projects){
                logger.warn("Ошибка отображения списка документов: нет доступных проектов: ownerId:$ownerId")
                return []
            }
            
            Criteria criteria = currentSession.createCriteria(DocumentView)
                .createAlias("document", "d")//
                .createAlias("d.project", "p")//
                .add(Restrictions.in("p.id", projects.id))//
    
    //            if(projectId)
    //                criteria.add(Restrictions.eq("d.project.id", projectId))
    
            if (docnumber)
                criteria.add(Restrictions.ilike("docNumber", docnumber, MatchMode.ANYWHERE))
            if (ctr1)
                criteria.add(Restrictions.ilike("supplierName", ctr1, MatchMode.ANYWHERE))
            if (ctr2)
                criteria.add(Restrictions.ilike("customerName", ctr2, MatchMode.ANYWHERE))
            if (dateFrom) {
                Calendar date1 = Calendar.instance
                date1.setTime(new Date(dateFrom))
                criteria.add(Restrictions.ge("docDate", date1))
            }
            if (dateTo) {
                Calendar date1 = Calendar.instance
                date1.setTime(new Date(dateTo))
                date1.add(Calendar.DAY_OF_MONTH, 1)
                criteria.add(Restrictions.lt("docDate", date1))
            }
            if (contract)
                criteria.add(Restrictions.ilike("contract", contract, MatchMode.ANYWHERE))
            if (amountFrom)
                criteria.add(Restrictions.ge("amount", amountFrom))
            if (amountTo)
                criteria.add(Restrictions.le("amount", amountTo))
            if (vatAmountFrom)
                criteria.add(Restrictions.ge("vatAmount", vatAmountFrom))
            if (vatAmountTo)
                criteria.add(Restrictions.le("vatAmount", vatAmountTo))
            if (withVatAmountFrom)
                criteria.add(Restrictions.ge("totalAmount", withVatAmountFrom))
            if (withVatAmountTo)
                criteria.add(Restrictions.le("totalAmount", withVatAmountTo))
            if (defect) {
                criteria.add(Restrictions.isNotNull("defect"))
                if (d)
                    criteria.add(Restrictions.eq("defect", d))
            }
    //        if (vatId)
    //            criteria.add(Restrictions.eq("d.", withVatAmountTo))
    
            if (docType) {
                def dt = DocumentType.values().find { it.link == docType || it.code == docType }
                if (dt)
                    criteria.add(Restrictions.like("docLink", dt.code, MatchMode.START))
                else
                    logger.error("Неправильное значение параметра фильтрации по виду документа [d_t:$docType]. Допустимые значения ${DocumentType.values().code}")
            }
    
            // получаем общее кол-во записей без ограничений по странице
            def rowCount = criteria.setProjection(Projections.rowCount()).uniqueResult() as Integer
    
            List result = criteria.setProjection(null)//
                    .setResultTransformer(Criteria.ROOT_ENTITY)//
                    .addOrder(Order."$order"(sortField))//
                    .setMaxResults(limit)//
                    .list()
    
            [rowCount, result]
    
        }

    поиск ?!

    floppy, 20 Декабря 2013

    Комментарии (23)
  5. Pascal / Говнокод #13842

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    Товарищи, я прошу всех посмотреть вот этот фильм:
    
    [запрос "Расскажите сказку, доктор!" на Яндекс]
    
    Возможно, это выглядит нелепо - постить ссылку сюда, но все же, сделайте это.
    
    Этот фильм был снят через несколько дней после войны. 
    На мой взгляд, имеет огромную воспитательную ценность.

    Stertor, 21 Сентября 2013

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    case WM_SIZE:
    			for(i=0;i<6;i++)
    			{
    				if(RegNotifyChangeKeyValue(hTopKeys[i],TRUE,REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_ATTRIBUTES|
    					REG_NOTIFY_CHANGE_LAST_SET|REG_NOTIFY_CHANGE_SECURITY,NULL,FALSE)==ERROR_SUCCESS)
    				{
    					MessageBox(NULL,"1","1",MB_OK);
    				}
    			}

    http://forum.shelek.ru/index.php/topic,14613.0.html

    Обратите внимание, товарищи, что у лица, создавшего сей шедевр, статус - "Опытный". Вот так и живем.

    Stertor, 30 Июля 2013

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

    +79

    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
    #include <iostream>
    #include <Windows.h>
    #include <iomanip>
    #include <string>
    #include <cctype>
    #include <sstream>
     
    using namespace std;
     
    void main()
    {
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
     stringstream ss;
     int counter = 0, vvod = 0;
     char str[9];
     cout << "Введите число - ";
     cin >> vvod;
     ss << vvod;
     ss >> str;
     for(int i = 0; i < strlen(str); i++)
     {
         counter++;
     }
     cout << counter << " разрядов." << endl;
     
    cout << "\n";
    system("PAUSE");
    }

    psina-from-ua, 28 Июля 2013

    Комментарии (23)
  8. Java / Говнокод #13278

    +69

    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
    static {
    	Unsafe u = null;
    	Exception ex = null;
    	try {
    		Class objectStreamClass = Class.forName("sun.misc.Unsafe");
    		Field unsafeField = objectStreamClass.getDeclaredField("theUnsafe");
    		unsafeField.setAccessible(true);
    		u = (Unsafe) unsafeField.get(null);
    	} catch (ClassNotFoundException e) {
    		ex = e;
    	} catch (SecurityException e) {
    		ex = e;
    	} catch (NoSuchFieldException e) {
    		ex = e;
    	} catch (IllegalArgumentException e) {
    		ex = e;
    	} catch (IllegalAccessException e) {
    		ex = e;
    	}
    	exception = ex;
    	unsafe = u;
    }

    xstream-1.2.2 - древнота, но попахивает...

    kostoprav, 01 Июля 2013

    Комментарии (23)
  9. Pascal / Говнокод #13258

    +142

    1. 1
    Язык Богов

    Stertor, 29 Июня 2013

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    public function parse_url($url)
    {
            return parse_url($url);
    }

    Модель из моего диплома... Всё по фен-шуй!

    nonamez, 28 Июня 2013

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

    +152

    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
    function Order(obj) {
      var frm = $(obj);
      var first_name = frm.find("input[name='first_name']").val();
      var last_name = frm.find("input[name='last_name']").val();
      var email = frm.find("input[name='email']").val();
      var phone = frm.find("input[name='phone']").val();
      var text = frm.find(".coment-form-textarea").val();
      var captcha = frm.find("input[name='captcha']").val();
    
      var valid = true;
      MsgErrorDestroy(frm, '#order-first_name', 'input[name="first_name"]');
      MsgErrorDestroy(frm, '#order-last_name', 'input[name="last_name"]');
      MsgErrorDestroy(frm, '#order-email', 'input[name="email"]');
      MsgErrorDestroy(frm, '#order-phone', 'input[name="phone"]');
      MsgErrorDestroy(frm, '#order-text', '.coment-form-textarea');
    
      if (first_name == '') {
        MsgError(frm, 'Введите ваше имя.', '#order-first_name', 'input[name="first_name"]');
        valid = false;
      }
      if (last_name == '') {
        MsgError(frm, 'Введите вашу фамилию.', '#order-last_name', 'input[name="last_name"]');
        valid = false;
      }
      if (!emailValid(email)) {
        MsgError(frm, 'Введите ваш email.', '#order-email', 'input[name="email"]');
        valid = false;
      }
      if (phone == '') {
        MsgError(frm, 'Введите ваш номер телефона.', '#order-phone', 'input[name="phone"]');
        valid = false;
      }
      if (text == '') {
        MsgError(frm, 'Введите ваше сообщение.', '#order-text', '.coment-form-textarea');
        valid = false;
      }
      if (captcha == '') {
        MsgError(frm, 'Введите капчу.', '#comment-capcha', 'input[name="captcha"]');
        valid = false;
      }
      if (valid == false) {
        return false;
      }
    }
    
    function MsgError(frm, msg, select_msg, select_input) {
      if (select_msg != 0) {frm.find(select_msg).html(msg);}
      if (select_input != 0) {frm.find(select_input).addClass('input-error');}
      if (select_msg != 0) {frm.find(select_msg).removeClass('hide');}
      //frm.find('#'+'profile-'+key).addClass('show');
    }
    function MsgErrorDestroy(frm, select_msg, select_input) {
      if (select_msg != 0) {frm.find(select_msg).html('');}
      if (select_input != 0) {frm.find(select_input).removeClass('input-error');}
      if (select_msg != 0) {frm.find(select_msg).removeClass('show');}
      //$('#'+'profile-'+key).addClass('hide');
    }

    Валидация какого-то там заказа. Автор вероятно не слышал про массивы и объекты.

    baldrs, 17 Июня 2013

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