1. 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)
  2. Куча / Говнокод #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)
  3. PHP / Говнокод #11567

    +70

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

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

    travka, 10 Августа 2012

    Комментарии (5)
  4. 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)
  5. C# / Говнокод #11565

    +138

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

    Maps, 10 Августа 2012

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

    +23

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

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

    viktorious, 10 Августа 2012

    Комментарии (14)
  7. 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)
  8. 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)
  9. PHP / Говнокод #11561

    +60

    1. 1
    2. 2
    3. 3
    4. 4
    $action = $_POST['action'];
    $function = "ajax_{$action}";
    if (!function_exists($function)) die("<b>Указанного действия не существует</b>");
    call_user_func($function);

    Что передали, то и выполнили.

    DropWorld, 09 Августа 2012

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    var priorities = Repository.Get<IIncidentPriority>().Query().OrderBy(x => x.Priority)
     .Select(x => new InputItem { Id = x.Id.ToString(CultureInfo.InvariantCulture), Value = x.LocalizationValue })
    .ToList();
    
    priorities.Add(new InputItem { Id = "-1", Value = Localizator.Get("X4.Incident.Undefined") });
    priorities.Reverse();

    тру хацкеры презирают метод Insert )

    tob1az, 09 Августа 2012

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