1. C# / Говнокод #11870

    +137

    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
    private string ExtractNodeValue(string text, string nodeName)
    {
        string result = string.Empty;
    
        int slength = ("<" + nodeName + ">").Length;
        int sindex = text.IndexOf("<" + nodeName + ">");
        int eindex = text.IndexOf("</" + nodeName + ">");
    
        if (sindex > 0 && eindex > 0)
            result = text.Substring(sindex + slength, eindex - sindex - slength);
    
        return result;
    }
    
    
    
    string request = string.Format("http://maps.google.com/maps/geo?ll={0},{1}&hl=en&output=xml&key=abcdefg", location.latitude, location.longitude);
    Logger.Log(request);
    HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(request);
    WebResponse responce = httprequest.GetResponse();
    Stream str = responce.GetResponseStream();
    XmlTextReader reader = new XmlTextReader(str);
    reader.XmlResolver = null;
    XmlDocument doc = new XmlDocument();
    doc.Load(reader);
    str.Close();
    reader.Close();
    
    XmlNodeList listResponse = doc.ChildNodes[1].ChildNodes[0].ChildNodes;
    foreach (XmlNode nodePlace in listResponse)
    {
        if (nodePlace.Name == "Placemark")
        {
            string text = nodePlace.InnerXml;
    
            string Country = ExtractNodeValue(text, "CountryName");
            if ((this.DataContext.Countries.Count(x => x.Name == location.countryName) == 0 || string.IsNullOrWhiteSpace(location.countryName)) &&
                !string.IsNullOrWhiteSpace(Country))
            {
                location.countryName = Country;
            }
    
            string Region = ExtractNodeValue(text, "AdministrativeAreaName");
            if (this.DataContext.States.Count(x => x.AlphaCode == location.region || x.Name == location.region) == 0 &&
                !string.IsNullOrWhiteSpace(Region))
            {
                location.region = Region;
            }
    
            string City = ExtractNodeValue(text, "LocalityName");
            if (this.DataContext.Cities.Count(x => x.Name == location.city) == 0 &&
                !string.IsNullOrWhiteSpace(City))
            {
                location.city = City;
            }
            break;
        }
    }

    отличный парсиг xml.

    mangyst, 04 Октября 2012

    Комментарии (2)
  2. JavaScript / Говнокод #11869

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function hideHint() {
        $(".popup_hint").each(function() {
           if($(this).attr("class")=="popup_hint") $(this).hide(); 
        });
    
        $(".popup_hint_or").each(function() {
           if($(this).attr("class")=="popup_hint_or") $(this).hide(); 
        });
    }

    Масло масляное.

    someuglymf, 04 Октября 2012

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

    +56

    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 function bugreportAction() {
            if (!isset($_POST['Type']) || !isset($_POST['Text']) || !isset($_POST['Module']))
                return false;
            if (trim($_POST['Text']) == "Ваш текст здесь...")
                return false;
            $rzt = $this->Debug->AddReport($_POST['Type'], $_POST['Text'], $_POST['Module']);
            if ($rzt)
                echo "OK";
            else
                echo "FAIL";
            return $rzt;
        }

    На работе нашел в проектах у других программистов, особенно понравилось.
    if (trim($_POST['Text']) == "Ваш текст здесь...")
    return false;

    Stud, 04 Октября 2012

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

    +28

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    std::string toString(std::function<std::string(T)> f = std::function<std::string(T)>()) {
       std::stringstream ss;
       if(f)
          ss << f(some_value);
       else
          ss << some_value;
       return ss.str();
    }

    an0nym, 03 Октября 2012

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

    +123

    1. 1
    2. 2
    fixed login dabl validation;
    dabl ajax zaproses;

    комментарий к коммиту

    crook, 03 Октября 2012

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

    +42

    1. 1
    2. 2
    3. 3
    4. 4
    objbase.h:
    
    #define __STRUCT__ struct
    #define interface __STRUCT__

    спасибо Микрософт за счастливое детство соответствие стандарту при засирании глобального неймспейса своими больными фантазиями

    defecate-plusplus, 03 Октября 2012

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

    +153

    1. 1
    2. 2
    3. 3
    <!--[if IE 6]><script>
    	var ____________ie6 = true;
    </script><![endif]-->

    Из кода страницы почтового ящика на mail.ru. И зачем было когда-то ругать себя за govnokod.ru/5573 - даже большие дядьки так делают, чё я!

    telnet, 03 Октября 2012

    Комментарии (4)
  8. JavaScript / Говнокод #11863

    +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
    /**
             *  Create table sorting
             **/
            var sotr=function(el,by){
                var trs=dialog.find('#file_list').find('tr')
                ,reverse=false;
                if(el.attr('reverse')=='true'){
                    el.removeAttr('reverse');
                    reverse=true;
                }else{
                    el.attr('reverse','true')
                }
                trs=trs.sort(function(a,b){
                    a=$(a);
                    b=$(b);
                    var i=0;
                    switch(by){
                        case 'by-name':
                            var txt1=$(a.find('td')[0]).text();
                            var txt2=$(b.find('td')[0]).text();
                            if ((txt1 < txt2)){
                                return reverse?1:-1;
                            }else if ((txt1 > txt2)&&!reverse){
                                return  reverse?-1:1;
                            }else{
                                return 0;
                            }
                            break;
                        case 'by-link':
                            if(reverse)
                                return $(a.find('td')[1]).text().length-$(b.find('td')[1]).text().length
                            else
                                return $(b.find('td')[1]).text().length-$(a.find('td')[1]).text().length
                            break;
                        case 'by-date':
                            var aDate=new Date(parseInt($(a.find('td')[2]).attr('data-date'))*1000)
                            ,bDate=new Date(parseInt($(b.find('td')[2]).attr('data-date'))*1000);
                                return (aDate>bDate)&&(reverse)?-1:1;
                            break;
                    }
                    
                });
                dialog.find('#file_list').find('tr').remove();
                trs.bind('click',function(e){
                    trClickListener.call(this,e);
                });
                trs.bind('dblclick',function(e){
                    trDBClickListener.call(this,e);
                });
                trs.appendTo(dialog.find('#file_list')).show(100);
                
            
            }

    хуита, 03 Октября 2012

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

    +130

    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
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Centering div content in 2012 using CSS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <style>
    
    /* align horizontally */
    .fu { width: 100%; text-align: center; }
    
    /* align vertically */
    @media all and (min-height:0px) { .fu { margin-top: 0px; }}
    @media all and (min-height:2px) { .fu { margin-top: 1px; }}
    @media all and (min-height:4px) { .fu { margin-top: 2px; }}
    @media all and (min-height:6px) { .fu { margin-top: 3px; }}
    @media all and (min-height:8px) { .fu { margin-top: 4px; }}
    @media all and (min-height:10px) { .fu { margin-top: 5px; }}
    @media all and (min-height:12px) { .fu { margin-top: 6px; }}
    @media all and (min-height:14px) { .fu { margin-top: 7px; }}
    @media all and (min-height:16px) { .fu { margin-top: 8px; }}
    @media all and (min-height:18px) { .fu { margin-top: 9px; }}
    @media all and (min-height:20px) { .fu { margin-top: 10px; }}
    @media all and (min-height:22px) { .fu { margin-top: 11px; }}
    .....
    .....
    .....
    @media all and (min-height:1994px) { .fu { margin-top: 997px; }}
    @media all and (min-height:1996px) { .fu { margin-top: 998px; }}
    @media all and (min-height:1998px) { .fu { margin-top: 999px; }}
    
    
    </style>
    </head>
    <body>
    <div class="fu">horizontally and vertically centered</div>
    </body>
    </html>​

    Центрируем содержимое дива по горизонтали и вертикали :) http://jsfiddle.net/ykrBh/

    makc3d, 02 Октября 2012

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

    +36

    1. 1
    printf("Aligment control: %d", sizeof(DataTransfer_T));

    LispGovno, 02 Октября 2012

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