- 1
- 2
- 3
<?if($_POST["is_ajax_post"] != "Y"){?>
<input type="hidden" name="is_ajax_post" id="is_ajax_post" value="Y">
<? } ?>
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+153
<?if($_POST["is_ajax_post"] != "Y"){?>
<input type="hidden" name="is_ajax_post" id="is_ajax_post" value="Y">
<? } ?>
Форма оформления заказа в компоненте sale.order.ajax. Bitrix. Логика.
+137
#define SPLICE(a,b) SPLICE_1(a,b)
#define SPLICE_1(a,b) SPLICE_2(a,b)
#define SPLICE_2(a,b) a##b
#define PP_ARG_N( \
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
_61, _62, _63, N, ...) N
/* Note 63 is removed */
#define PP_RSEQ_N() \
62, 61, 60, \
59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
/* Note dummy first argument _ and ##__VA_ARGS__ instead of __VA_ARGS__ */
#define PP_NARG(...) PP_NARG_(_, ##__VA_ARGS__, PP_RSEQ_N())
#define NARG(...) func(PP_NARG(__VA_ARGS__), __VA_ARGS__)
#define INCR 20
#define FIELD_0(...)
#define FIELD_1(field, ...) \
INCR+field
#define FIELD_2(field, ...) \
INCR+field, FIELD_1(__VA_ARGS__)
#define FIELD_3(field, ...) \
INCR+field, FIELD_2(__VA_ARGS__)
#define FIELD_4(field, ...) \
INCR+field, FIELD_3(__VA_ARGS__)
#define FIELD_5(field, ...) \
INCR+field, FIELD_4(__VA_ARGS__)
#define FIELD_5(field, ...) \
INCR+field, FIELD_4(__VA_ARGS__)
#define FIELD_6(field, ...) \
INCR+field, FIELD_5(__VA_ARGS__)
#define FIELD_7(field, ...) \
INCR+field, FIELD_6(__VA_ARGS__)
#define FIELD_8(field, ...) \
INCR+field, FIELD_7(__VA_ARGS__)
#define FIELD_9(field, ...) \
INCR+field, FIELD_8(__VA_ARGS__)
#define FIELD_10(field, ...) \
INCR+field, FIELD_9(__VA_ARGS__)
#define FIELD_11(field, ...) \
INCR+field, FIELD_10(__VA_ARGS__)
//..... дальше лень ...
#define FIELDS_(N, ...) \
SPLICE(FIELD_, N)(__VA_ARGS__)
#define FIELDS(...) \
FIELDS_(PP_NARG(__VA_ARGS__), __VA_ARGS__)
a = { FIELDS('p', 'a', 's', 's', 'w', 'o', 'r', 'd') }
Примитивное компил-тайм шифрование строки через сишный препроцессор. На выходе получаем
a = { 20 +'p', 20 +'a', 20 +'s', 20 +'s', 20 +'w', 20 +'o', 20 +'r', 20 +'d' };
+68
public static String elvis(String value, String ifNull) {
return value == null ? ifNull : value;
}
public static Boolean elvis(Boolean value, Boolean ifNull) {
return value == null ? ifNull : value;
}
public static Object elvis(Object value, Object ifNull) {
return value == null ? ifNull : value;
}
- Objects#firstNotNull()?
- нет, не слышал
+105
//Невероятные приключения Microsoft'а в Индии:
private string ExtractHttpVerb(XmlDocument configDOM)
{
string httpVerb;
string hv = IfExistsExtract(configDOM, "/Config/method", "2");
switch (hv)
{
case "0":
httpVerb = HttpVerbs[0];
break;
case "1":
httpVerb = HttpVerbs[1];
break;
case "2":
httpVerb = HttpVerbs[2];
break;
default:
httpVerb = HttpVerbs[2];
break;
}
return httpVerb;
}
−167
PROCEDURE login_attr(a_id IN CHAR, a_pw IN VARCHAR2, v_ret IN OUT VARCHAR2)
IS
v_count INTEGER;
BEGIN
v_count := 0;
SELECT NVL (COUNT (attrib_desc), 0)
INTO v_count
FROM tab_attr a,
tab_users b
WHERE a.msc_cd = b.user_dept
AND a.attr_cd = 'CD'
AND lattr_cd = 'ABCD'
AND UPPER (user_no) = UPPER (a_id)
AND UPPER (user_pw) = UPPER (a_pw);
IF v_count > 0 THEN
SELECT attrib_desc || '@' || user_lang || '@' || user_autoimg ||
'@' || user_imgtime || '@' || user_loc || '@' ||
user_dept
INTO v_ret
FROM tab_attr a,
tab_users b
WHERE a.msc_cd = b.user_dept
AND a.attr_cd = 'CD'
AND lattr_cd = 'ABCD'
AND UPPER (user_no) = UPPER (a_id)
AND UPPER (user_pw) = UPPER (a_pw);
ELSE
v_ret := ' ';
END IF;
END;
Нам нужно больше селектов.
P.S. почему в предпросмотре язык Java, хотя выбран SQL?
−166
SELECT ...
FROM users_account
....
WHERE
(T.userid=@userid or (@userid=null and @account!=null))
and (T.account=@account or (@userid!=null and @account=null))
Есть табличка с юзерами и счетами на которых у юзеров есть игровая валюта.
Есть индекс по обоим этим полям (userid, account).
Каждый такой запрос сканирует весь индекс,а не делает по ней поиск, чем и грузит субд.
Но попытки оптимизировать запрос не увечались успехом,
т.к. я так и не понял что хотел сказать автор в своём условии where.
−99
for i in range(0,len(m)):
if i==0:
f=False
s += x[m[i]]
else:
if i==len(m)-1:
if not f:
f=False
s += ',' + x[m[i]]
else:
f=False
s += x[m[i]]
break
else:
if m[i]-m[i-1]==1:
if m[i+1]-m[i]==1:
if not f:
f=True
s += '-'
continue
else:
continue
else:
if not f:
f=False
s += ',' + x[m[i]]
else:
f=False
s += x[m[i]]
else:
f=False
s += ','+x[m[i]]
Была задача: на вход(m) подается массив чисел, например [1,3,5,6,7], а на выходе получаем человекочитаемую строку(s) "пн,ср,пт-вс"
Вышло такое из меня пару месяцев назад, теперь я никогда не смогу в нем разобраться х_х
+42
#include <time.h>
#include <string>
#include <iostream>
#include <functional>
using namespace std::placeholders;
class F
{
int inc;
public:
F( int inc_v ): inc( inc_v ) {};
int calc( int x )
{
return x + inc;
};
};
F a1( -10 );
F a2( 11 );
int f1( int x )
{
return x - 10;
};
int f2( int x )
{
return x + 11;
};
struct my_ftor
{
F *obj;
int (F::*meth)(int);
int operator()(int x)
{
return (obj->*meth)( x );
};
my_ftor() {};
my_ftor( F *x, int(F::*y)(int) ) : obj(x), meth(y) {};
};
template<typename functor_type>
void test( std::function<functor_type(int)> filler, char *name )
{
const int size = 1000;
const int iters = 10000;
int beg_time, end_time;
functor_type funcs[ size ];
beg_time = clock();
for ( int i = 0; i < iters; i++ )
{
for ( int j = 0; j < size; j++ )
{
funcs[ j ] = filler(j);
}
};
end_time = clock();
float creation = ((float)(end_time - beg_time) / CLOCKS_PER_SEC);
beg_time = clock();
int res = 0;
for ( int i = 0; i < iters; i++ )
{
for ( int j = 0; j < size; j++ )
{
res = funcs[ j ]( res );
};
};
end_time = clock();
float execution = ((float)(end_time - beg_time) / CLOCKS_PER_SEC);
std::cout << name << " creation time: " << creation << " execution time: " << execution << " result: " << res << "\n";
}
int main(int c, char * * v)
{
test<int(*)(int)>( [](int i) {return i % 2 ? f1 : f2; }, "simple &function test" );
test<std::function<int(int)>>( [](int i) {return i % 2 ? f1 : f2; }, "functor &function test" );
test<std::function<int(int)>>( [](int i) {return i % 2 ? std::bind( &F::calc, &a1, _1 ) : std::bind( &F::calc, &a2, _1 ); }, "functor &object test" );
test<my_ftor>( [](int i) {return i % 2 ? my_ftor( &a1, &F::calc ) : my_ftor( &a2, &F::calc ); }, "obj->*meth struct test" );
std::cout << "END\n";
return 0;
}
http://ideone.com/1iNzR
Чем код так долго занимается?
simple &function test creation time: 0.05 execution time: 0.09 result: 5000000
functor &function test creation time: 0.51 execution time: 0.14 result: 5000000
functor &object test creation time: 1.25 execution time: 0.14 result: 5000000
obj->*meth struct test creation time: 0.12 execution time: 0.05 result: 5000000
END
+39
#include <iostream>
#include <memory>
struct Test {
~Test() { std::cout << "~Test\n"; }
};
int main() {
std::shared_ptr<void> ptr( new Test );
return 0;
}
http://ideone.com/xXPWhE
Но:
#include <iostream>
#include <memory>
struct Test
{
~Test() { std::cout << "~Test\n"; }
};
int main() {
std::shared_ptr<void> ptr( (void*) new Test );
return 0;
}
http://ideone.com/jhNvpJ
+46
//Сом ненужный щит
#include <iostream>
using namespace std;
#include <string>
#include <iostream>
struct Tracer {
Tracer(void)
:m_name("(none)")
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer(const std::string & name)
:m_name(name)
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer(const Tracer & other)
:m_name(other.m_name)
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer(const Tracer && other)
:m_name(other.m_name)
{
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
}
Tracer & operator=(const Tracer & other) {
m_name = other.m_name;
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
return *this;
}
Tracer & operator=(const Tracer && other) {
m_name = other.m_name;
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
return *this;
}
~Tracer() {
std::cout << "[" << m_name << "] " << __PRETTY_FUNCTION__ << std::endl;
m_name="You looser!";
}
std::string m_name;
};
//Тот щит, ради чего всё затевалось
template<class T> const T& Min(const T &x, const T &y) { return (x.m_name < y.m_name) ? x : y; }
int main() {
const Tracer& mr = Min(Tracer("a"), Tracer("b"));
cout<<"Some work with mr: "<<mr.m_name<<endl;
return 0;
}
[b] Tracer::Tracer(const string&)
[a] Tracer::Tracer(const string&)
[a] Tracer::~Tracer()
[b] Tracer::~Tracer()
Some work with mr:
Этож сколько я коммитов сделал с возвратом константной ссылки на константный параметр.