- 1
document.getElementById('out').value = document.getElementById('in').value.toString().translit().split(' ').join('_').toString().toLowerCase()
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+149
document.getElementById('out').value = document.getElementById('in').value.toString().translit().split(' ').join('_').toString().toLowerCase()
translit() видимо самописный...
−107
-(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;
}
Старый проект. Открыл класс наугад.
Так кто-то строил форму для регистрации юзера. Каждое поле в форме - уникально.
+62
$data['date'] = date('Y'.'-'.'m'.'-'.'d'.' '.'G'.':'.'m'.':'.'s');
+129
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;
}
}
+148
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
+57
function attribute( $attr ) {
if( method_exists( $this, $attr ) ) {
return $this->$attr();
}
return $this->$attr();
}
Видимо сначало было без проверки.
+56
function isAvailable( $args ) {
$available = fetchAvailability( $args );
return $available ? 'yep' : 'noup';
}
// Где-то в javascript после вызова isAvailable()
function isAvailableCallback( result ) {
if ( result === 'yep' ) {
...
}
}
Альтернативный способ работы с логическим типом данных. Используется как и в javascript так и в php.
+68
/*
* 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, а сделал как обычно через ж
+54
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);
Товаришь программист! Не умеешь срать - не мучай жопу!
+42
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;
}