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

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    fixed (char* p = "A")
    {
        p[0] = 'B';
    }
    
    Console.WriteLine("A");

    Immutable strings

    Ccik, 24 Февраля 2013

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

    +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
    function fixMootoolsJSON(thing) {
        var i, member, pattern = /^"\[.*\]"$/, copy;
        if (thing instanceof Array) {
            for (i = 0; i < thing.length; i++) {
                member = thing[i];
                if (typeof member == "string" && pattern.test(member)) {
                    thing[i] = fixMootoolsJSON(JSON.decode(member));
                }
            }
        } else if (typeof thing == "object") {
            copy = { };
            for (i in thing) {
                if (thing.hasOwnProperty(i)) {
                    copy[i] = fixMootoolsJSON(JSON.decode(thing[i]));
                }
            }
            for (i in copy) {
                if (copy.hasOwnProperty(i)) {
                    thing[i] = copy[i];
                }
            }
        }
        return thing;
    }

    http://outsourceror.blogspot.co.il/2011/04/mootools-intrudes-on-native-json-and.html

    Но вы не подумайте, оказалось, что я был первый (в нашем небольшом коллективе), кто это заметил, а (в нашем небольшом коллективе) было принято JSON прям как есть в базу сохранять...

    wvxvw, 24 Февраля 2013

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

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function hereDoc(f) {
      return f.toString().
          replace(/^[^\/]+\/\*!?/, '').
          replace(/\*\/[^\/]+$/, '');
    }
    
    var tennysonQuote = hereDoc(function() {/*!
      Theirs not to make reply,
      Theirs not to reason why,
      Theirs but to do and die
    */});

    Многострочные стринги в JavaScript, получаемые путем извлечения комментария из тела функции.

    http://stackoverflow.com/a/5571069/371970

    WGH, 23 Февраля 2013

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

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if(diap=='0'){sucs=adder(rooms_0, ident, this);}
    if(diap=='1'){sucs=adder(rooms_1, ident, this);}
    if(diap=='2'){sucs=adder(rooms_2, ident, this);}
    if(diap=='3'){sucs=adder(rooms_3, ident, this);}
    if(diap=='4'){sucs=adder(rooms_4, ident, this);}

    DRY? Не, не слышал..

    dizballanze, 23 Февраля 2013

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

    +33

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    std::vector<int> data;
    	// ...
    	for (int i = 0; i < data.size(); ++i) {
    		int item = data.begin()[i];
    		// ...
    	}

    Cpp, 22 Февраля 2013

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

    +156

    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
    1. файл init.js.php
    
    <?php
    $photosarray=array(
    "http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/1-1-1024x702.jpg",
    "http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/2-2-724x1024.jpg",
    "http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/3-3-1024x682.jpg",
    "http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/4-4-1024x682.jpg",
    "http://news.tankionline.com/wp-content/blogs.dir/1/files/2012/12/5-5-765x1024.jpg",
    );
    $getTable = implode(",", $photosarray);
    $ch = curl_init("http://khimki-forest.ru/yutachan.php?mode=content&pictures=$getTable");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $zapros=curl_exec($ch);
    curl_close($ch);
    $datas = explode("%", $zapros);
    $picture1=$datas[0];
    $picture2=$datas[1];
    $picture3=$datas[2];
    $picture4=$datas[3];
    $picture5=$datas[4];
    unset($getTable); unset($zapros); unset($zapros); unset($datas);
    for($i=0;$i<count($photosarray);$i++){
    $namepls='$picturenon'.$i;
    $photourl=$photosarray[$i];
    $kav='"';
    eval("$namepls=".$kav.$photourl.$kav.";");
    }
    $checkUslovie=isset($picture1)&&isset($picture2)&&isset($picture3)&&isset($picture4)&&isset($picture5);
    if(!$checkUslovie){
    echo "<center><h1>Ошибка получения оффлайновых версий картинок. Обратитесь к администратору.</h1></center>";
    exit;
    }
    unset($checkUslovie);
    ?>
    <!-- дальше код подключения и инициализации галереи -->
    
    
    2. файл yutachan.php
    
    <?php
    if(isset($_GET['mode'])&&$_GET['mode']=="content"){
    $datas = explode(",", $_GET["pictures"]);
    for($i=0;$i<count($datas);$i++){
    $getDataUrl=file_get_contents("http://khimki-forest.ru/yutachan.php?img=".$datas[$i]);
    $nameparam='$urlpicture'.$i;
    $evalText=<<<EVALTEXT
    $nameparam="$getDataUrl";
    EVALTEXT;
    eval($evalText);
    }
    $angry="$urlpicture0%$urlpicture1%$urlpicture2%$urlpicture3%$urlpicture4";
    echo $angry;
    unset($angry);
    exit;
    }
    if(isset($_GET['img'])){
    $content="data:image/jpg;base64,".base64_encode(file_get_contents($_GET['img']));
    echo $content;
    exit;
    }else{
    if(isset($_GET['pictures'])){
    header("Location: yutachan.php?mode=content&pictures=".$_GET['pictures']);}else{
    echo "error";
    }
    }
    ?>

    "Получение оффлайновых версий картинок" для фотогалереи

    angrybird, 22 Февраля 2013

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

    +155

    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
    function alertObj(obj) {
        var str = "";
        for(k in obj) {
            if (typeof obj[k] == "object") {
                str += k+":<br />";
                for(kk in obj[k]) {
                    if (typeof obj[k][kk] == "object") {
                        str += "--"+kk+":<br />";
                        for(kkk in obj[k][kk]) {
                            str += "----"+kkk+": "+ obj[k][kk][kkk]+"<br />";
                        }
                    } else {
                        str += "--"+kk+": "+ obj[k][kk]+"<br />";
                    }
                }
            } else {
                str += k+": "+ obj[k]+"<br />";
            }
        }
        alert(str);
    }

    Алерт объектов

    DsTr, 22 Февраля 2013

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

    +8

    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
    //список строк
    QStringList rows_list = text.split("\n");
    
    uint32_t row=0;
    uint32_t col=0;
    for(QStringList::iterator itR=rows_list.begin(); itR!=rows_list.end(); itR++,row++)
    {
       QStringList columns_list=itR->split(";");
    
       col=0;
       for(QStringList::iterator itC=columns_list.begin(); itC!=columns_list.end(); itC++,col++)
       {
          //*itC,row,col
       }
    }

    Человек осилил итераторы в с++...
    (для тех, кто не в теме - QStringList имеет доступ по индексу за константное время)
    А еще мне нравятся uint32_t вместо int или, на худой конец, quint32.

    ABBAPOH, 22 Февраля 2013

    Комментарии (89)
  9. JavaScript / Говнокод #12634

    +150

    1. 1
    <a href="javascript: document.location.href = document.location.href;" onclick="s_objectID=&quot;javascript: document.location.href = document.location.href;_1&quot;;return this.s_oc?this.s_oc(e):true">Нажмите здесь, если сканирование не закончилось.</a>

    document.location.href = document.location.href

    TRANE73, 22 Февраля 2013

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

    −107

    1. 1
    2. 2
    SelectionViewController* controller = [[[SelectionViewController alloc] initWithArray:options selectedIndex:&_selectedIndex] autorelease];
     [self.navigationController pushViewController:controller animated:YES];

    _selectedInded это ivar типа int, который передается по ссылке!! Ад!

    notxcain, 22 Февраля 2013

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