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

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

    −109

    1. 1
    2. 2
    3. 3
    4. 4
    def remove_duplicates(seq):
        seen = set()
        seen_add = seen.add
        return [x for x in seq if x not in seen and not seen_add(x)]

    замечательная функция, возвращающая уникальные элементы списка.

    python_ninja, 16 Февраля 2015

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

    +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
    function display_form($value){
    		switch($value){
    			case "page_title":
    				return "<input type='text' id='page_title' name='settings[page_title]' value='".$this->values[$value]."'/>";
    			break;
    			case "admin_email":
    				return "<input type='text' id='admin_email' name='settings[admin_email]' value='".$this->values[$value]."'/>";
    			break;
    			case "max_rental":
    				return "<input type='text' id='max_rental' name='settings[max_rental]' value='".$this->values[$value]."'/>";
    			break;
    			case "offset":
    				return "<input type='text' id='offset' name='settings[offset]' value='".$this->values[$value]."'/>";
    			break;
    			case "launch_limit":
    				return "<input type='text' id='offset' name='settings[launch_limit]' value='".$this->values[$value]."'/>";
    			break;
    			
    			case "page_text":
    				return "<textarea id='page_text' class='ckeditor' name='settings[page_text]'>".$this->values[$value]."</textarea>";
    			break;
    			
    			case "email_text":
    				return "<textarea id='page_text' class='ckeditor' name='settings[email_text]'>".$this->values[$value]."</textarea>";
    			break;
    			
    			case "confirm_message":
    				return "<textarea id='page_text' class='ckeditor' name='settings[confirm_message]'>".$this->values[$value]."</textarea>";
    			break;
    			
    			case "general_hours":
    				$hours = unserialize($this->values[$value]);
    				return "
    					<table id='hours'>
    					<tr><th></th>
    						<th>Sunday</th>
    						<th>Monday</th>
    						<th>Tuesday</th>
    						<th>Wednesday</th>
    						<th>Thursday</th>
    						<th>Friday</th>
    						<th>Saturday</th>
    					</tr>
    					<tr>
    						<th>Open</th>
    						<td>".$this->display_hour_options("Sunday","start",$hours['Sunday']['start'])."</td>
    						<td>".$this->display_hour_options("Monday","start",$hours['Monday']['start'])."</td>
    						<td>".$this->display_hour_options("Tuesday","start",$hours['Tuesday']['start'])."</td>
    						<td>".$this->display_hour_options("Wednesday","start",$hours['Wednesday']['start'])."</td>
    						<td>".$this->display_hour_options("Thursday","start",$hours['Thursday']['start'])."</td>
    						<td>".$this->display_hour_options("Friday","start",$hours['Friday']['start'])."</td>
    						<td>".$this->display_hour_options("Saturday","start",$hours['Sunday']['start'])."</td>
    					</tr>
    					<tr>
    						<th>Close</th>
    						<td>".$this->display_hour_options("Sunday","end",$hours['Sunday']['end'])."</td>
    						<td>".$this->display_hour_options("Monday","end",$hours['Monday']['end'])."</td>
    						<td>".$this->display_hour_options("Tuesday","end",$hours['Tuesday']['end'])."</td>
    						<td>".$this->display_hour_options("Wednesday","end",$hours['Wednesday']['end'])."</td>
    						<td>".$this->display_hour_options("Thursday","end",$hours['Thursday']['end'])."</td>
    						<td>".$this->display_hour_options("Friday","end",$hours['Friday']['end'])."</td>
    						<td>".$this->display_hour_options("Saturday","end",$hours['Saturday']['end'])."</td>
    					</tr>
    					</table>
    				";
    			break;
    			
    			case "interests":
    				$interests = unserialize($this->values[$value]);
    				return "<strong>Display:</strong> <br /><input type='text' name='settings[interests][display]' value='".$interests['display']."'/><br />
    						<strong>Options: </strong><small>(Seperated by \"|\")</small> <br /><textarea id='page_title' name='settings[interests][choices]'>".implode("|",$interests['choices'])."</textarea>";
    			break;
    			
    			case "occasions":
    				$occasions = unserialize($this->values[$value]);
    				return "<strong>Display:</strong> <br /><input type='text' name='settings[occasions][display]' value='".$occasions['display']."'/><br />
    						<strong>Options: </strong><small>(Seperated by \"|\")</small> <br /><textarea id='page_title' name='settings[occasions][choices]'>".implode("|",$occasions['choices'])."</textarea>";
    			break;
    		}
    	}

    ActiveForm на все случаи жизни

    dejust, 15 Февраля 2015

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

    +125

    1. 1
    2. 2
    3. 3
    Console.WriteLine("Say my name");
               Console.ReadLine();
               Console.WriteLine("Yes, damn right!");

    Worldoorboll, 13 Февраля 2015

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

    +161

    1. 1
    this.$items = this.$items.last().add(this.$items.not(this.$items.last()));

    this.$items – jQuery многоножка

    fake, 10 Февраля 2015

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function StrToFloat($str) {
        if (strstr($str, ',')) {
            $i = explode(',', $str);
            $str = implode('.', $i);
            settype($str, 'float');
        }
        return $str;
    }

    kissarat, 09 Февраля 2015

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

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function resort($a){
        $res=mysql_query("select * from image where id_gal='".$a."' order by position");
        for ($q=array(); $w=mysql_fetch_assoc($res); $q[]=$w);
        for ($i=0; $i<count($q); $i++){mysql_query("delete from image where id='".$q[$i]['id']."'");}
        for ($i=0; $i<count($q); $i++){
        static $e=1;
            $res="INSERT INTO `image` ( `id` , `id_gal` , `user_id`, `file` , `podp` , `position`, `status` )
                    VALUES ('".$q[$i]['id']."', '".$q[$i]['id_gal']."', '".$q[$i]['user_id']."', '".$q[$i]['file']."', '".$q[$i]['podp']."', '".($e++)."', '".$q[$i]['status']."')";
            mysql_query($res);
        }
    }

    Сортируем фото после удаления одного из них. Зачем то нужен непрерывный position

    stechkh, 07 Февраля 2015

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /**
         * Verify displayed special product price on product page(front-end) equals passed from fixture.
         *
         * @return null|string|void
         */
        protected function verifySpecialPrice()
        {
            return null;
        }

    Судя с того, что написано в дескрипшене, а именно
    @return void
    даный метод можно свести к
    return;
    или даже
    //

    Lord723518, 03 Февраля 2015

    Комментарии (3)
  9. Ruby / Говнокод #17560

    −141

    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
    # GET /med_programs/1/edit
      def edit
        @med_program = MedProgram.includes(:appeal, :template).find(params[:id])
        next_step_path = next_step_appeal_path(@med_program.appeal_id)
        # TODO: flash.keep ?
        case true
          when @med_program.appeal.kit_not_found?
            redirect_to @med_program.appeal
          when @med_program.appeal.new?
            # Just render edit view
          when @med_program.appeal.verify_person?
            redirect_to edit_person_path(@med_program.appeal.person_id, :back_url => next_step_path)
            return # для наглядности
          when @med_program.appeal.create_user?
            if @med_program.appeal.person.user_id
              path = edit_user_path(@med_program.appeal.person.user_id, :back_url => next_step_path)
            else
              path = new_user_path(:person_id => @med_program.appeal.person_id, :back_url => next_step_path)
            end
            redirect_to path
            return # для наглядности
          when @med_program.appeal.add_doctor?
            redirect_to add_doctor_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.create_user_doctor?
            if @med_program.doctor.person.user_id
              path = edit_user_path(@med_program.doctor.person.user_id, :back_url => next_step_path)
            else
              path = new_user_path(:person_id => @med_program.doctor.person_id, :back_url => next_step_path)
            end
            redirect_to path
            return # для наглядности
          when @med_program.appeal.add_contractor?
            redirect_to add_contractor_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.input_settings?
            redirect_to set_settings_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.pick_specialists?
            redirect_to select_specialists_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.pick_operators?
            redirect_to select_operators_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.read_informed_consent?
            redirect_to informed_consent_med_program_path(@med_program.id)
            return # для наглядности
          when @med_program.appeal.sign_contract?
            redirect_to sign_contract_med_program_path(@med_program.id)
            return # для наглядности
          else
            redirect_to @med_program
        end
      end

    Самый наглядный код в мире

    FancyDancy, 02 Февраля 2015

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for($i = 0; $i < $count; ++$i){
      $result_formatted[$i][] = $result[$counter];
      ++$counter;
      $result_formatted[$i][] = $result[$counter];
      ++$counter;
    }

    Magic operations

    alexhifer, 26 Января 2015

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

    +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
    16. 16
    17. 17
    18. 18
    //......................................
    void DlPortWritePortUshort(WORD addr, WORD data) {
      DWORD br;
      (&addr)[1]=data;
      DeviceIoControl(hdriver,IOCTL_WRITE_PORT_USHORT,&addr,4,NULL,0,&br,NULL);
    }
    
    DWORD DlPortReadPortUlong(WORD addr) {
     DWORD br;
     DeviceIoControl(hdriver,IOCTL_READ_PORT_ULONG,&addr,2,&addr,4,&br,NULL);
     return *(DWORD*)&addr;
    }
    
    void DlPortWritePortUlong(WORD addr, DWORD data) {
      DWORD br;
      DeviceIoControl(hdriver,IOCTL_WRITE_PORT_ULONG,&addr,8,NULL,0,&br,NULL);
    }
    //......................................

    Кусок очередного форка dll-ки для работы с очередным, мать его, форком драйвера inpout32.sys.
    Попался в поисках исправленного драйвера и dll-обёртки для него.

    harvestor, 22 Января 2015

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