1. Си / Говнокод #17801

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int weeks_in_month(int month, int year){
        int weeks=1, first, i=0;  //i - числа месяца
        first = weekday(1, 1, 1, 1, 1, month, year);
        i += 8 - first;
        while(i <= days_in_month(month, year)){
            ++weeks;
            i += 7;
        }
        return weeks;
    }

    alobanov, 16 Марта 2015

    Комментарии (26)
  2. Си / Говнокод #17800

    +132

    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
    void calendar(int year){
        int i, j, k, frst=1, week, length, day = 0;
        printf("                               ");
        if(year < 1000) printf(" ");
        printf("%d\n\n", year);
        int first[3];   // число начала недели (первая неделя - любой день недели, следющие - понедельник)
        for(i = 1; i <= 4; ++i){
            print_tetral(i);
            first[1] = weekday(1, 1, 1, 1, 1, i*3-2, year);
            first[2] = weekday(1, 1, 1, 1, 1, i*3-1, year);
            first[3] = weekday(1, 1, 1, 1, 1, i*3, year);
            length = max(weeks_in_month(i*3-2, year), \
                         weeks_in_month(i*3-1, year), \
                         weeks_in_month(i*3, year));
            for(week = 0; week < length; ++week){
                for(j = 1; j <= 3; ++j){
                    frst = first[j];
                    if(week > 0) frst = 1;
                    if(week == 0)
                        for(k = 1; k < first[j]; ++k)
                            printf("   ");
                    k = frst;
                    day = 0;
                    while(k <= 7 && day < days_in_month(i*3-3+j, year) && week < weeks_in_month(i*3-3+j, year)){
                        day = 7*week + k - first[j] + 1;
                        if(day > days_in_month(i*3-3+j, year)) break;
                        if(day < 10) printf(" %d ", day);
                        else if(day >= 10) printf("%d ", day);
                        ++k;
                    }
                    if(week == length - 1 || day >= days_in_month(i*3-3+j, year))
                        for(; k <= 7; ++k)
                            printf("   ");
                    printf("  ");
                }
                printf("\n");
            }
            printf("\n");
        }
    }

    Печатаем календарь.

    alobanov, 16 Марта 2015

    Комментарии (2)
  3. Си / Говнокод #17799

    +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
    int days_in_month(int month, int year){
        if(month == 2){
            if(is_leap_year(year)) return 29;
            else return 28;
        }
        if(month < 8){
            if(month % 2 == 1) return 31;
            else return 30;
        }
        if(month > 7){
            if(month % 2 == 1) return 30;
            else return 31;
        }
        return 0;
    }

    Количество дней в месяце. Моя первая кучка. Не судите строго ^_^

    alobanov, 16 Марта 2015

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

    +128

    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
    HTML:
    <div id="calendar">
    		<div class="day">
    		<span class="num_job">5</span>
    			<span class="num_day">1</span>
    			<span class="name_day">пн</span>
    			<br/>
    			<span class="month">янв</span>
    			
    			
    			<span class="importance"></span>
    		</div>	
    		<div class="day">
    		<span class="num_job">12</span>
    			<span class="num_day">2</span>
    			<span class="name_day">вт</span>
    			<br/>
    			<span class="month">янв</span>
    			
    			
    			<span class="importance"></span>
    		</div>
    </div>
    CSS:
    body{
    	background: #ddd;
    	width: 1064px;
      margin: 0 auto;
    }
    #calendar{
    	width: 1064px;
    	margin: 0 auto;
    /*	height: 500px;*/
    display: inline-block;
    	background: #fff;
    }
    .day{
    	background: #f1f6f7;
    	border: 1px solid #dddbdb;
    	width: 130px;
    	height: 130px;
    	float: left;
    	margin: 10px;
    }
    .day:hover{
    	background: #6EB1BE;
    	cursor: pointer;
    }
    .day:hover .num_day, .day:hover .month, .day:hover .name_day{
    	color: #fff;
    }
    .day:hover .num_job{
    	color: #6EB1BE;
    	background: #fff;
    }
    
    .num_day{
    	font-family: Arial;
    	font-size: 72px;
    	font-weight: bold;
    	color: #1e99f7;	
    	position: relative;
    	top: -15px;
    	left: 15px;
    	letter-spacing: -6px;
    }
    .month, .name_day{
    	position: relative;
    	font-family: Arial;
    	font-size: 24px;
    	color: #1e99f7;	
    }
    .month{
    	top: -25px;
    	left: 37px;
    }
    
    .name_day{
      font-size: 11px;
      top: -12px;
      left: 15px;
    }
    .num_job{
    	background: #1e99f7;
    	color: #fff;
    	display: block;
    	width: 25px;
    	height: 25px;
    	line-height: 25px;
    	text-align: center;
    	border-radius: 100%;
    	font-family: Arial;
    	font-size: 17px;
    	font-weight: bold;
    	position: relative;
    	top: 5px;
    	left: 100px;
    }

    Вот я сверстал календарик. Подойдёт ли такой код для рабочего варианта? Что добавить? Что убрать? Как будет лучше?

    Simasik, 16 Марта 2015

    Комментарии (2)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)