- 1
- 2
- 3
- 4
- 5
- 6
function array_search_my($string,$array){
foreach($array as $el){
if($el==$string) return true;
}
return false;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+161
function array_search_my($string,$array){
foreach($array as $el){
if($el==$string) return true;
}
return false;
}
in_array - не круто.
−125
ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(НовыйПользователь.Спонсор); //Выдергиваем указанного спонсора чтобы запихать ему в ногу
Курсор = ТекущийПользователь.НастройкаКурсорНоги;//Определяет в какую ногу будут попадать новые рефералы
Итератор = 0;
Пока Истина цикл
Спонсор = ТекущийПользователь;//Небольшой финт
Если Итератор = 0 тогда
Если Курсор = "Левая" тогда
ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(ТекущийПользователь.ЛеваяНога);
Иначе
ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(ТекущийПользователь.ПраваяНога);
КонецЕсли;
Иначе
ТекущийПользователь = Справочники.Контрагенты.НайтиПоКоду(ТекущийПользователь.ПраваяНога); //Всех в "Правую ногу"
КонецЕсли;
Если ТекущийПользователь = Справочники.Контрагенты.ПустаяСсылка тогда
Если Итератор = 0 тогда
Если Курсор = "Левая" тогда
Спонсор.ЛеваяНога = ТекущийПользователь;
Иначе
Спонсор.ПраваяНога = ТекущийПользователь;
КонецЕсли;
Иначе
Спонсор.ПраваяНога = ТекущийПользователь;
КонецЕсли;
Прервать;//Успешное завершение
КонецЕсли;
КонецЦикла;
+85
public final class Equality {
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @return true if the arguments are equal to each other and false otherwise
*/
public static <O> boolean eq(@Nullable O o, @Nullable O a) {
return Objects.equals(o, a);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a) {
return eq(o, a);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b) {
return eq(o, a) || eq(o, b);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @param c an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c) {
return eqAny(o, a, b) || eq(o, c);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @param c an object to be compared with {@code o} for equality
* @param d an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d) {
return eqAny(o, a, b, c) || eq(o, d);
}
/**
* @param o an object
* @param a an object to be compared with {@code o} for equality
* @param b an object to be compared with {@code o} for equality
* @param c an object to be compared with {@code o} for equality
* @param d an object to be compared with {@code o} for equality
* @param e an object to be compared with {@code o} for equality
* @return true if the any arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, @Nullable O a, @Nullable O b, @Nullable O c, @Nullable O d, @Nullable O e) {
return eqAny(o, a, b, c, d) || eq(o, e);
}
/**
* @param o an object
* @param a an array of objects to be compared
* @return true if any the arguments are equal to each other and false otherwise
*/
public static <O> boolean eqAny(@Nullable O o, O... a) {
for(O e: a)
if(eq(o, e))
return true;
return false;
}
}
Мой любимый класс.
Когда на душе становится тяжело, я всегда открываю этот класс, и признаки депрессии улетучиваются.
И да, комментарии врут, и да, там еще столько же методов eqAll(...)
+161
there is a reason why opencart is the no.1 most used ecommerce solution in places like china and india, its the easiest code base to understand!
--
many apps servers! what does that mean? you mean different applications running from the same framework?
you build each application starting from the index.php file and include what ever library classes you require.
--
"I agree with you that it's harder to write simple code, because REPEATING CODE IS HARD TO DEBUG HARD TO READ AND TO CORRECT. so it makes you waste a lot of time."
this is what search and replace is for!
Создатель опенкарта (Daniel Kerr) исходит на говно, много мякотки
http://www.techchattr.com/never-use-opencart#comment-1151857248
+51
//Sets the color(background and foreground)
void Console::SetColor(){
#ifdef _WIN32
SetConsoleTextAttribute(hConsole, FGColor | BGColor);
#else
string clr = "\033[";
clr += BGColor;
clr += ";";
clr += FGColor;
clr += "m";
cout << clr;
#endif
}
Изменение цвета текста и фона консоли
+145
char bStr[1000];
strncpy(bStr, " [\0", strlen(" [\0"));
Потому что в man:
Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null terminated.
+98
switch (_viewerPanel.Modified)
{
case true:
_viewerPanel.FilenameLabel.Text = _listOfRecords[index].Name;
_filesPanel.listViewControl.Items[index].Text = _listOfRecords[index].Name;
_fileChangeDictionary[_listOfRecords[index].FullName] = true;
break;
case false:
_viewerPanel.FilenameLabel.Text = _listOfRecords[index].Name;
_filesPanel.listViewControl.Items[index].Text = _listOfRecords[index].Name;
_fileChangeDictionary[_listOfRecords[index].FullName] = false;
break;
}
Удивительно, но это писал не индус...
+145
add ax,1 ; Добавляем в ax 1 (не знаю, почему он так сделал, МЕДЛЕННО И 3 БАЙТА), можно было же inc ax
add ax,1
add ax,1
add ax,1
add ax,1
add ax,1
add ax,1
add ax,1
add ax,1
mov ax,9 ; А теперь я понял тщетность бытия и те потраченные байты выше.
Самый лучший говнокод новичка, который я видел.
+95
public static class ColorExtension
{
public static bool IsDarkColor(this Color color)
{
return (color.R & 255) + (color.G & 255) + (color.B & 255) < 3*256/2;
}
}
x & 255 = ?, где x типа byte
+152
<?
require_once('ittable.class.php');
class ITForm extends ITTable
{
public function __construct($tbl)
{
parent::__construct($tbl);
//путь с скрипту который удаляет файлы по tblname record_id filename
$this->path2deletephp='/itcms4/ckeditor/delete.php';
}
public function generateFormData($i, $action, $head, $submitvalue='', $captcha=0)
{
global $itcmscfg;
$form->submitvalue=htmlentities($submitvalue?$submitvalue:$head, ENT_NOQUOTES, 'UTF-8');
$form->tbl = $this->tbl;
if($this->files) $enctype='enctype="multipart/form-data"';
$form->head = htmlentities($head, ENT_NOQUOTES, 'UTF-8');
$form->begin = "<form name='$this->tbl$i->id' id='$this->tbl$i->id' action='$action' method='post' $enctype>";
$form->inputhidden .= "<input type='hidden' name='id' value='$i->id'><input type='hidden' name='referer' value='" . ($_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:'./') . "'>\n";
if($action=='delete.php') {$form->disabled = 'disabled'; $OPERATION = UPDATABLE;}
elseif($action=='insert.php') $OPERATION = INSERTABLE;
elseif($action=='update.php') $OPERATION = UPDATABLE;
else $OPERATION = UPDATABLE;
foreach($this->columns as $field=>$ftype)
{
$itforms = " $form->disabled name='$field' id='input-$field'" . $this->getITFormsAttr($field);
$value = isset($i->$field) ? $i->$field : ($_GET[$field] ? $_GET[$field]: $ftype->Default);
if(!$ftype->htmlcode) $value = htmlentities($value, ENT_QUOTES, 'UTF-8');
$itcmscfg->cfgfile = intval($itcmscfg->cfgfile);
if($ftype->Key=='UNI') $itforms .= " data-async='false' data-unique='{cfgfile:$itcmscfg->cfgfile, tblname:\"$this->tbl\", record_id:\"$i->id\"}'";
if($ftype->visibility & HIDDEN){$form->inputhidden .= "<input type='hidden' $itforms value='$value'>"; continue;}
//если поле не RADONLY, то проверить задан ли regexp и разрешена ли операция
if( !($ftype->visibility & READONLY) )
if(!$ftype->pattern || !($ftype->visibility & $OPERATION))
continue;
$form->inputs[$field]->name = "<label for='input-$field' id='label-$field'>$ftype->outputname</label>";
//выводим элементы
if($ftype->options)
{
$form->inputs[$field]->input = $ftype->options->html($field, " $form->disabled " . $this->getITFormsAttr($field), $value);
if($ftype->options->type==OT_BINARY_CHECKBOX)
$form->js .= "itform.setCheckboxProperty('$field', 'sum', '$ftype->minselected', '$ftype->maxselected');\n";
}
elseif($ftype->inputtype=='wysiwyg')
$form->inputs[$field]->input = "<script src=/include/ckeditor/ckeditor.js></script>
<textarea class='ckeditor' name='$field'>$value</textarea>";
elseif($ftype->Type=='text')
$form->inputs[$field]->input = "<textarea rows='10' cols='80' $itforms " . ($form->disabled?' readonly':'') . ">$value</textarea>";
elseif($ftype->inputtype)
$form->inputs[$field]->input = "<input type='$ftype->inputtype' value='$value' $itforms>";
else
$form->inputs[$field]->input = "<input type='text' value='$value' $itforms>";
$f1 = $ftype->func;
if(isset($f1))
$form->inputs[$field]->input .= (' ' . $f1($value));
}//foreach
if($this->files)
{
foreach($this->files as $k=>$o)
{
$itforms = "";
//это только для action==insert.php можно, при редактирвоании не обязательно файл заливать
$itforms .= ($o->required && $action=='insert.php') ? " data-min-length='1'" : '';
$itforms .= $o->validExtentions ? " data-regexp='$o->validExtentions'" : '';
if($o->help) $itforms .= " data-help='$o->help'";
if($o->multiple)
{
$itforms .= ' multiple';
$multiple = '[]';
}
else
$multiple='';
$outputname = htmlentities($o->outputname, ENT_NOQUOTES, 'UTF-8');
$form->inputs[$k]->name = "<label for='input-$k'>$outputname</label>";
$form->inputs[$k]->input = "<input type='file' name='$k$multiple' id='input-$k' $itforms>";
}//foreach
if(intval($i->id))
$form->files = $itcmscfg->fs->getFiles4TblRecord($this->tbl, $i->id);
}//if
return $form;
}//fun