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

    +140

    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
    public static Thread RunInNewThread(Action<string[]> method, string[] args, ThreadPriority priority)
    {
                Thread thread = new Thread(() => method(args));
                thread.Name = method.Method.Name;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Priority = priority;
                thread.Start();
                return thread;
    }
    
    public static Thread RunInNewThread(Action<bool> method, bool args, ThreadPriority priority)
    {
                Thread thread = new Thread(() => method(args));
                thread.Name = method.Method.Name;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Priority = priority;
                thread.Start();
                return thread;
    }
    
    public static Thread RunInNewThread(Action<DateTime> method, DateTime date, ThreadPriority priority)
    {
                Thread thread = new Thread(() => method(date));
                thread.Name = method.Method.Name;
                thread.SetApartmentState(ApartmentState.STA);
                thread.Priority = priority;
                thread.Start();
                return thread;
    }

    Шикарно

    taburetka, 16 Августа 2013

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

    +83

    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
    typedef map<string,string> keys_map;
    ...
    const keys_map::const_iterator SectionData::operator[](int Index) const
    {                                                                     
            keys_map::const_iterator it=m_Keys.begin();                   
            int cnt=0;
            for(;it!=m_Keys.end(); it++)                                  
            {
                    if(cnt==Index)                                        
                            return it;                                    
                    cnt++;  
            }       
            return (keys_map::const_iterator)NULL;                        
    }
    ...
    SectionData section;
    keys_map::::const_iterator iter;
    for (i=0; i<section.GetSize(); i++) {
            iter = section[i];
            ...
    }

    правильный способ итерироваться по мапу

    gpr, 16 Августа 2013

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

    +138

    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
    Object.valuesNP = function(obj){
        var result = [];
        for (var i in obj)
            if (obj.hasOwnProperty(i))
                result.push(obj[i]);
        return result;
    };
    
    function findCSS(name){
        var css = document.styleSheets;
        var flag = false;
        var result = null;
        Object.valuesNP(css).each(function(content,index){
            if (!flag && content instanceof Object)
                Object.valuesNP(content.cssRules).each(function(content,index){
                    if (content instanceof Object && content.selectorText == name && !flag ){
                        flag = true;
                        result = content;
                    }
                })
            });
        return result;
    }

    Надо было поменять параметры некоторого класса(стиль). Ну и за пару минут было накидано вот енто.
    Самое смешное, что через неделю это уже не потребовалось.
    Вызывать так:
    var buttonClass = findCSS('.buttonClass') || console.log('CSS .buttonClass not found');

    Dart_Sergius, 16 Августа 2013

    Комментарии (4)
  4. PHP / Говнокод #13614

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if(isset($_POST['what']) && $_POST['what']=='form6' && isset($_POST['bot'])&& empty($_POST['bot']) && isset($_POST['fio']) && !empty($_POST['fio']) && isset($_POST['phone']) && !empty($_POST['phone'])){
    
    	$_POST['phone']=htmlspecialchars(stripslashes(trim($_POST['phone'])));
    	$_POST['fio']=htmlspecialchars(stripslashes(trim($_POST['fio'])));
    	
    	$message="Отправлено:\n".date("d.m.Y H:i")."\nОткуда: http://ipgeobase.ru/?address=".$_SERVER['REMOTE_ADDR']."\n\nФорма \"Заказ звонка\" \n\nИмя:\n".$_POST['fio']."\n\nТелефон:\n".$_POST['phone']."\n\nВперед!";
    	
    	mail ('[email protected]','заявка',$message, "Content-type: text/plain; charset=utf-8");

    Пиздец... За что?

    deep, 15 Августа 2013

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

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function showTimeToLive(doTranslation)
    {
        doTranslation = (doTranslation == undefined) ? true : doTranslation;
        ....
        timer = window.setTimeout (doTranslation ? "turnOff(true)" : "turnOff(false)", secs)
        ....
    }

    falsting, 15 Августа 2013

    Комментарии (1)
  6. Java / Говнокод #13611

    +130

    1. 1
    i=s.indexOf ("!") ;

    Смотрю с утра в код, а там жопа.

    KostylMaster, 15 Августа 2013

    Комментарии (39)
  7. Java / Говнокод #13610

    +119

    1. 1
    private static ControlledBlock uncontrolledBlock;

    Взаимоисключающие параграфы...

    someone, 15 Августа 2013

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    list($long_startIp, $long_endIp) = ip_range($value);
    $strange = long2ip($long_startIp);
    $endrange = long2ip($long_endIp);
    $addit[] = ('a.dst_ip BETWEEN ' . ip2long($strange) . ' AND ' . ip2long($endrange));

    Студенты нынче совсем тупые пошли.

    DrFreez, 15 Августа 2013

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    ....
    elseif(!strcasecmp(substr($value['type'],-4),'form'))
    {
          $class=$value['type']==='form' ? get_class($this->_form) : Yii::import($value['type']);
          $element=new $class($value,null,$this->_form);
    }
    ......

    В недрах Yii.
    Условие довольно странное ,этож надо было до этого додуматься

    xakki, 14 Августа 2013

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

    +138

    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
    <?php
    header("Content-Type: text/javascript;charset=utf-8");
     
    $html='';
    #$fp = fopen('counter.txt', 'w+');
     
    if (isset($_GET)) {
        $type=$_REQUEST['type'];
     
     
        if (isset ($_REQUEST['callback'])){
            $html.=$_REQUEST['callback']."(";
        }
     
        $fils=array('ukqs','uk','regions', 'org', 'citiesarhobl', 'cities', 'omsu', 'iogv','fund_uk','standart');
     
        if (isset($_GET['cfund_uk'])) {
            $fund_file='jbase/cities_'.$_GET['cfund_uk'].'.js';
            if (file_exists($fund_file))
                $html.=file_get_contents($fund_file);
            else
                $html.='error:'.$fund_file;
        }
        else
            if (isset($_GET['rfund_uk'])) {
                $fund_file='jbase/'.$_GET['rfund_uk'].'_regions.js';
                if (file_exists($fund_file))
                    $html.=file_get_contents($fund_file);
                else
                    $html.='error';
            }
        if (isset($_REQUEST['uks'])&&($type=='cities')) {
            $fund_file='jbase2/'.$_GET['uks'].'_cities.js';
            if (file_exists($fund_file))
                $html.=file_get_contents($fund_file);
            else
                $html.='error:'.$fund_file;
        }
        else
            if (isset($_REQUEST['uks'])&&($type=='regions')) {
                $fund_file='jbase2/'.$_GET['uks'].'_regions.js';
                if (file_exists($fund_file))
                    $html.=file_get_contents($fund_file);
                else
                    $html.='error';
            }
        else
            if ($type=='standart') {
                $fund_file='standart.js';
                if (file_exists($fund_file))
                    $html.=file_get_contents($fund_file);
                else
                    $html.='error';
            }
        else
        foreach ($fils as $ty)
            if ($ty==$type)
                $html.=file_get_contents($type.".js");    
        if (isset ($_REQUEST['callback']))
        {
            $html.=")";
        }
        #$date=date("F j, Y, g:i a");
       #$test = fwrite($fp, $date."#####\n\r ".$html);
     
        print $html;
        #fclose($fp);
    }
    ?>

    этот файл отдаёт json ajax ответ, подгружая его из *.js файла

    tariel, 14 Августа 2013

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