1. Java / Говнокод #11571

    +75

    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
    private void viewField(int id) {
            try {
                List<Fieldmaterials> materials = materialsSession.FieldmaterialsBy(id);
                int size = materials.size() - 1;
                int i = 0;
                JSONWriter json = new JSONStringer().object();
                json.key("namefield").array();
    
                while (i <= size) {
                    Fieldmaterials get = materials.get(i);
                    json.value(get.getNamefield());
                    i++;
                }
                json.endArray();
                json.key("typefield").array();
    
                i = 0;
                while (i <= size) {
                    Fieldmaterials get = materials.get(i);
                    json.value(get.getTypefield());
                    i++;
                }
    
                json.endArray();
                json.key("orderfield").array();
    
                i = 0;
                while (i <= size) {
                    Fieldmaterials get = materials.get(i);
                    json.value(get.getOrderfieldmaterials());
                    i++;
                }
                json.endArray().endObject();
    
            } catch (Exception e) {
                e.printStackTrace();
            }

    Не нашел более хорошего способа сериализовать в JSON. Нужно было оформить поля объектов в массивы, что-бы потом удобно разобрать в javascript

    Kerny, 11 Августа 2012

    Комментарии (11)
  2. PHP / Говнокод #11570

    +52

    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
    $hash = md5($eshopId."::".
                            $orderId."::".
                    	    $_REQUEST["serviceName"]."::".
                            $_REQUEST["eshopAccount"]."::".
                            $_REQUEST["recipientAmount"]."::".
                			$_REQUEST["recipientCurrency"]."::".
                			$_REQUEST["paymentStatus"]."::".
                			$_REQUEST["userName"]."::".
                            $_REQUEST["userEmail"]."::".
                			$_REQUEST["paymentData"]."::".
                			$secretKey);
                if (strtoupper($_REQUEST["hash"]) != strtoupper($hash)) {
                    die('Err: wrong hash.');
                }
    ......

    я конечно уважаю modx но ето через чур
    http://bezumkin.ru/modx/minishop/extra/intellectmoney.html

    Sulik78, 11 Августа 2012

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

    +56

    1. 1
    $where = str_replace("post_status = 'publish'","post_status = 'publish' OR post_status = 'future' OR post_status = 'draft' OR post_status = 'inherit'", $where);

    Wordpress. Govnocode is poetry

    telnet, 10 Августа 2012

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

    +128

    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
    rotate n xs = b ++ a
        where n'     = n `mod` (length xs)
          (a, b) = splitAt ((length xs) - n') xs
    
    rotateAmount xs = _ra 0 ((length xs) - 1) (listArray (0, ((length xs) - 1)) xs)
        where _ra s e ys = if (e - s) == 1 
                           then (if ((ys ! s) &lt (ys ! e)) then s else e)  -- base case
                           else let h  = ys ! s                  -- first item
                                    l  = ys ! e                  -- last item
                                    mi = s + ((e - s) `div` 2)   -- middle index
                                    m  = ys ! mi                 -- middle item
                                in if (h &lt l)
                                   then s                        -- return start index
                                   else if (h &gt m)
                                        then _ra s  mi ys
                                        else _ra mi e  ys

    A “rotated array” is an array of integers in ascending order, after which for every element i, it has been moved to element (i + n) mod sizeOfList. Write a function that takes a rotated array and, in less-than-linear time, returns n (the amount of rotation). http://techguyinmidtown.com/2008/07/05/my-answers-to-the-microsoft-interview-questions

    FAKYOUINTIRNEAT, 10 Августа 2012

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

    +70

    1. 1
    $device->logicalDevices = $device->getLogicalDevices();

    ООП, такой ООП.

    travka, 10 Августа 2012

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

    +66

    1. 1
    2. 2
    3. 3
    4. 4
    $pr = array();
    foreach ($params as $k => $v)
        $pr[] .= urlencode($k).'='.urldecode($v);
    $data = join('&', $pr);

    http_build_query() для слабаков! Только велосипеды, только выстрел себе в ногу.
    /netcat/admin/nc_adminnotice.class.php

    telnet, 10 Августа 2012

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

    +138

    1. 1
    2. 2
    3. 3
    4. 4
    code = _factorCodeMax[factorUnid];
    code++;
    _factorCodeMax[factorUnid] = code;
    return code;

    Maps, 10 Августа 2012

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

    +23

    1. 1
    QHash<QByteArray, QSharedPointer<KeywordAnalyzerResult::Statistics> >::const_iterator i = res.result()->constBegin();

    Создание STL-style итератора для Qt-ных контейнеров обычно выглядит уродски.

    viktorious, 10 Августа 2012

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

    +58

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if (!$output) {
            $output = 'R0lGODlhMAAQAPUuALV7Z6p9ZkUiDkEhDIpMPSgcC2pAMFI9ibSEbZxpTP///7uJciodDTMkEYNVO7eCcpZfQJBeQ5xjRkIdCsaWgL2OdL';
            $output .= '6IbL2OcqJqRyweDj8qFXpOMy8fDyQYCC8gDUIqEiYaCraJbL2Lco9ePoBTNG1DKpxyXK2AbbN7Yqx2WjQlEoFTOW9FLCseDQAAAAAAAAA';
            $output .= 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C1hNUCBEYXRhWE1QRD94cDIzRThDRkQwQzcyIiB4';
            $output .= 'bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkU2RTVBQzAwMDFwYWNrZXQgZW5kPSJyIj8+ACH5BAUAAC4ALAAAAAAwABAAQAZkQJdwSCwaj';
            $output .= '8ik0uVpcQodUIuxrFqv2OwRoTgAFgdFQEsum8/ocit0oYgqKVVaG4EMCATBaDXv+/+AgYKDVS2GDR8aGQWESAEIAScmCwkJjUcSKA8GBh';
            $output .= 'YYJJdGLCUDEwICDhuEQQA7';
            $output = base64_decode($output);
    }

    Хранение картинки прямо в PHP коде.

    DropWorld, 09 Августа 2012

    Комментарии (18)
  10. Java / Говнокод #11562

    +72

    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
    private String getMessage(String prop, boolean suffixEnabled) {
            String title = null;
            if (prop.equals("headerTitle.suffix")) {
                try {
                    title = messageSource.getMessage("headerTitle.suffix", null, locale);
                } catch (NoSuchMessageException e) {
                    //e.printStackTrace();
                }
                if (title == null)
                    title = "";
            } else {
                try {
                    title = messageSource.getMessage(prop, null, locale);
                    if (suffixEnabled)
                        title += " " + messageSource.getMessage("headerTitle.suffix", null, locale);
                } catch (NoSuchMessageException e) {
                    //e.printStackTrace();
                }
                if (title == null) {
                    try {
                        title = messageSource.getMessage("headerTitle.default", null, locale);
                    } catch (NoSuchMessageException ex) {
                        title = "";
                    }
                }
    
            }
            return title;
        }

    welvet, 09 Августа 2012

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