1. PHP / Говнокод #15991

    +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
    {php}
        $this->_tpl_vars['image_set'] = array();
        $this->_tpl_vars['json_string'] = "";
    {/php}
    
    {if $pcollection}
        {foreach name=pcollection key=picture_id item=picture from=$pcollection}
            {php}
                array_push($this->_tpl_vars['image_set'], "{$this->_tpl_vars['urlprefix']}/thumb.php?file=" . str_replace("thumbs","original","media/pictures/{$this->_tpl_vars['album']->getPath()}/{$this->_tpl_vars['picture']->getPath()}")."&size=245x143");
            {/php}
        {/foreach}
    {/if}
    
    {php}
        $this->_tpl_vars['json_string'] = json_encode($this->_tpl_vars['image_set']);
    {/php}
    {$json_string}

    получение объекта в smarty, потом пара фокусов, и вуаля, выплевываем json строку

    expert, 15 Мая 2014

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

    +69

    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
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    package com.javarush.test.level06.lesson11.bonus02;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
     
    /* Нужно добавить в программу новую функциональность
    Задача: У каждой кошки есть имя и кошка-мама. Создать класс, который бы описывал данную ситуацию. Создать два объекта: кошку-дочь и кошку-маму. Вывести их на экран.
    Новая задача: У каждой кошки есть имя, кошка-папа и кошка-мама. Изменить класс Cat так, чтобы он мог описать данную ситуацию.
    Создать 6 объектов: маму, папу, сына, дочь, бабушку(мамина мама) и дедушку(папин папа).
    Вывести их всех на экран в порядке: дедушка, бабушка, папа, мама, сын, дочь.
     
    Пример ввода:
    дедушка Вася
    бабушка Мурка
    папа Котофей
    мама Василиса
    сын Мурчик
    дочь Пушинка
     
    Пример вывода:
    Cat name is дедушка Вася, no mother, no father
    Cat name is бабушка Мурка, no mother, no father
    Cat name is папа Котофей, no mother, father is дедушка Вася
    Cat name is мама Василиса, mother is бабушка Мурка, no father
    Cat name is сын Мурчик, mother is мама Василиса, father is папа Котофей
    Cat name is дочь Пушинка, mother is мама Василиса, father is папа Котофей
    */
     
    public class Solution
    {
        public static void main(String[] args) throws IOException
        {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
     
            String grfatherName = reader.readLine();
            Cat catGrfather = new Cat(grfatherName);
     
            String grmotherName = reader.readLine();
            Cat catGrmother = new Cat(grmotherName);
     
            String fatherName = reader.readLine();
            Cat catFather = new Cat(fatherName, catGrfather, null);
     
            String motherName = reader.readLine();
            Cat catMother = new Cat(motherName, null, catGrmother);
     
            String sonName = reader.readLine();
            Cat catSon = new Cat(sonName, catFather, catMother);
     
            String daughterName = reader.readLine();
            Cat catDaughter = new Cat(daughterName, catFather, catMother);
     
            System.out.println(catGrfather);
            System.out.println(catGrmother);
            System.out.println(catFather);
            System.out.println(catMother);
            System.out.println(catSon);
            System.out.println(catDaughter);
     
        }
     
        public static class Cat
        {
            private String name;
            private Cat father;
            private Cat mother;
     
     
            Cat(String name)
            {
                this.name = name;
            }
     
            Cat (String name, Cat father, Cat mother){
                this.name = name;
                this.mother = mother;
                this.father = father;
     
            }
     
            @Override
            public String toString()
            {
                if ((mother == null) && (father == null))
                    return "Cat name is " + name + ", no mother, no father ";
                else if (father == null)
                    return "Cat name is " + name + ", mother is " + mother.name + " , no father";
                else if (mother == null)
                    return  "Cat name is " + name + ", no mather " + ", father is " + father.name;
                else
                    return "Cat name is " + name + ", mother is " + mother.name + ", father is " + father.name;
            }
        }
    }

    Да лаба, точнее задание. Но меня так умиляет решение задачи :) Просто немного хардкода :)

    kostoprav, 15 Мая 2014

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

    +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
    if ($.browser.msie && $.browser.version < 8) {
            $("div.banneritem:gt(0)").remove();
                    $("#viewnow").remove();
                    $("#morerealestates").css("margin-top", "-26px");
                    $("img[align=right]").css("float", "right");
       }
       else {
            setTimeout(function(){
                    slider();
            }, 0);
       }
           
            var got = $("div.banneritem:eq(0)").find("#preview").find("a").attr("href");;
            var timer = 7500;
            var anim = 750;
            function slider()
            {
                    setTimeout(function(){
                            do_slide(0);
                            setTimeout(function(){
                                    do_slide(1);
                                    setTimeout(function(){
                                            do_slide(2);
                                            setTimeout(function(){
                                                    do_slide(2, true);
                                                    setTimeout(function(){
                                                            do_slide(1, true);
                                                            setTimeout(function(){
                                                                    do_slide(0, true);
                                                                    slider();
                                                            }, timer);
                                                    }, timer);
                                            }, timer);
                                    }, timer);
                            }, timer);
                    }, timer);
            }
     
            function do_slide(v,rev)
            {
                    x = "div.banneritem:eq(" + v + ")";
                    if(rev==null)
                    {
                            $(x).slideUp(anim);
                            foo = $("div.banneritem:eq(" + (v+1) + ")").find("#preview").find("a").attr("href");
                    }else
                    {
                            $(x).slideDown(anim);
                            foo = $("div.banneritem:eq(" + (v-1) + ")").find("#preview").find("a").attr("href");
                    }
                   
                    if(foo!=null) got = foo;
                   
            }
           
            $("#viewnow").click(function(){
                    window.location=got;
            });

    Классика, слайдер на 3 елемента, с возавтом ;)

    expert, 15 Мая 2014

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

    +154

    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
    if($('.article-775-gallery')){
            $('.article-775-gallery').each(function(){
                get_images_by_building_gallery_id($(this).attr('id').replace(/gallery-/g,''));
            });
        }
    
        /* ************************************************************************************************************** */
    
        function get_building_details_by_property_id(id, size){
            $.get(urlprefix + "/ajax/nanar/" + id, function(data){
                var desc = jQuery.parseJSON(data);
                console.log(desc);
                if(desc.street && desc.zip && desc.town){
                    $('div[id="new-property-entry-id-' + id + '"] .house-item-head').html(desc.street + " <strong>" + desc.zip + " " + desc.town + " </strong>");
                    $('div[id="new-property-entry-id-' + id + '"] .house__item-descr').text(desc.description);
                    $('div[id="new-property-entry-id-' + id + '"] img').attr('src', desc.preview + size);
                    $('div[id="new-property-entry-id-' + id + '"] .verd').text(desc.verd);
                    $('div[id="new-property-entry-id-' + id + '"] .stard').text(desc.stard);
                    $('div[id="new-property-entry-id-' + id + '"] .tegund').text(desc.tegund);
                    $('div[id="new-property-entry-id-' + id + '"] .rooms').text(desc.rooms);
                    $('div[id="new-property-entry-id-' + id + '"]').slideDown();
                }
            });
        }
    
        if($('div[id^="new-property-entry-id-"]')){
            setTimeout(function(){
                $($('div[id^="new-property-entry-id-"]')).each(function(){
                    var size;
                    if($('div[id^="new-property-entry-id-"] div').hasClass('big-image')){
                        size = "180x140";
                        $('.new-property-entry-description').css('width','476px');
                        $('.time').css('display','block');
                    }else{size = "322x157";}
                    get_building_details_by_property_id($(this).attr('id').replace(/new-property-entry-id-/g,''), size);
                });
            },500);
        }

    код творит чудеса :), я его побоялся трогать.... знаю что функция на 9 строчке, это некое подобие шаблонизатора

    expert, 15 Мая 2014

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

    +154

    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
    $('.order-form-popup form').on('submit', function (e) {
    			e.preventDefault();
    			var data = $(this).serializeArray(),
    				mainProfilesList = '',
    				fillingsList = '';
    
    			$('.field-name-field-eo-main-profiles .field-item').each(function () {
    				mainProfilesList += ('<li>' + ($(this).text()) + '</li>');
    			});
    
    			$('.field-name-field-eo-fillings .field-item').each(function () {
    				fillingsList += ('<li>' + ($(this).text()) + '</li>');
    			});
    
    			data.push({
    				name: 'profiles',
    				value: '<ul>' + mainProfilesList + '</ul>'
    			});
    
    			data.push({
    				name: 'fillings',
    				value: '<ul>' + fillingsList + '</ul>'
    			});
    
    			data.push({
    				name: 'number',
    				value: $('.field-name-field-eo-product-number .field-item').text()
    			});
    
    			data.push({
    				name: 'qty',
    				value: $('#qty-input').val()
    			});
    
    			data.push({
    				name: 'area',
    				value: $('.field-name-field-eo-area .field-item').text()
    			});
    
    			data.push({
    				name: 'price',
    				value: $('.field-name-field-eo-price-without-discount .field-item').text()
    			});
    
    			$.ajax({
    				url: location.protocol + '//' + location.hostname + '/send-message.php',
    				type: 'POST',
    				data: data,
    				success: function (data, textStatus) {
    					var msg = '<h3 id="order-form-popup-msg" style="text-align: center; margin-top: 50%;">Заявка успешно отправлена.<br /> Спасибо!</h3>'
    					$('.order-form-popup form, .order-form-popup-title').hide();
    					$('.order-form-popup').append(msg);
    					window.setTimeout(function () {
    						$('.order-form-popup, .order-form-overlay').fadeOut(500);
    						$('#order-form-popup-msg').remove();
    						$('.order-form-popup form, .order-form-popup-title').show();
    					}, 3500);
    				},
    				error: function (jqXHR, textStatus, errorThrown) {
    					//for debugging
    				}
    			});
    		});

    Сериализация данных из полей, находящихся вне формы.

    DrDre, 15 Мая 2014

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

    +154

    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
    Ext.define('Block', {
        config: {
            title: 'default',
            desc: 'default'
        },
        constructor: function (config) {
            this.initConfig(config);
        },
        tpl: new Ext.Template( '<div class="block">\
                                <div class="close">×</div>\
                                <div class="wrapper">\
                                <h3 class="title">{0}</h3>\
                                <p class="desc">{1}</p>\
                                </div>\
                                </div>'),
        create: function(){
            var div = new Ext.dom.Element(document.createElement('div')),
                html = this.tpl.apply([
                    this.title,
                    this.desc
                ]);
            div.setHTML(html);
            return div.first();
        }
    });
    
    var form = Ext.get('form'),
        blocks = Ext.get('blocks');
    
    form.addListener('submit', function(e, me){
        e.preventDefault();
    
        var title = me.elements.title.value,
            desc = me.elements.desc.value,
            blockInstance = Ext.create('Block');
    
        blockInstance.setTitle(title);
        blockInstance.setDesc(desc);
    
        var blockElement = blockInstance.create();
        blocks.appendChild(blockElement);
        blockElement.select('.close').addListener('click', function(){
            blockElement.remove();
        });
        me.reset();
    });

    Реализация минимального todo app на ExtJS. Переписывалась с чистого js ради эксперимента.

    DrDre, 15 Мая 2014

    Комментарии (1)
  7. PHP / Говнокод #15985

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function c(){
      //Внимание! Далее идёт индусский код! Слабонервных попрошу уда(л|в)иться...
      require ('config.php');
     $included = get_included_files();
      if(!in_array('config.php',$included)){
       Error(404);
       return;
      }
     ...
     ...
    }

    Стиль и коммент оставил оригинальные, видимо ЭТО кому-то из наших уже попадало до меня.
    Далее код - в натуре полный "хадж".

    virtual_cia, 15 Мая 2014

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

    +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
    if('false' == 'true') {
        var anm= '';
        anm = anm.split(",");
        var rd = jQuery(this).jqGrid('getRowData', id);
        if(rd) {
            for(var i=0; i<anm.length; i++) {
                if(rd[anm[i]]) {
                    data[anm[i]] = rd[anm[i]];
                }
            }
        }
    }

    Somnio, 14 Мая 2014

    Комментарии (8)
  9. Си / Говнокод #15983

    +131

    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
    #include <stdio.h>
    #include <tchar.h>
    
    #define MVALUE 6
    
    
    void bufret(int pos, int limit, int maxlimit, bool direction)
    {
    	putchar((char)((pos&0xff)+0x30)) ;
    	if(((pos<limit)&&direction)||((pos>1)&&(!direction)))
    	{   
         putchar('-') ;
    	 if(direction)
    		 pos++ ;
    	 else 
    		 pos--;
    	}    
    	else
    	{
          limit++ ;   
          if(direction)
    		pos=limit;
    	  else
    	    pos=1 ;
    	    direction=!direction ;
    	 
    		putchar('\n') ;
    	}
    	if(limit < maxlimit)
    		bufret(pos,limit,maxlimit,direction) ;
    
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	 bufret(1, 1, MVALUE+1, true) ;
    	 getchar() ;
    	return 0;
    }

    Решил наговнокодить по мотивам этой статьи:
    http://habrahabr.ru/post/116842/

    Как думаете, получилось,

    ASDASD, 14 Мая 2014

    Комментарии (14)
  10. Pascal / Говнокод #15982

    +89

    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
    var
      Form1: TForm1;
      i:integer; // глобальные переменные - "общие"
      CritSec:TCriticalSection; // объект критической секции
    implementation
    
    {$R *.dfm}
    
    procedure ThreadFunc;
    begin
    while (i<100000) do
      begin
      CritSec.Enter; // открываем секцию
      i:=i+1; //увеличиваем i
      Form1.Label1.Caption:=IntToStr(i); //из потока к элементам формы нужно обращаться через имя формы
      CritSec.Leave; // закрываем
      end;
    
    endthread(0); // красиво выходим из потока.
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var tid1,tid2,id:longword;
    begin
    i:=0;
    tid1:=beginthread(nil,0,Addr(ThreadFunc),nil,0,id); //запускаем функцию ThreadFunc в потоке
    tid2:=beginthread(nil,0,Addr(ThreadFunc),nil,0,id); //в tid2 присваиваем Идентификатор потока, который пригодится позже.
    end;
    
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    CritSec:=TCriticalSection.Create; // создаём объект критической секции, на всё время работы программы
    end;
    
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
    CritSec.Free; // разрушаем
    end;
    
    end.

    Уебище, блять, лесное.
    http://grabberz.com/showthread.php?t=24619

    brutushafens, 14 Мая 2014

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