1. JavaScript / Говнокод #17797

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $('#Leasing_payment_sum').keyup(function(){
        if($(this).val()/$(this).val()){
            var result = $(this).val()*1+$(this).val()*0.18;
            $('#Leasing_payment_sum_with_nds').val(result.toFixed(2));
        }
    });

    Удивляет проверка...

    creepy-code, 16 Марта 2015

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

    +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
    <?php
    // Код курильщика
       for ($i=1;$i<8;$i+=2){
       if($i==$row->ShipingTime) $result .="<option selected value='".$i."'>".$i."</option>";
       else $result .="<option value='".$i."'>".$i."</option>";
    
        if($i==7) {$i+=3;
         if($i==$row->ShipingTime) $result .="<option selected value='".$i."'>".$i."</option>";
         else $result .="<option value='".$i."'>".$i."</option>";
        }
        else {
         if($i==10) {
          $i+=4;
          if($i==$row->ShipingTime) $result .="<option selected value='".$i."'>".$i."</option>";
          else $result .="<option value='".$i."'>".$i."</option>";
         }
         else {
          for ($i=20;$i<45;$i+=10){
           if($i==$row->ShipingTime) $result .="<option selected value='".$i."'>".$i."</option>";
           else $result .="<option value='".$i."'>".$i."</option>";
           if($i==40){$i+=20;
            if($i==$row->ShipingTime) $result .="<option selected value='".$i."'>".$i."</option>";
            else $result .="<option value='".$i."'>".$i."</option>";
            $i+=30;
            if($i==$row->ShipingTime) $result .="<option selected value='".$i."'>".$i."</option>";
            else $result .="<option value='".$i."'>".$i."</option>";
           }
         }
        }
       }
    
    
    // Код здорового человека (провели рефакторинг)
    $ST_variants = array('1', '3', '5', '7', '10', '14', '20', '30' , '40', '60', '90');
    foreach ($ST_variants as $value) {
      print "<option ". ($value==$row->ShipingTime) ? 'selected' : '' ; ." value='".$value."'>".$value."</option>";
    }

    Заказчик хотел получить <select> со списком значений: '1', '3', '5', '7', '10', '14', '20', '30' , '40', '60', '90'...

    govnokoder2, 16 Марта 2015

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

    +58

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    unsigned long long int getSumUtil(unsigned long long int *st, unsigned long long int ss, unsigned long long int se, unsigned long long int qs, unsigned long long int qe, unsigned long long int index)
    
    //cout<<"here";
    
    //prunsigned long long intf("here");
    
    //printf("%llu\n%llu\n%c",i,j,type);

    По следам prunsigned intf из http://govnokod.ru/17791.
    http://www.codechef.com/viewplaintext/3039072
    Ctrl+H - наш ответ typedef!

    1024--, 16 Марта 2015

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

    −397

    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
    [array_static removeAllObjects];
    [array_static addObject:@"Files"];
    [array addObjectsFromArray:[filemanager contentsOfDirectoryAtPath:DOCUMENTS error:nil]];
    
    for (int l=0; l<array.count; l++) {
    	for (int j=0; j<array.count; j++) {
    		for (int i=0; i<array.count; i++) {
    			if ([[array objectAtIndex:i] rangeOfString:@"."].location != NSNotFound) {
    				[array removeObjectAtIndex:i];
    			}
    		}
    	}
    }
    
    for (int i = 0; i<array.count; i++) {
    	if (![array_static containsObject:[array objectAtIndex:i]]) {
    		[array_static addObject:[array objectAtIndex:i]];
    	}
    }

    Дали задание добавить фичу в один старый проект. Открыл проект, сижу и наслаждаюсь видом 8)

    OUrsus, 16 Марта 2015

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

    +158

    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
    eps=0.001;
    
    s1=new Source(1000,0.17);
    mx=new Mixer(1000);
    mb=new Mem(0.15,0.95);
    sp=new Splitter(0.80);
    s2=new Sink();
    s3=new Sink();
    
    mx.in1=s1.out1;
    mx.in2=sp.out2;
    mb.in1=mx.out1;
    sp.in1=mb.out2;
    s3.in1=sp.out1;
    s2.in1=mb.out1;
    
    for (i=0;i<50;i++){
        mx.calc();
        mb.calc();
        sp.calc();
    }
    
    function Stream(v,c){
        this.v=v||null;
        this.c=c||null;
        this.selfCheck=false;
        this.Show=function(){//how to add default values?
            return "volume="+this.v+",conc="+this.c+",selfCheck:"+this.selfCheck+"; ";
        }
    }
    
    function Source(v,c){
        this.out1=new Stream(v,c);
        this.calc=function(){};
    }
    function Sink(){
        this.in1=null;
        this.calc=function(){};
    }
    
    function Mixer(fixedV){
        this.fv=fixedV;
        this.in1=null;
        this.in2=null;
        this.out1=new Stream();
        this.calc=function(){
            this.out1.v=this.fv;//||this.in1.v+this.in2.v;
            this.in2.v=this.in2.v||0;
            this.in2.c=this.in2.c||0;
            this.in1.v=this.out1.v-this.in2.v;
            this.out1.c =(this.in1.v*this.in1.c+this.in2.v*this.in2.c)/this.out1.v;
            this.out1.selfCheck=Math.abs
            ((this.in1.v*this.in1.c+this.in2.v*this.in2.c)-(this.out1.v*this.out1.c))<eps;
        }
    }
    
    function Splitter(kS){
        this.in1=null;
        this.ks=kS||0.05;
        this.out1=new Stream();
        this.out2=new Stream();
        this.calc=function(){
            this.out1.v=this.in1.v*(1-this.ks);
            this.out2.v=this.in1.v*(this.ks);
            this.out1.c=this.in1.c;
            this.out2.c=this.in1.c;
        }
    
    }
    
    function Mem(kV,kC) {
        this.kv = kV||0.15;
        this.kc = kC||0.95;
        this.in1 = null;
        this.out1 = new Stream();
        this.out2 = new Stream();
        this.calc = function () {
            this.out1.v = this.in1.v * this.kv;
            this.out1.c = this.in1.c * (1 - this.kc);
            this.out2.v = this.in1.v * (1 - this.kv);
            this.out2.c = (this.in1.v * this.in1.c - this.out1.v * this.out1.c) / this.out2.v;
            this.out1.selfCheck = this.out2.selfCheck = Math.abs
            (this.in1.v * this.in1.c - (this.out1.v * this.out1.c + this.out2.v * this.out2.c)) < eps;
    
        }
    }

    xtfkpi, 16 Марта 2015

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

    −115

    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
    96. 96
    97. 97
    98. 98
    def _message_handler_thread(self):
            self._nick_change_failed = []
            while self.running:
                msg = self._message_queue.get(True)
                text = msg.get_data()
                conn = msg.get_connection()
                args = text.replace("\r", "").replace("\n", "").split(" ")
                command = args[0].upper()
                command_args = args[1:]
                if command == "NICK":
                    if len(command_args) < 1:
                        self._send_not_enough_parameters(conn, command)
                    else:
                        ident = self._clients[conn].identifier if self._clients[conn].identifier else None
                        if not self._set_nick(conn, command_args[0], ident):
                            self._nick_change_failed.append(conn)
                elif command == "USER":
                    if conn in self._clients:
                        if len(command_args) < 2:
                            self._send_not_enough_parameters(conn, command)
                        else:
                            ''''
                            self._send_lusers(conn)
                            self._clients[conn].real_name = command_args[:]
                            self._clients[conn].identifier = self._clients[conn].get_nick() + "!" + \
                                                                   command_args[0] + "@" + self.name
                            '''
                            self._set_nick(conn, command_args[0], command_args[1])
                            self._send_motd(conn)
                    else:  # Another way to identify is USER command.
                        if len(command_args) < 2:
                            self._send_not_enough_parameters(conn, command)
                        elif conn in self._nick_change_failed:
                            self._nick_change_failed.remove(conn)
                        else:
                            if self._set_nick(conn, command_args[0], command_args[1]):
                                self._clients[conn].identifier = self._clients[conn].get_nick() + "!" + \
                                    command_args[0] + "@" + self.name
                                self._send_motd(conn)
                elif command == "PRIVMSG" or command == "NOTICE":
                    if len(command_args) < 2:
                        self._send_not_enough_parameters(conn, command)
                    else:
                        message_text = command_args[1] if not command_args[1][0] == ":" else \
                            text.replace("\r\n", "")[text.index(":")+1:]
                        src = self._clients[conn].get_identifier()
                        dest = command_args[0]
                        if not dest.startswith("#"):
                            for clnt in self._clients.values():
                                if clnt.nick == dest:
                                    clnt.connection.send(
                                        ":%s %s %s :%s" % (src, command, dest, message_text)
                                    )
                                    break
                            else:
                                self._send_no_user(conn, dest)
                        else:
                            for chan in self._channels:
                                if chan.name == dest:
                                    self._channel_broadcast(conn, chan, ":%s %s %s :%s" %
                                                (src, command, dest, message_text))
                                    break
                            else:
                                self._send_no_user(conn, dest)
                elif command == "JOIN":
                    if len(command_args) < 1:
                        self._send_not_enough_parameters(conn, command)
                    elif not all(c in ALLOWED_CHANNEL for c in command_args[0]) and len(command_args[0]):
                        self._send_no_channel(conn, command_args[0])
                    else:
                        for chan in self._channels:
                            if chan.name == command_args[0]:
                                chan.users += 1
                                self._clients[conn].channels.append(chan)
                                self._send_to_related(conn, ":%s JOIN %s" % (self._clients[conn].get_identifier(),
                                                                             chan.name), True)
                                self._send_topic(conn, chan)
                                self._send_names(conn, chan)
                        else:
                            chan = Channel(command_args[0], 1)
                            chan.users = 1  # We have a user, because we have created it!
                            self._channels.append(chan)
                            self._clients[conn].channels.append(chan)
                            self._clients[conn].send(":%s JOIN %s" % (self._clients[conn].get_identifier(),
                                                       command_args[0]))
                elif command == "PART":
                    if len(command_args) < 1:
                        self._send_not_enough_parameters(conn, command)
                    else:
                        for chan in self._channels:
                            if chan.name == command_args[0]:
    
                                self._send_to_related(conn, ":%s PART %s" % (self._clients[conn].get_identifier(),
                                                                             command_args[0]))
                                self._clients[conn].channels.remove(chan)
                                chan.users -= 1
                                break
    ...

    Я писал сервер для IRC...
    Больше говнокода: https://github.com/SopaXorzTaker/irc-server/

    GoUseGitHub, 15 Марта 2015

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

    +57

    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
    #include <cstdio>
    #include <cstring>
    
    int main() {
        unsigned long long int a[100000];
        unsigned long long int N;
        unsigned long long int max,max1;
        unsigned long long int maxC,maxC1;
        unsigned long long int maxN[100000];
        unsigned long long int ans = 0;
        unsigned long long int ans1 = 0;
        max = max1 = maxC = maxC1 = 0;
        scanf("%llu",&N);
        for (unsigned long long int i = 0; i < N; ++i) {
            scanf("%llu",a + i);
            if (a[i] > a[max]) {
                max1 = max;
                maxC1 = maxC;
    //            memcpy(maxN,maxN1,maxC*sizeof(unsigned long long int));
                max = i;
                maxC = 1;
                maxN[0] = max;
            } else if (a[i] == a[max]) {
                maxN[maxC++] = i;
            } else if (a[i] > a[max1]) {
                max1 = i;
                maxC1 = 1;
            } else if (a[i] == a[max1]) {
                maxC1++;
            }
        }
        if (maxC == 1) {
            ans = a[max];
            if (a[max] == a[max1] + 1) {
                if (a[max] < (maxC1 + 1) * a[max1]) {
                    printf("%llu\n",a[max]);
                    return 0;
                }
            }
            if (max > 0) {
                if (a[max - 1] + 1 < ans - 1) {
                    if (a[max - 1] + 1 == a[max1]) {
                        if (a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0)) < ans) {
                            ans1 = a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0));
                            if (ans > ans1) ans = ans1;
    //                        prunsigned long long intf ("1 : %d\n",ans);
                        }
                    }
                    else { 
                        ans1 = a[max] - 1 + (a[max] - 1 == a[max1]?a[max1] * maxC1:0);
                        if (ans > ans1) ans = ans1;
    //                    prunsigned long long intf ("2 : %d\n",ans);
                    }
                }
            }
            if (max < N - 2) {
                if (a[max + 1] + 1 < ans - 1) {
                    if (a[max + 1] + 1 == a[max1]) {
                        if (a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0)) < ans) {
                            ans1 = a[max1] * (maxC1 + 1 + (a[max] - 1 == a[max1]?1:0));
                            if (ans > ans1) ans = ans1;
    //                        prunsigned long long intf ("3 : %d\n",ans);
                        }
                    }
                    else { 
                        ans1 = a[max] - 1 + (a[max] - 1 == a[max1]?a[max1] * maxC1:0);
                        if (ans > ans1) ans = ans1;
    //                    prunsigned long long intf ("4 : %d\n",ans);
                    }
                }
            }
            printf("%llu\n",ans);
            return 0;
        } // one max line
        bool f = true;
        bool f1 = true;
        if (a[max] * maxC > a[max] + 1) {
    //        prunsigned long long intf("here %d\n",maxC);
            for (unsigned long long int i = 0; i < maxC; ++i) {
                if (f1 && ((maxN[i] && a[maxN[i] - 1]) || (maxN[i] < N - 1 && a[maxN[i] + 1]))) f1 = false; // get from near line
                if (f && ((maxN[i] && a[maxN[i] - 1] < a[max] - 1) || (maxN[i] < N - 1 && a[maxN[i] + 1] < a[max] - 1))) f = false;
            }
        }
        ans1 = ans = maxC * a[max];
        
        if (!f && a[max] > 1) ans = (maxC - 1) * a[max];
        if (!f1) ans1 = a[max] + 1;
        printf("%llu\n",ans>ans1?ans1:ans);
        return 0;
    }

    Серега говнокодит задачу с OpenCup'a от 15.03.2015 (задача L - Бассейн счастья)

    kosta3ov, 15 Марта 2015

    Комментарии (26)
  8. Куча / Говнокод #17790

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    http://download.hdd.tomsk.ru/preview/wxjuxudv.jpg
    
    Защита от ботов 100500ого левела
    
    И что не так с этими вебпрограммистами?
    
    С сайта
    http://friends-online.co/eng/1-season/1-seria-1-season.html

    kegdan, 15 Марта 2015

    Комментарии (417)
  9. ActionScript / Говнокод #17789

    −95

    1. 1
    2. 2
    if (avoidFlickeringTimer.running);
        avoidFlickeringTimer.reset();

    чинили-чинили...

    wvxvw, 15 Марта 2015

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

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    for ($i=1;$i<=10;$i++) { 
    		  if(isset(${"imagenum".$i})) {
                         ....
                     }
    }

    И такое бывало

    sikamikanico, 15 Марта 2015

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