- 1
- 2
- 3
- 4
- 5
- 6
- 7
HRESULT SomeClass::GetVersion(std::wstring& version)
{
CComBSTR versionBstr;
m_Interface->get_Version(&versionBstr);
version = std::move(std::wstring((_bstr_t)versionBstr, versionBstr.Length()));
return S_OK;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
HRESULT SomeClass::GetVersion(std::wstring& version)
{
CComBSTR versionBstr;
m_Interface->get_Version(&versionBstr);
version = std::move(std::wstring((_bstr_t)versionBstr, versionBstr.Length()));
return S_OK;
}
Как показать в одном методе (не)знание move семантики, правил приведения типов и COM фреймворка
0
#include <xmmintrin.h>
void crasher() {
constexpr __m128 w = {1,2,3,4};
asm ("addps %[w], %[w]" : : [w] ""(w));
}
Крашим GCC
https://ideone.com/iIAN0i
−13
for i=1,1000 do
str = string.format("xyi%i", i)
f = io.open(str, "w")
f:write("я вирус! приветикиии")
f:flush()
f:close()
end
оцениваем по 1000 бальной шкале плиз!
+4
#include<stdio.h>
#include<math.h>
int const n = 50, n1 = 40, m = n / n1;
double f1(double t, double x, double y, double z);
double f2(double t, double x, double y, double z);
double f3(double t, double x, double y, double z);
int main() {
int i, k, ll;
double k11, k12, k13, k21, k22, k23, k31, k32, k33, k14, k24, k34;
double x, y, z, max;
double res[12][n1 + 1], h, a, b, t, pi, xn, yn, zn;
max = 1000.0; x = 3.0;
y = -2.0; z = -3.0;
a = 0.0; b = 1.0;
h = (b - a) / double(n);
k = 0; t = a;
res[0][0] = t; res[1][0] = x;
res[2][0] = y;
res[3][0] = z;
for (i = 1; i <= n; i++) {
k11 = f1(t, x, y, z);
k21 = f2(t, x, y, z);
k31 = f3(t, x, y, z);
k12 = f1(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
k22 = f2(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
k32 = f3(t + h / 2.0, x + h*k11 / 2.0, y + h*k21 / 2.0, z + h*k31 / 2.0);
k13 = f1(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
k23 = f2(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
k33 = f3(t + h / 2.0, x + h*k12 / 2.0, y + h*k22 / 2.0, z + h*k32 / 2.0);
k14 = f1(t + h, x + h*k13, y + h*k23, z + h*k33);
k24 = f2(t + h, x + h*k13, y + h*k23, z + h*k33);
k34 = f3(t + h, x + h*k13, y + h*k23, z + h*k33);
x = x + h*(k11 + 2.0*(k12 + k13) + k14) / 6.0;
y = y + h*(k21 + 2.0*(k22 + k23) + k24) / 6.0;
z = z + h*(k31 + 2.0*(k32 + k33) + k34) / 6.0;
t = t + h;
if (i%m == 0) {
k = k + 1;
res[0][k] = t;
res[1][k] = x;
res[2][k] = y;
res[3][k] = z;
res[4][k] = exp(t) + exp(2.0*t) + exp(-t);
res[5][k] = exp(t) - 3.0*exp(-t);
res[6][k] = exp(t) + exp(2.0*t) - 5.0*exp(-t);
res[7][k] = res[4][k] - res[1][k];
res[8][k] = res[5][k] - res[2][k];
res[9][k] = res[6][k] - res[3][k];
} if (res[7][k] < 0.0) {
res[7][k] = -res[7][k];
}
else if (res[8][k] < 0.0) {
res[8][k] = -res[8][k];
}
else if (res[9][k] < 0.0) {
res[9][k] = -res[9][k];
}
res[10][k] = res[7][k] + res[8][k] + res[9][k];
}
ll = k;
printf("k=%d\n", ll);
for (i = 0; i <= ll; i++) {
if (res[10][i] < max) max = res[10][i];
} for (i = 0; i <= n1; i++) {
printf("t=%.16lf\n", res[0][i]);
printf("x=%.16lf x(exact)=%.16lf delta=%.16lf\n", res[1][k], res[4][k], res[1][k] - res[4][k]);
printf("y=%.16lf y(exact)=%.16lf delta=%.16lf \n", res[2][k], res[5][k], res[2][k] - res[5][k]);
printf("z=%.16lf z(exact)=%.16lf delta=%.16lf \n", res[3][k], res[6][k], res[3][k] - res[6][k]);
}
printf("result:\n");
printf("t=%.16lf\n", res[0][n1]);
printf("x=%.16lf x(exact)=%.16lf delta=%.16lf\n", res[1][n1], res[4][n1], res[1][n1] - res[4][n1]);
printf("y=%.16lf y(exact)=%.16lf delta=%.16lf \n", res[2][n1], res[5][n1], res[2][n1] - res[5][n1]);
printf("z=%.16lf z(exact)=%.16lf delta=%.16lf \n", res[3][n1], res[6][n1], res[3][n1] - res[6][n1]);
printf("max norma|x|1=%.16lf \n", max / 3.0);
system("pause");
return 0;
}
double f1(double t, double x, double y, double z)
{
return x + z - y;
}
double f2(double t, double x, double y, double z)
{
return x + y - z;
}
double f3(double t, double x, double y, double z)
{
return 2.0*x - y;
}
Кандидат физико-математических наук сделал методичку по предмету "Моделирование систем". Это он так описал алгоритм решения системы ОДУ методом Рунге-Кутты.
+6
for(int i = 0; i < codes.size(); ++i) {
switch(i) {
case 0: ret.code0 = codes[i]; break;
case 1: ret.code1 = codes[i]; break;
case 2: ret.code2 = codes[i]; break;
case 3: ret.code3 = codes[i]; break;
case 4: ret.code4 = codes[i]; break;
case 5: ret.code5 = codes[i]; break;
}
}
А всё потому, что ret.code[0-5] - битовые поля. Эх.
−3
>ipconfig | find "IP"
═рёЄЁющър яЁюЄюъюыр IP фы Windows
IP-рфЁхё . . . . . . . . . . . . : 192.168.1.60
ЧЗХ (кодировка)?
−115
def _message_handler_thread(self):
self._nick_change_failed = []
while self.running:
msg = self._message_queue.get(True)
text = msg.get_data()
conn = msg.get_connection()
args = text.replace("\r", "").replace("\n", "").split(" ")
command = args[0].upper()
command_args = args[1:]
if command == "NICK":
if len(command_args) < 1:
self._send_not_enough_parameters(conn, command)
else:
ident = self._clients[conn].identifier if self._clients[conn].identifier else None
if not self._set_nick(conn, command_args[0], ident):
self._nick_change_failed.append(conn)
elif command == "USER":
if conn in self._clients:
if len(command_args) < 2:
self._send_not_enough_parameters(conn, command)
else:
''''
self._send_lusers(conn)
self._clients[conn].real_name = command_args[:]
self._clients[conn].identifier = self._clients[conn].get_nick() + "!" + \
command_args[0] + "@" + self.name
'''
self._set_nick(conn, command_args[0], command_args[1])
self._send_motd(conn)
else: # Another way to identify is USER command.
if len(command_args) < 2:
self._send_not_enough_parameters(conn, command)
elif conn in self._nick_change_failed:
self._nick_change_failed.remove(conn)
else:
if self._set_nick(conn, command_args[0], command_args[1]):
self._clients[conn].identifier = self._clients[conn].get_nick() + "!" + \
command_args[0] + "@" + self.name
self._send_motd(conn)
elif command == "PRIVMSG" or command == "NOTICE":
if len(command_args) < 2:
self._send_not_enough_parameters(conn, command)
else:
message_text = command_args[1] if not command_args[1][0] == ":" else \
text.replace("\r\n", "")[text.index(":")+1:]
src = self._clients[conn].get_identifier()
dest = command_args[0]
if not dest.startswith("#"):
for clnt in self._clients.values():
if clnt.nick == dest:
clnt.connection.send(
":%s %s %s :%s" % (src, command, dest, message_text)
)
break
else:
self._send_no_user(conn, dest)
else:
for chan in self._channels:
if chan.name == dest:
self._channel_broadcast(conn, chan, ":%s %s %s :%s" %
(src, command, dest, message_text))
break
else:
self._send_no_user(conn, dest)
elif command == "JOIN":
if len(command_args) < 1:
self._send_not_enough_parameters(conn, command)
elif not all(c in ALLOWED_CHANNEL for c in command_args[0]) and len(command_args[0]):
self._send_no_channel(conn, command_args[0])
else:
for chan in self._channels:
if chan.name == command_args[0]:
chan.users += 1
self._clients[conn].channels.append(chan)
self._send_to_related(conn, ":%s JOIN %s" % (self._clients[conn].get_identifier(),
chan.name), True)
self._send_topic(conn, chan)
self._send_names(conn, chan)
else:
chan = Channel(command_args[0], 1)
chan.users = 1 # We have a user, because we have created it!
self._channels.append(chan)
self._clients[conn].channels.append(chan)
self._clients[conn].send(":%s JOIN %s" % (self._clients[conn].get_identifier(),
command_args[0]))
elif command == "PART":
if len(command_args) < 1:
self._send_not_enough_parameters(conn, command)
else:
for chan in self._channels:
if chan.name == command_args[0]:
self._send_to_related(conn, ":%s PART %s" % (self._clients[conn].get_identifier(),
command_args[0]))
self._clients[conn].channels.remove(chan)
chan.users -= 1
break
...
Я писал сервер для IRC...
Больше говнокода: https://github.com/SopaXorzTaker/irc-server/
−422
import math
print math.pow(2,64) //1.84467440737e+19
print pow(2,64) //18446744073709551616
print 2**64 //18446744073709551616
http://ideone.com/kmGrBa
http://ideone.com/otSgCP
Говно в обоих версиях калькулятора.
+15
int getRandomNumber(){
int Number[1];
return Number[6];
}
//Я только учусь, поэтому не судите строго.
И кому теперь нужно srand(GetTickCount());
+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