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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    this.alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
    this.identityDefence = this.alphabet[Math.floor(Math.random() * (this.alphabet.length - 1))] + Math.floor(Math.random() * 1000) 
    + this.alphabet[Math.floor(Math.random() * (this.alphabet.length - 1))] 
    + this.alphabet[Math.floor(Math.random() * (this.alphabet.length - 1))] + Math.floor(Math.random() * 1000) 
    + this.alphabet[Math.floor(Math.random() * (this.alphabet.length - 1))] + Math.floor(Math.random() * 1000);

    А как вы генерируете случайный id объектов?

    SuperCuke, 02 Февраля 2015

    Комментарии (24)
  2. 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)
  3. Ruby / Говнокод #17559

    −157

    1. 1
    patient_id = MedProgram.where(:id => params[:med_program_id]).limit(1).pluck(:patient_id).first

    FancyDancy, 02 Февраля 2015

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

    +53

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    for (int i = 1; i <= s.Length; ++i) {
        if (s[i] == '/') {
            s = s.SubString(1, i) + s.SubString(i, MaxInt);
            ++i;
        }
    }

    Кручу-верчу запутать хочу. Кто с первого раза догадается, в чём задача кода - получит пирожок с полочки.

    P.S. Строки билдеровские, нумерация с 1. SubString принимает индекс начала и количество символов.

    bormand, 02 Февраля 2015

    Комментарии (98)
  5. C# / Говнокод #17557

    +136

    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
    private static string RemoveInvalidChars(string source)
    {
        foreach (var c in invalidChars)
            source = source.Replace(c.ToString(), "");
    
        return source;
    }
    
    public static string Validate(string source)
    {
        source = RemoveInvalidChars(source);
    
        return source;
    }

    pushistayapodmyshka, 02 Февраля 2015

    Комментарии (19)
  6. Java / Говнокод #17556

    +64

    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
    import java.util.HashMap;
    import java.util.Map;
    import java.util.StringTokenizer;
    
    public class PolynomialParser {
    	
    	public Polynomial parse(String rawPolynomial) {
    		String source = normalizeSourceString(rawPolynomial);
    		Map<Integer, Integer> result = new HashMap<>();
    		
    		StringTokenizer tokenizer = new StringTokenizer(source, "[+-]", true);
    		boolean isCurrentNegative = false;
    		int currentDegree;
    		int currentCoefficient;
    		while (tokenizer.hasMoreTokens()) {
    			String currentToken = tokenizer.nextToken();
    			if ("-".equals(currentToken)) {
    				isCurrentNegative = true;
    			} else if ("+".equals(currentToken)) {
    				isCurrentNegative = false;
    			} else {
    				if (currentToken.contains("x")) {
    					if (currentToken.contains("^")) {
    						String[] tmp = currentToken.split("x\\^");
    						currentDegree = Integer.parseInt(tmp[1]);
    						int draftCoefficient = Integer.parseInt(tmp[0]);
    						currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    					} else {
    						currentDegree = 1;
    						String[] tmp = currentToken.split("x");
    						int draftCoefficient = (tmp.length == 0) ? 1 : Integer.parseInt(tmp[0]);
    						currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    					}
    				} else {
    					currentDegree = 0;
    					int draftCoefficient = Integer.parseInt(currentToken);
    					currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    				}
    				result.put(currentDegree, currentCoefficient);
    			}
    		}
    		return new Polynomial(result);
    	}
    	
    	private String normalizeSourceString(String source) {
    		String result = source.replaceAll("\\s+","");
    		return result.toLowerCase();
    	}
    }

    Из сегодняшнего. Парсинг многочленов.

    itrofan-ebufsehjidov, 01 Февраля 2015

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

    +108

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    void Data3Fill(string _TownCheck, string _StreetCheck, string _HouseCheck, string _FlatCheck, string _BloodCheck,
    string _InsuranceCheck, string _EndPolCheck, string _DateFutureCheck, string _DoctorCheck, string _DiagnosisCheck, string _ComplaintsCheck, string _VichCheck, string _CancerCheck, string _SurnameCheck, string _NameCheck, string _MidnameCheck,
    string _SexCheck, string _StatusCheck, string _HighStatusCheck)
    {
    ...
    }

    Одному моему другу такой подход кажется нормальным.

    LoveSong, 01 Февраля 2015

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

    +143

    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
    #include <stdio.h>
    
    int main(void)
    {
    	int d2[3][3][3];
    	int i,i2,i3;
    	for(i = 0; i <= 3; ++i)
    		for(i2 = 0; i2 <= 3; ++i2)
    			for(i3 = 0; i3 <= 3; ++i3)
    				d2[i][i2][i3]=5;
    	i=0,i2=0,i3=0;
    	for(i = 0; i <= 3; ++i)
    		for(i2 = 0; i2 <= 3; ++i2)
    			for(i3 = 0; i3 <= 3; ++i3)
    				printf("%d\n",d2[i][i2][i3]);
    	return 0;
    }

    играюсь я короче с массивом, этот код компилируется,все печатает но в конце Segmentation fault, почему?
    gcc -Wall -Wextra -Werror -Wpedantic -ftrapv -fwrapv -fdiagnostics-show-option -std=gnu11 -o "test" "test.c"

    pl7ofit, 01 Февраля 2015

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

    +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
    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
    char* obrab_stroki(char*, int);
    int move(char*);
    int action_register(char*);
    int speed(char*);
    int condition(char*);
    
    char answer1[25];
    uint8_t Output[512];
    uint32_t number_for_output=16;
    typedef struct { char *name; uint8_t adress; } struct_label;
    typedef struct { char *name; uint8_t adress; } struct_goto_label;
    //----------------------------------------------------------------------------------------
    while (strcmp(qwerty[++string_count],""))
    	{
    		str=obrab_stroki(qwerty[string_count], 0);
    		printf("s:%s\n",str);
    		
    		if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"{")) fig_skob++;
    		if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"}")) fig_skob--;				
    		if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"{") && !strcmp(str,"if")) { fig_skob_if++; adres_return[fig_skob_if]=number_for_output+3; }
    		if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,"}") && fig_skob_if>0) { Output[adres_return[fig_skob_if]]=number_for_output; fig_skob_if--;}
    		if (fig_skob==0)
    		{
    			Output[number_for_output++]=0;
    			Output[number_for_output++]=0;
    		}
    
    		if (!strcmp(qwerty[string_count]+strlen(qwerty[string_count])-1,":")) 
    		{ 
    			label[number_label].name=qwerty[string_count];
    			label[number_label++].adress = number_for_output;
    			continue;
    		}				
    //-------------------------------------------------------------------------------------------
    if (!strcmp(str,"r")) if (action_register(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
    		if (!strcmp(str,"move")) if (move(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
    		if (!strcmp(str,"speed")) if (speed(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
    		if (!strcmp(str,"if")) if (condition(qwerty[string_count]) == 1) {printf("ERROR in string: %d", string_count); return 1;} else continue;
    		
    //-----------------------------------------------------------------------------------------
    char* obrab_stroki(char* qwerty, int i)
    {
    	int count;
    	char asnwer1[25];
    
    	for (count=0; (qwerty[count+i]<='z' && qwerty[count+i]>='a') || (qwerty[count+i]<='Z' && qwerty[count+i]>='A'); count++)
    	{
    		answer1[count]=qwerty[count+i];
    	}
    	answer1[count]='\0';
    
    	return answer1;
    }//тут как бы нет ошибок =)
    
    //----------------------------------------------------------------------------------------------
    if (qwerty[i]=='-')
    	{
    		if (qwerty[i+1]=='1' && qwerty[i+2]=='0')
    			{
    				Output[number_for_output++]=answer|MOTOR_SPEC_SPEED_DEC;
    				Output[number_for_output++]=0;
    				return 0;
    			}
    		else
    			return 1;
    	}

    Человек писал компилятор. Самые эпичные моменты

    epichniygovnokoder, 31 Января 2015

    Комментарии (12)
  10. Ruby / Говнокод #17552

    −99

    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
    def append_card(cards, new_card)
          if cards.nil?
            new_card == GameEvent::YELLOW_CARD ? 'yellow' : 'red'
          elsif cards == 'yellow'
            new_card == GameEvent::YELLOW_CARD ? 'two_yellow' : 'yellow_red'
          elsif cards == 'red'
            new_card == GameEvent::YELLOW_CARD ? 'yellow_red' : 'red'
          elsif cards == 'two_yellow'
            'two_yellow'
          elsif cards == 'yellow_red'
            new_card == GameEvent::YELLOW_CARD ? 'two_yellow' : 'yellow_red'
          end 
        end

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

    iHateBidlocod, 31 Января 2015

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