1. C++ / Говнокод #17338

    +48

    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
    #include <iostream>
    
    #include "msg/messagehandler.h"
    #include "msg/messagedispatcher.h"
    
    #include "kukarek.h"
    #include "pocpocpoc.h"
    
    using namespace std;
    
    class Foo : public MessageHandler
    {
    public:
        Foo(MessageDispatcher* dispatcher):
            MessageHandler(dispatcher)
        {
            using namespace std::placeholders;
            subscribe<Kukarek>(bind(&Foo::kukarek, this, _1));
        }
    
        void foo()
        {
            sendMessage(PocPocPoc{5});
        }
    
        void kukarek(const Kukarek& k)
        {
            cout << "Foo Kukarek " << k.i << endl;
        }
    };
    
    class Bar : public MessageHandler
    {
    public:
        Bar(MessageDispatcher* dispatcher):
            MessageHandler(dispatcher)
        {
            using namespace std::placeholders;
            subscribe<PocPocPoc>(bind(&Bar::pocpocpoc, this, _1));
            subscribe<Kukarek>(bind(&Bar::kukarek, this, _1));
        }
    
        void bar()
        {
            sendMessage(Kukarek{42});
        }
    
        void kukarek(const Kukarek& k)
        {
            cout << "Bar Kukarek " << k.i << endl;
        }
    
        void pocpocpoc(const PocPocPoc& p)
        {
            cout << "Bar PocPocPoc " << p.j << endl;
        }
    };
    
    int main()
    {
        MessageDispatcher dispatcher;
        Foo f(&dispatcher);
        Bar b(&dispatcher);
        cout << "Hello World!" << endl;
        f.foo();
        b.bar();
        return 0;
    }

    Hello World!
    Bar PocPocPoc 5
    Foo Kukarek 42
    Bar Kukarek 42
    https://code.google.com/p/message-poc-poc-poc/

    DlangGovno, 18 Декабря 2014

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // В чем смысл переменной knc?
    var knc = 0;
    var k_fr = parent.document.getElementById(kph);
    if (k_fr) {
        knc = 1;
    }

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

    MrFranke, 18 Декабря 2014

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

    +164

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    var id;
    
    $(window).resize(function() {
      clearTimeout(id);
      id = setTimeout(doneResizing, 500);
    });
    
    function doneResizing(){
      window.location.reload();   
    }

    На странице элемент, у которого надо менять положение при ресайзе.

    AntonMMF, 18 Декабря 2014

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function json2array($json){
    	if(get_magic_quotes_gpc()){
    		$json = stripslashes($json);
    	}
    	$json = substr($json, 1, -1);
    	$json = str_replace(array(":", "{", "[", "}", "]"), array("=>", "array(", "array(", ")", ")"), $json);
    	@eval("\$json_array = array({$json});");
    	return $json_array;
    }

    Нашел в спамере ВК. Переводит JSON в массив

    Rakovskiy, 18 Декабря 2014

    Комментарии (7)
  5. Python / Говнокод #17333

    −111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    def parse(file):
        if 1==1: #вырвано из другого места, лень пробелы удалять
            if file:
                try:
                    doc = ET.parse(file)
                except IOError:
                    return HttpResponse(u'nofile')

    лол

    alexscrat, 18 Декабря 2014

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

    +134

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    if (String.Compare(GlobalSettings.EnvironmentType, "Production", StringComparison.OrdinalIgnoreCase) != 0
                        && !value.EndsWith(StgPostfix, StringComparison.OrdinalIgnoreCase))
                    {
                        namePostfix = value;
                    }
                    else
                    {
                        namePostfix = value;
                    }

    condition

    mzahor, 18 Декабря 2014

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

    +96

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static string RemoveWhitespace(this string input)
            {
                return input.ToCharArray()
                    .Where(c => !Char.IsWhiteSpace(c))
                    .Select(c => c.ToString(CultureInfo.InvariantCulture))
                    .Aggregate((a, b) => a + b);
            }

    RemoveWhitespace

    mzahor, 18 Декабря 2014

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function(loaded) {
        
        var sale=$("#markupz").val();
        var markup=$("#salez").val();
    		
         ...
    								
    });

    утонул в таком коде

    govnokoder2, 18 Декабря 2014

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

    +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
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            var alldir = Directory.GetDirectories(SearchIn.Text);
            foreach (var s in alldir)
            {
                if(s.Split('\\').Last().IndexOf(SearchFor.Text) != -1)
                {
                    string parent = Directory.GetParent(s).FullName;
                    string thisfolder = s.Split('\\').Last().Replace(SearchFor.Text, ReplaceTo.Text);
                    string fullpath = parent + "\\" + thisfolder;
                    Directory.Move(s, fullpath);
                }
            }
        }
    
        private void SearchIn_DoubleClick(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                SearchIn.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }

    Откопала свой хэллоу ворлд на шарпе.
    Что забавно, больше всего здесь меня удручают названия переменных и компонентов.

    pushistayapodmyshka, 18 Декабря 2014

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

    +133

    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
    public static T ElementAtReverse<T>(this IEnumerable<T> source, int index)
    {
        while (true)
        {
            var array = source as T[] ?? source.ToArray();
    
            var elementsCount = array.Count();
    
            if (index < elementsCount || elementsCount == 0)
                return array.ElementAt(elementsCount - 1 - index);
    
            source = array;
            index = index % elementsCount;
        }
    }

    pushistayapodmyshka, 18 Декабря 2014

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