1. Лучший говнокод

    В номинации:
    За время:
  2. JavaScript / Говнокод #12807

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $.post("include/show_watching.php",
        function(data) {
            $('#content').empty().append(data);
        }
    );

    Вот такой вот POST-запрос.

    Stallman, 26 Марта 2013

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

    +156

    1. 1
    2. 2
    if( SITE == 'http://dev.example.com' ) die( file_get_contents( 'http://www.example.com/error.php?error=xml' ) );
    die( file_get_contents( SITE.'/error.php?error=xml' ) );

    некоторые 404-ую выводят вот так

    dead_star, 22 Марта 2013

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function postGameOrder(option) {
        // 48 cтрок кода
            if (option == 1) {
                if (!confirm("Are you sure you want to save this configuration?")) {
                    return false;
                }
            }
        // 45 строк кода
    }

    P.S. Умолчу уже о том, что среди тех 48 и 45 строк кода происходит обращение к глобальным переменным.
    На публикацию же вдохновило то, что вот это обращение к option — единственное во всей функции.

    wissenstein, 22 Декабря 2012

    Комментарии (0)
  6. JavaScript / Говнокод #12277

    +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
    this.start = function() {
    		// Инициализирует парсинг выгрузки из Агента Плюс.
    		if (this.open()) {
    			this.catalogs = this.getTags("catalogs", true)[0].childs;
    			this.subdocuments = this.getTags("documents", true)[1].childs;
    			this.guids = this.document.childs[0].childs[0].childs;
    			this.sellhistory = this.getCatalog("ИсторияПродаж").childs[0].childs;
    			this.sellpoints = this.getCatalog("ТорговыеТочки").childs[0].childs;
    			this.contragents = this.getCatalog("Контрагенты").childs[1].childs;
    			this.deals = this.getCatalog("Договоры").childs[0].childs;
    			this.nomenclature = this.getCatalog("Номенклатура").childs;
    			this.measure = this.getCatalog("ЕдиницыИзмерения").childs[0].childs;
    			this.route = this.getDocument("Маршрут").childs[0].childs[0].childs[0].childs[0]
    			this.names = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
    			this.info = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
    			this.hash = {deals: {}, nomenclature: {}, consts: {}, contragents: {}, sellpoints: [], measure: {}};
    			for (var i = 0; i < this.catalogs.length; i++) {
    				this.names.catalog.push(this.catalogs[i].attrib.Comment.replace(/Справочник\./g, ""));
    				this.info.catalog.push(this.catalogs[i].attrib);
    			}
    			for (var i = 0; i < this.nomenclature[1].childs.length; i++) {
    				this.names.nomenclature.push(this.nomenclature[1].childs[i].attrib.Name);
    				this.info.nomenclature.push(this.nomenclature[1].childs[i].attrib);
    				this.hash.nomenclature[this.nomenclature[1].childs[i].attrib.GUID] = this.nomenclature[1].childs[i].attrib;
    			}
    			for (var i = 0; i < this.deals.length; i++) {
    				this.names.deals.push(this.deals[i].attrib.Name);
    				this.info.deals.push(this.deals[i].attrib);
    				this.hash.deals[this.deals[i].attrib.GUID] = this.deals[i].attrib;
    			}
    			for (var i = 0; i < this.measure.length; i++) {
    				this.names.measure.push(this.measure[i].attrib.Name);
    				this.info.measure.push(this.measure[i].attrib);
    				this.hash.measure[this.measure[i].attrib.GUID] = this.measure[i].attrib;
    			}
    			for (var i = 0; i < this.contragents.length; i++) {
    				this.names.contragents.push(this.contragents[i].attrib.Name);
    				this.info.contragents.push(this.contragents[i].attrib);
    				this.hash.contragents[this.contragents[i].attrib.GUID] = this.contragents[i].attrib;
    			}
    			for (var i = 0; i < this.sellpoints.length; i++) {
    				this.names.sellpoints.push(this.sellpoints[i].attrib.Name);
    				this.info.sellpoints.push(this.sellpoints[i].attrib);
    				this.hash.sellpoints[this.sellpoints[i].attrib.GUID] = this.sellpoints[i].attrib;
    			}
    			for (var i = 0; i < this.guids.length; i++) {
    				this.hash.consts[this.guids[i].attrib.GUID] = this.guids[i].attrib.VALUE;
    			}
    			
    			this.dynamic.routes = new Array();
    			for (var i = 0; i < this.route.childs.length; i++) {
    				var sp = this.getSPointByGUID(this.route.childs[i].attrib.A02);
    				var adr = sp.Name;
    				var ca = this.getCAgentByGUID(this.route.childs[i].attrib.A01);
    				var ptypeguid = this.hash.deals[ca.A08].A06;
    				var cagent = ca.Name;
    				var dealguid = ca.A08;
    				var exists = false;
    				for (var j = 0; j < this.dynamic.routes.length; j++) if (this.dynamic.routes[j].address.trim().toLowerCase() == adr.trim().toLowerCase()) exists = exists || true;
    				if (!exists) this.dynamic.routes.push({ptypeguid: ptypeguid, spointguid: sp.GUID, address: adr, dealguid: dealguid, cagent: cagent, cagentguid: ca.GUID, datestamp: this.convRouteDate(this.route.childs[i].attrib.A03)});
    			}
    		} else return;
    	};

    Маленькая часть нашего скрипта для работы с 1С - Node.JS - WebClient.

    Govnisti_Diavol, 12 Декабря 2012

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

    +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
    function ValidatePhone(strphone)
    {
        for(j=0;j<strphone.length;j++)
        {
        var cut;
        cut=strphone.charAt(  j )
        if(cut!=0&&cut!=1&&cut!=2&&cut!=3&&cut!=4&&cut!=5&&cut!=6&&cut!=7&&cut!=8&&cut!=9&&cut!="("&&cut!=")"&&cut!=".")
          return false;
     
        } 
        return true;
    }

    классика

    bytes, 16 Октября 2012

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    getControlValues : function(isSimpleValue){
        return this._getControlData(function(tab){
            return tab.getControlValues(isSimpleValue);
        });
    }

    Образец "самодокументируемого кода"
    Маленький метод, но как много в нем загадок.

    jangot, 10 Октября 2012

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

    +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
    function isProperty(object, property) {
        "use strict";
        var p, names, original = object,
            ecmaTypes = [Object, Array, String, Number, Date];
        try {
            for (p = 0; p < ecmaTypes.length; p += 1) {
                if (ecmaTypes[p] == object) {
                    console.log("looking up: " + ecmaTypes[p]);
                    names = Object.getOwnPropertyNames(ecmaTypes[p]);
                    if ('prototype' in ecmaTypes[p]) {
                        names = names.concat(
                            Object.getOwnPropertyNames(
                                ecmaTypes[p].prototype));
                    }
                    break;
                }
            }
            do {
                object = object.prototype.__proto__.constructor;
                names = names ?
                    names.concat(Object.getOwnPropertyNames(object)) : [];
                if ('prototype' in object) {
                    names = names.concat(
                        Object.getOwnPropertyNames(object.prototype))
                }
            } while  (object != Object)
            if (!names) {
                names = Object.getOwnPropertyNames(object);
            }
        } catch (error) {
            for (p in object) {
                if (object[p] == property) {
                    return true;
                }
            }
            return false
        }
        for (p = 0; p < names.length; p += 1) {
            if (original[names[p]] == property ||
                original.prototype[names[p]] == property) {
                return true;
            }
        }
        return false;
    }

    А как еще узнать, является ли функция методом принадлежащим объекту или нет? Это еще после трех часов проведенных в муках пытаясь понять, что вообще происходит.

    wvxvw, 10 Октября 2012

    Комментарии (27)
  10. JavaScript / Говнокод #11778

    +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
    @show[]
    $cars[^table::sql{select * from count_cars order by sortir}]
    <script>
    var CarsDescription = new Array()^;
    $counter(1)
    ^cars.menu{
    CarsDescription[$counter] = '$cars.characteristic'^;
     ^counter.inc[]
    }
    </script> 
    <script type="text/javascript" src="/cars_calc/script.js"></script>
    <link rel="stylesheet" type="text/css" href="/cars_calc/style.css">
    <section class="page">
       <section class="scheme">
        <span id="cr" class="cr"></span>
            $cars_count(16)      
            ^for[car](1;$cars_count){ 
        <span id="select-car-$carId" class="car-$carId">$car</span>
            }
     </section>

    Код из одной веб-студии. Смысл в том что в javascript должен быть передан массив из базы данных, вместо того чтобы послать пакет с нужными данными в формате json (или любом другом) и обработать его, в исходный файл html-разметки (тут как видно и javascript вставлен) добавили код Parser'а (для тех кто-незнаком это язык для быстрой разработки веб-сайтов от Лебедева, что-то вроде простой альтернативы php), который перед тем как отдать пользователю страницу, обрабатывает её и вставляет в нужные места, нужные данные. В общем сами оценивайте этот маразм...

    Kerny, 16 Сентября 2012

    Комментарии (35)
  11. JavaScript / Говнокод #11654

    +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
    var Utils = {
      // https://gist.github.com/1308368
      uuid: function(a,b){for(b=a='';a++<36;b+=a*51&52?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):'-');return b},
      pluralize: function( count, word ) {
       return count === 1 ? word : word + 's';
      },
      store: function( namespace, data ) {
       if ( arguments.length > 1 ) {
        return localStorage.setItem( namespace, JSON.stringify( data ) );
       } else {
        var store = localStorage.getItem( namespace );
        return ( store && JSON.parse( store ) ) || [];
       }
      }
     };

    kyzi007, 27 Августа 2012

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