- 1
- 2
- 3
>ipconfig | find "IP"
═рёЄЁющър яЁюЄюъюыр IP фы Windows
IP-рфЁхё . . . . . . . . . . . . : 192.168.1.60
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−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
−138
ALTER TABLE `test` ENGINE MyISAM;
SELECT COUNT(*) FROM `test`;
ALTER IGNORE TABLE `test` ADD UNIQUE INDEX `dupidx` (`col1`, `col2`, ...);
SELECT COUNT(*) FROM `test`;
ALTER TABLE `test` DROP INDEX `dupidx`;
ALTER TABLE `test` ENGINE InnoDB;
На Говнокод не тянет. Но идея мне кажется говнистой. Задача удалить все записи с дубликатами значений в полях.
+73
int k = 0;
for (int i = 1; i<=str.length(); i++){
k = i;
}
System.out.println("dlina: "+k);
Счётчик длины строки....
+27
function makehash($str,$salt='',$strength='08'){
if (!$salt):
$salt = "";
for ($i = 0; $i < 22; $i++) {
$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1);
}
endif;
return crypt($str, "$2a$".$strength."$".$salt);
}
no comments
+4
int eval (const Expr& e)
{
Match(e)
Case(const Value& x) return x.value;
Case(const Plus& x) return eval (x.e1)+eval(x.e2);
Case(const Minus& x) return eval(x.e1)−eval(x.e2);
Case(const Times& x) return eval(x.e1)∗eval(x.e2);
Case(const Divide& x) return eval(x.e1)/eval (x.e2);
EndMatch
}
Бьёрн Страуструп выбирает борщ.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3449.pdf
http://www.linux.org.ru/forum/development/9525806
Заметим, что не только Страуструп раскаялся в прошлом. Кармак с энтузиазмом рассказывает, как с головой погрузился в Haskell и Scheme, объясняет, почему хаскель невероятно крут и почему сегодня он бы, вероятно, сделал QuakeScheme вместо QuakeC. Он пишет на хаскеле порт wolf3D.
+130
#include <stdio.h>
int main()
{
int a = 5, b = 6;
void* go;
go = ( a > b )? &&true1: &&false1;
goto *go;
true1:
{
printf("%i > %i\n", a, b);
goto next1;
}
false1:
{
printf("%i <= %i\n", a, b);
}
next1:
a = 7;
go = ( a > b )? &&true2: &&false2;
goto *go;
true2:
{
printf("%i > %i\n", a, b);
goto next2;
}
false2:
{
printf("%i <= %i\n", a, b);
}
next2:
return 0;
}
В GCC есть такой экстеншен http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
Можно в goto передавать переменную и можно работать с адресами меток. В сочетании с тернарной условной операцией, этим можно заменить if