- 1
https://ideone.com/xM1uqd
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+147
https://ideone.com/xM1uqd
+937
public DataTable GetAllVideoDevice()
{
DataTable dt = DbUtil.GetData("SELECT VideoUrlId,VideoUrlName FROM VideoUrl");
return dt;
}
public int GetVideoDeviceCount()
{
int i = 0;
DataTable dt = GetAllVideoDevice();
if (dt.Rows.Count > 0) return dt.Rows.Count;
else return i;
}
У меня будут свои нули с блекджеком и шлюхами
+159
/**
* Дублирование пароля в поле CONFIRM_PASSWORD.
*/
function removeConfirmPasswordField()
{
$arFields = filter_input(INPUT_POST, 'REGISTER', FILTER_DEFAULT , FILTER_REQUIRE_ARRAY);
if($arFields)
{
$arKeys = array_keys($arFields);
$arNeedKeys = array('PASSWORD', 'CONFIRM_PASSWORD');
if(count(array_intersect($arKeys, $arNeedKeys)) === count($arNeedKeys))
{
$_POST['REGISTER']['CONFIRM_PASSWORD'] = $_POST['REGISTER']['PASSWORD'];
$_REQUEST['REGISTER']['CONFIRM_PASSWORD'] = $_REQUEST['REGISTER']['PASSWORD'];
}
}
}
AddEventHandler('main', 'OnBeforeProlog', 'removeConfirmPasswordField');
Вот таким способом я дублирую значение поля ввода пароля в поле для его подтверждения...
+74
for (int i = 0; i < blockNodeSize; i++) {
String blockTitle = subBlock.getElementsByClass("b-results__drugs-title").get(i).text();
String blockData = String.valueOf(subBlock.getElementsByTag("dd").get(i))
//.replace("\n", "")
.replace("<dd>", "")
.replace("</dd>", "")
.replace("<p><i>", "")
.replace("</i></p>", ":")
.replace("<p>", "")
.replace("</p>", "")
.replace("</i>", "")
.replace("<br>", "")
.replace("</br>", "\n");
+52
void ArmInterface::dispatchMessage(QString name, QJsonArray args)
{
//флаг того что мы не смогли обработать
bool notCallbacks = true;
//проходим по всем методам( которые кстати можно создать в рантайме )
for( int i = 0; i < metaObject()->methodCount() ; i++ )
{
QMetaMethod method = metaObject()->method( i);
//имя метода подходит под имя под сообщение от сервера? Прекрасно проверяем дальше.
if ( method.name() != name )
{
qWarning() << "method.name() != name" << " -> " <<method.name() << " != " << name;
//так как метод не найден мы просто выйдем отсюда, не дожидаясь ничего плохого
continue;
}
//метод у нас публичный? Если да то можно запускать обработку иначе заявим что низя
if ( method.access() != QMetaMethod::Public )
{
qWarning() << "Method " << method.name()<< " not public!";
#ifdef IGNORE_NOT_PUBLIC_METHOD
continue;
#endif
}
//несовдатает количество аргументов? Хватит это терпеть пишем warning, и если надо выходим из этого диспатчера
int countParams = method.parameterCount();
if ( args.count() != method.parameterCount() )
{
qWarning() << "Method " << method.name() << " params count = " << method.parameterCount() << " and received args params count = " << args.count();
#ifndef IGNORE_METHOD_PARAMS_COUNT
continue;
#endif
//берем наименьшее количество параметров
countParams = countParams > args.count() ? countParams : args.count();
}
//создание валидного QGenericArgument
auto genericArg = [ this, method, args ]( int index ) -> QGenericArgument{
//out of range?
if ( args.count() <= index ||
method.parameterCount() <= index )
return QGenericArgument();
void * data = 0;
//сохраняем временный QVariant для дальнейшей более удобной работы с ним
QVariant temp = args.at( index ).toVariant();
//попытка конвертирования типов. Если что-то не получается, пишем в лог. Мб надо будет сделать преждевременный выход, если сконвертировать не получается.
if ( !temp.convert( method.parameterType( index) ) )
{
qWarning()<< objectName() << " method : " << method.name() <<
" Not convert " << method.parameterNames().at( index ) << args.at( index ).toVariant().typeName() <<
" from " << args.at( index ).toVariant().typeName() <<
" to " << QMetaType::typeName( method.parameterType( index) ) ;
};
//у нас есть такой аргумент? Если нет - то ничего не делаем
if ( args.count() > index )
{
data = QMetaType::create( method.parameterType( index ) , temp.data() );
}
const char * name = 0;
//у нас есть имя аргумента и аргумент в него? Если чего-то нет - то ничего и не будем ничего делать
if ( method.parameterNames().count() > index && data)
name = method.parameterNames().at( index ).data();
return QGenericArgument(
name,
data);
};
//тут можно вызывать!
method.invoke( this,
//генерируем аргументы
genericArg(0),
genericArg(1),
genericArg(2),
genericArg(3),
genericArg(4),
genericArg(5),
genericArg(6),
genericArg(7),
genericArg(8),
genericArg(9));
notCallbacks = false;
//раз вызвали значит нашли подходящий callback, а следовательно искать дальше ненадо. Выходим нафиг.
break;
}
//вызвали что -нить? Если вызвали то не вызываем ничего. А иначе идем в другую функцию - которая разбирается как раз с такими сообщениями.
//Если надо перехватить совершенно все сообщения - перегружать функцию в которой находимся.
if ( !notCallbacks )
dispathUndefinedMessage( name, args );
}
Написал и мучаюсь - гавнокод или все таки нет.
ахда, мне надо выучить русский )
+158
$arr = mysql_fetch_assoc(mysql_query("select * from customers where Email1='".$_POST['email']."'"));
if ($arr and count($arr)!=0) {
Проверка, что массив не пустой
+77
public static void main(String[] args) {
testIndiaLazy();
}
private static void testIndiaLazy() {
LazyInstantiator lazyInstantiator = new LazyInstantiator();
lazyInstantiator.getInstance();
lazyInstantiator.getInstance();
}
public static class LazyInstantiator {
private Object instance;
public Object getInstance() {
System.out.println("getInstance");
if (instance != null || create());
return instance;
}
private boolean create() {
System.out.println("create");
instance = new Object();
return true;
}
}
Out:
getInstance
create
getInstance
+164
window.onload = function (){
var divs=document.getElementsByTagName("DIV");
for( var i=0; i<divs.length; i++)
if(divs[i].className=="pro")
divs[i].style.minHeight=0+"px"
;
}
Целостность кода сохранена.
−111
Set rs = CurrentDb.OpenRecordset(sql, dbOpenDynaset)
If rs.RecordCount > 0 Then
rs.MoveLast
rscnt = rs.RecordCount
rs.MoveFirst
If rscnt >= 2 Then
ApllyActions = 1
lActionText.Visible = True
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 4 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 6 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 8 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 10 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 12 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 14 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 16 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 18 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 20 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 22 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
If rscnt >= 24 Then
rs.MoveNext
rs.Edit
rs!Cost = rs!CostSrc * (100 - discount) / 100
rs!Summa = rs!CostSrc * (100 - discount) / 100
rs!discount = -discount
rs.Update
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Код старшего программиста для проведения продажи "3 товара по цене двух". Опыт -10 лет. Если в чеке единиц товара больше 24, => не сработает.
+57
/* Fix NAN constant for VisualC++. */
#ifdef _MSC_VER
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#define NAN (*(const float *) __nan)
#endif
#endif
????