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

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

    +149

    1. 1
    document.getElementById('out').value = document.getElementById('in').value.toString().translit().split(' ').join('_').toString().toLowerCase()

    translit() видимо самописный...

    TRANE73, 22 Января 2013

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

    −107

    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
    -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {	
    	return 6;
    }
    
    -(UITableViewCell *) tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	static NSString *kCellIdentifier = @"";
    	switch (indexPath.row) 
    	{
    		case 0:
    			kCellIdentifier = @"SpaceCell";
    			break;
    		case 1:
    			kCellIdentifier = @"LoginCell";
    			break;
    		case 2:
    			kCellIdentifier = @"PasswordCell";
    			break;
    		case 3:
    			kCellIdentifier = @"EmailCell";
    			break;
    		case 4:
    			kCellIdentifier = @"BirhtdayCell";
    			break;
    		default:
    			kCellIdentifier = @"ForgotCell";
    			break;
    	}
    	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:kCellIdentifier] autorelease];
    	cell.selectionStyle = UITableViewCellSelectionStyleNone;
    	cell.backgroundColor = [UIColor clearColor];
    	cell.backgroundView.backgroundColor = [UIColor clearColor];
    
    	if (indexPath.row == 1)
    	{
    		[self backgroundCells:cell fileImage:@"top_downlayer.png"];
    		self.loginTextField.text = userName;
    		self.loginTextField.placeholder = @"User Name";
    		self.loginTextField.frame = CGRectMake(10.0f, 10.0f, 300.0f, 30.0f);
    		[cell.contentView addSubview:self.loginTextField];
    	}
    	else if (indexPath.row == 2)
    	{
    		[self backgroundCells:cell fileImage:@"middle_downlayer.png"];
    		self.passwordTextField.text = password;
    		self.passwordTextField.placeholder = @"Password";
    		self.passwordTextField.frame = CGRectMake(10.0f, 8.0f, 300.0f, 30.0f);
    		[cell.contentView addSubview:self.passwordTextField];
    	}
    	else if (indexPath.row == 3)
    	{
    		[self backgroundCells:cell fileImage:@"middle_downlayer.png"];
    		self.email.text = emailString;
    		self.email.placeholder = @"Email";
    		self.email.frame = CGRectMake(10.0f, 7.0f, 300.0f, 30.0f);
    		[cell.contentView addSubview:self.email];
    	}
    	else if (indexPath.row == 4)
    	{
    		[self backgroundCells:cell fileImage:@"middle_downlayer.png"];
    		UIImageView *inputIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"input_login.png"]];
    		inputIV.frame = CGRectMake(20, 8, 280, 28);
    		[inputIV setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    		[cell addSubview:inputIV];
    		[inputIV release];
    						
    		if (![resultsDate.text length])
    		{
    			UILabel *birhtdayLabel = [[UILabel alloc] initWithFrame:CGRectMake(29, 12, 150, 20)];
    			birhtdayLabel.text = @"Birthday";
    			[birhtdayLabel setTextAlignment:UITextAlignmentLeft];
    			[birhtdayLabel setFont: [UIFont fontWithName:@"Arial" size:17.0f]];
    			[birhtdayLabel setTextColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.25]];
    			[birhtdayLabel setHighlightedTextColor:[UIColor whiteColor]];
    			[birhtdayLabel setBackgroundColor:[UIColor clearColor]];
    			[birhtdayLabel setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
    			[cell addSubview:birhtdayLabel];
    			[birhtdayLabel release];
    		}
    		else
    			[cell addSubview:resultsDate];
    	}
    	else if (indexPath.row == 5)
    	{
    		[self backgroundCells:cell fileImage:@"down_downlayer.png"];
    		UIImage *buttonBackgroundPressed = [UIImage imageNamed:@"search_btn_act.png"];
    		UIImage *buttonBackground = [UIImage imageNamed:@"search_btn.png"];
    		UIButton *singUpButton = [CustomButton buttonWithTitle:@"SIGN UP" target:self selector:@selector(singUpTouchAction:) frame:CGRectMake(20, 6, 280, 28) image:buttonBackground imagePressed:buttonBackgroundPressed];
    		singUpButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    		singUpButton.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    		[cell addSubview:singUpButton];
    	}
    	return cell;
    }

    Старый проект. Открыл класс наугад.

    Так кто-то строил форму для регистрации юзера. Каждое поле в форме - уникально.

    QuickNick, 14 Января 2013

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

    +62

    1. 1
    $data['date'] = date('Y'.'-'.'m'.'-'.'d'.' '.'G'.':'.'m'.':'.'s');

    nicksevenfold, 11 Января 2013

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    static int multipart_buffer_eof(multipart_buffer *self TSRMLS_DC)
    {
    	if ( (self->bytes_in_buffer == 0 && fill_buffer(self TSRMLS_CC) < 1) ) {
    		return 1;
    	} else {
    		return 0;
    	}
    }

    nyaknyan, 05 Января 2013

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

    +148

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function mouseHover(state) {
    	var row = window.event.srcElement;
    	row.style.cursor='hand';
    	var colorChange = ((state == "over") ? "#ff0000" : "");
    	row.style.color = colorChange;
    	var textChange  = ((state == "over") ? "underline" : "none");
    	row.style.textDecoration = textChange;
    }
    
    Где-то в Html
    
    <DIV onmouseover="mouseHover('over')" onmouseout="mouseHover('out')">

    Из странички отчёта Microsoft SCCM

    dens, 27 Декабря 2012

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

    +57

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function attribute( $attr ) {
        if( method_exists( $this, $attr ) ) {
            return $this->$attr();
        }
    
        return $this->$attr();
    }

    Видимо сначало было без проверки.

    enures, 25 Декабря 2012

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

    +56

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function isAvailable( $args ) {
        $available = fetchAvailability( $args );
        
        return $available ? 'yep' : 'noup';
    }
    
    // Где-то в javascript после вызова isAvailable()
    function isAvailableCallback( result ) {
        if ( result === 'yep' ) {
        ...
        }
    }

    Альтернативный способ работы с логическим типом данных. Используется как и в javascript так и в php.

    enures, 25 Декабря 2012

    Комментарии (4)
  9. Java / Говнокод #12327

    +68

    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
    /*
        * Todo Гавнокод
        * Надо как то поуниверсальнее сделать
        * А то когда модель вмешавается в отображение, это криворукость
        */
        private static String ___recurGet(Dir dir){
            MorphiaQuery dirs = dir.getDirList();
            String  id = dir.getIdAsStr(),
                    name = dir.name;
    
            String html = "<div class=\"bottom-line\">";
            html += "<a href=\"#\" onclick=\"setPrnt('"+id+"')\" id=\""+id+"\">";
            html += name;
            html += "</a>";
            html += "<div class=\"pull-right\">";
            html += "<a href=\"#\" class=\"icon-trash\" onclick=\"deleteNode('"+id+"')\"></a>";
            html += "</div>";
            html += "</div>";
    
            if(dirs.count() < 1)
                return html;
    
            html += "<ul>";
            for(int i = 0; i < dirs.count(); i++){
                html += "<li>";
                html += ___recurGet((Dir)dirs.offset(i).first());
                html += "</li>";
            }
            html += "</ul>";
            return html;
        }
    
        public static String getTreeAsHtml(String _typ){
            MorphiaQuery dirs = getRootDirList().filter("typ",Type.valueOf(_typ));
    
            if(dirs.count() < 1)
                return "Категорий нет";
    
            String html = "<ul id=\"treeView\">";
            for(int i = 0; i < dirs.count(); i++){
                html += "<li>";
                html += ___recurGet((Dir)dirs.offset(i).first());
                html += "</li>";
            }
            html += "</ul>";
            return html;
        }

    В модели "категория" написал метод для получения дерева категории в виде html кода...
    Причем такая генерация должна происходить в view, а сделал как обычно через ж

    haker, 21 Декабря 2012

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

    +54

    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
    function validEmail($email)
    {
    	$isValid = true;
    	$atIndex = strrpos($email, "@");
    	if (is_bool($atIndex) && !$atIndex) {
    		$isValid = false;
    	} else {
    		$domain = substr($email, $atIndex + 1);
    		$local = substr($email, 0, $atIndex);
    		$localLen = strlen($local);
    		$domainLen = strlen($domain);
    		if ($localLen < 1 || $localLen > 64) {
    			// local part length exceeded
    			$isValid = false;
    		} else if ($domainLen < 1 || $domainLen > 255) {
    			// domain part length exceeded
    			$isValid = false;
    		} else if (!strrpos($domain, ".")) {
    			// domain part does not have .
    			$isValid = false;
    		} else if ($domain[0] == '.' || $domain[$domainLen - 1] == '.') {
    			// domain part starts or ends with '.'
    			$isValid = false;
    		} else if ($local[0] == '.' || $local[$localLen - 1] == '.') {
    			// local part starts or ends with '.'
    			$isValid = false;
    		} else if (preg_match('/\\.\\./', $local)) {
    			// local part has two consecutive dots
    			$isValid = false;
    		} else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
    			// character not valid in domain part
    			$isValid = false;
    		} else if (preg_match('/\\.\\./', $domain)) {
    			// domain part has two consecutive dots
    			$isValid = false;
    		} else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) {
    			// character not valid in local part unless 
    			// local part is quoted
    			if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) {
    				$isValid = false;
    			}
    		}
    		/* if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
    		  // domain not found in DNS
    		  $isValid = false;
    		  } */
    	}
    	return $isValid;
    }

    Интересно а автор когдата слишал про filter_var?
    Это все можна заменить на filter_var($input, FILTER_VALIDATE_EMAIL);
    Товаришь программист! Не умеешь срать - не мучай жопу!

    v_anonym, 19 Декабря 2012

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

    +42

    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
    function Utf2Win($s){ return Utf8($s,'w') ; }  
    function Win2Utf($s){ return Utf8($s,'u') ; }  
    function Utf8($s, $sTo = 'utf2win'){  
       $a = array();  
      for ($i=128; $i <= 191; $i++){  
       $a['utf'][] = ($i<144) ? chr(209).chr($i) : chr(208).chr($i);  
       $a['win'][] = ($i<144) ? chr($i + 112) : chr($i + 48) ;  
      }  
      $a['utf'][] = chr(208) . chr(129);  
      $a['win'][] = chr(168);  
      $a['utf'][] = chr(209) . chr(145);  
      $a['win'][] = chr(184);
    
      $a['utf'][] = chr(209) . chr(78);  
      $a['win'][] = chr(73);
    
      $a['utf'][] ='в„–';
      $a['win'][] = '№';
    
       if(in_array(strtolower($sTo), array('utf2win','w','cp1251','windows-1251')))  
         return str_replace($a['utf'], $a['win'], $s);  
       if(in_array(strtolower($sTo), array('win2utf','u','utf8','utf-8')))  
         return str_replace($a['win'], $a['utf'], $s);  
    } 
    
    function getfield_csv($string,$index)
    {
      $arr = explode(";",$string);
      return $arr[$index];
    }
    
    function read_csv($file)
    {
      $hFile = fopen($file,"r");
        $source_data_utf = fread($hFile,filesize($file));
      fclose($hFile);
      
      $source_data = Utf2Win($source_data_utf);
      
      $arr_source_data = explode("\r\n",$source_data);
      
      for($i=0;$i<count($arr_source_data);$i++)
      {
        $arr_source_data[$i] = str_replace(chr(239).chr(187).chr(191), "", $arr_source_data[$i]);
        $result[] = Array();
        $result[count($result)-1]['Ds'] = getfield_csv($arr_source_data[$i], 0);
        $result[count($result)-1]['Fkp'] = getfield_csv($arr_source_data[$i], 5);
        $result[count($result)-1]['Tgg'] = getfield_csv($arr_source_data[$i], 3);
        $result[count($result)-1]['Pol'] = getfield_csv($arr_source_data[$i], 4);
        $result[count($result)-1]['Tr'] = getfield_csv($arr_source_data[$i], 6);
      }
      return $result;
    }

    clauclauclau, 17 Декабря 2012

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