- 1
var war;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+167
var war;
Объявляем войну :)
Не говнокод, но весело.
+130
char unsigned c;
DWORD m;
DWORD n;
int i = 0;
BOOL b = TRUE;
HANDLE hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not open File");
return NULL;
}
// узнаем размер файла
while (b)
{
b = ReadFile(hFile, &c, 1, &m, NULL);
if (m == 0)
{
printf("STOP ");
printf("%i\n", i);
break;
}
i++;
}
собственно узнаем размер файла, что тут еще скажешь)
+143
Hello, <em>ujkbktj</em>!<br />
<br />
Пользователь <a href="http://govnokod.ru/user/1997">istem</a> ответил на Ваш комментарий к <a href="http://govnokod.ru/5120">говнокоду #5120</a>!<br />
<br />
Напомним, Вы <a href="http://govnokod.ru/5120#comment66331">написали</a>:<br />
<em><span style="text-decoration:blink;">это не код!!</span></em><br />
<br />
На что получили <a href="http://govnokod.ru/5120#comment66347">ответ</a>:<br />
<em>И чё ж у Вас айдишник-то не 666...</em>
<br /><br /><br />
С уважением, Ваш <a href="http://govnokod.ru">Говнокод</a>.
...
+161
// If iMode!=0, non-blocking mode is enabled.
u_long iMode=1;
ioctlsocket(Socket,FIONBIO,&iMode);
// Main loop
for(;;)
{
// Display message from server
char buffer[1000];
memset(buffer,0,999);
int inDataLength=recv(Socket,buffer,1000,0);
std::cout<<buffer;
int nError=WSAGetLastError();
if(nError!=WSAEWOULDBLOCK&&nError!=0)
{
std::cout<<"Winsock error code: "<<nError<<"\r\n";
std::cout<<"Server disconnected!\r\n";
// Shutdown our socket
shutdown(Socket,SD_SEND);
// Close our socket entirely
closesocket(Socket);
break;
}
Sleep(1000);
}
http://www.win32developer.com/tutorial/winsock/winsock_tutorial_3.shtm
Вот как нада работать с сокетами... (строка 27).
+168
function getAlphabetList($list = null)
{
$alphabet = split(' ', 'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z');
foreach($alphabet as $letter)
{
$has_letter = false;
if(is_array($list))
{
foreach ($list as $value)
{
if(substr(strtoupper($value),0,1) == strpos($letter,$value,1))
{
$has_letter = true;
}
}
}
if($has_letter)
{
$output .= '<a href="?letter='.$letter.'">'.$letter.'</a> ';
} else {
$output .= $letter.' ';
}
}
return $output;
}
Шерстим список записей, определяем, на какие буквы они начинаются, и для имеющихся букв генерируем гиперссылки. Мужика попросили разобраться, почему каталог на 126000 записей тормозит при отображении, и он увидел в коде это.
http://thedailywtf.com/Articles/Thorough-Letter-Checking.aspx
+180
$cfg['day'] = array(
1 => '1',
2 => '2',
3 => '3',
4 => '4',
5 => '5',
6 => '6',
7 => '7',
8 => '8',
9 => '9',
10 => '10',
11 => '11',
12 => '12',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
21 => '21',
22 => '22',
23 => '23',
24 => '24',
25 => '25',
26 => '26',
27 => '27',
28 => '28',
29 => '29',
30 => '30',
31 => '31'
);
Чего только не встретишь в самописных движках, даже вот такой конфиг :)
+145
if (!defined(DIRECTORY_SEPARATOR)) {
$sep = (substr(strtolower(PHP_OS),0,3) == 'win') ? '\\' : '/';
define('DIRECTORY_SEPARATOR', $sep);
}
Даже если и так, то может быть и MAC OS'овский разделитель учтём???
Я-то думал обычный slash - решение всех проблем, или на МАКАХ подавляющее
число хостингов что ли?
+157
// (c) Template Optimizer
// (c) Template Compiler
// skin/news.tpl
/*<?php
die ('<br /><br />Template Parser: <b>Access locked</b>');
?>*/
$value0 = '
';
if ( $this->get_tpl_tag ('USER.ACCESS') == '1' )
{
$value0 .= '
';
$this->set_tpl_tag ('ACTION', 'new_add');
$value0 .= '
';
$this->set_tpl_tag ('SUBMIT', 'Добавить');
$value0 .= '
';
$this->set_tpl_tag ('CAPTION', 'Добавить новость');
$value0 .= '
' . $this->file_include ('content.tpl') . '
';
}
$value0 .= '
';
$this->open_local (array ('NEW'));
if ( is_array ($this->get_tpl_tag ('NEWS')) )
foreach ( $this->get_tpl_tag ('NEWS') as $this->tags['NEW'] )
{
$value0 .= '
<table class="news" width="100%">
<tr>
<th>
<h2>' . $this->get_tpl_tag ('NEW.TITLE') . '</h2>
</th>
<th align="right">
<span class="gensmall">' . $this->get_tpl_tag ('NEW.TIME') . ' </span>
';
if ( $this->get_tpl_tag ('USER.ACCESS') == '1' )
{
$value0 .= '
<a href="admin.php?action=new_edit&new=' . $this->get_tpl_tag ('NEW.ID') . '"><img src="' . $this->root_dir . '/images/rename.gif" alt="Редактировать" title="Редактировать" style="vertical-align: middle; border: none;" /></a>
<a href="admin.php?action=new_delete&new=' . $this->get_tpl_tag ('NEW.ID') . '" onclick="return confirm (\'Удалить новость за ' . $this->get_tpl_tag ('NEW.TIME') . '?\');"><img src="' . $this->root_dir . '/images/delete.gif" alt="Удалить" title="Удалить" style="vertical-align: middle; border: none;" />
';
}
$value0 .= '
</th>
</tr>
<tr>
<td colspan="2">
' . $this->get_tpl_tag ('NEW.BODY') . '
</td>
</tr>
</table>
';
}
$this->close_local();
$value0 .= '
';
$this->set_tpl_tag ('_ALIGN_', 'LEFT');
$value0 .= '
' . $this->file_include ('pagebar.tpl');
Вот такой "говнокод" выдает мой шаблонизатор после компилирования шаблона.
В данном примере это блок новостей.
+111
procedure TForm1.Timer1Timer(Sender: TObject);
function UpTime(sf:string):boolean;
var time:string;
t:textfile;
begin
if form1.MaskEdit5.Text<>'' then
if Findmas_u(255,0,sf)<0 then
begin UpTime:=false;exit;end;
if not FileExists(sf) then
begin UpTime:=false;exit;end;
time:=DateUpdating_u(sf);
if time<>'' then
begin
try
assignfile(t,ExtractFilePath(form1.MaskEdit1.Text)+ChangeFileExt(ExtractFileName(sf),'.tim'));
rewrite(t);
writeln(t,time);
closefile(t);
except UpTime:=false;exit;end;
end;
UpTime:=true;
end;
var x,y,i1,i2,i3,xf,yf:integer;
sf,id,ff:string;
b:boolean;
begin
form1.Timer1.Enabled:=not form1.Timer1.Enabled;
try
form1.ProgressBar1.Position:=0;
application.ProcessMessages;
masopt_u(254,x,y);
if form1.MaskEdit1.Text='' then
form1.BitBtn3.Click else
if (DateUpdating_u(form1.MaskEdit1.Text)<>DateUpdatingMas_u(254))or(y>0) then
begin
if form1.MaskEdit3.Text<>'' then
if form1.CheckBox1.Checked then
sf:=TJ7PassAutentikR_u(form1.MaskEdit3.Text,form1.MaskEdit2.Text) else
sf:=TJ7PassAutentik_u(form1.MaskEdit3.Text,form1.MaskEdit2.Text) else
sf:=form1.MaskEdit2.Text;
if not OpenOneNu_u(form1.MaskEdit1.Text,'read:PSQL-Srv'+booltostr(form1.RadioButton2.Checked),3) then
begin
DeleteFile(ChangeFileExt(form1.MaskEdit1.Text,'.tmp'));
form1.RichEdit1.Lines.Add('('+datetostr(date)+' '+timetostr(time)+') Превышен интервал времени доступа.');
OpenOneNu_u(form1.MaskEdit1.Text,'read:PSQL-Srv'+booltostr(form1.RadioButton2.Checked),3);
end;
i1:=TJ7ReadMas_u(254,form1.MaskEdit1.Text,sf);
CloseOneNu_u(form1.MaskEdit1.Text,'read:PSQL-Srv'+booltostr(form1.RadioButton2.Checked));
if (i1<>0)and(i1<>11) then
begin
form1.RichEdit1.Lines.Add('('+datetostr(date)+' '+timetostr(time)+') Ошибка чтения команд, код: '+inttostr(i1)+'.');
closemas_u(254);
initmas_u(254,2,0);
TJ7CreateMas_u(254,form1.MaskEdit1.Text,sf,false,false,false,false,false);
closemas_u(254);
form1.Timer1.Enabled:=not form1.Timer1.Enabled;
exit;
end;
masopt_u(254,x,y);id:='';
if not form1.RadioButton1.Checked then
begin
for i1:=0 to y-1 do
if (masr_u(254,1,i1)<>'') then
if ((form1.RadioButton2.Checked)and(ord(masr_u(254,1,i1)[1])mod 2=0))or
((form1.RadioButton3.Checked)and(ord(masr_u(254,1,i1)[1])mod 2<>0))then
begin id:=masr_u(254,1,i1);break;end;
end else id:=masr_u(254,1,0);
if (id='')or(y=0) then
begin
if RTime_u(strtodatetime(DateUpdatingMas_u(254)),date+time)<1200 then
closemas_u(254);
form1.Timer1.Enabled:=not form1.Timer1.Enabled;
exit;
end;
if y>0 then form1.StaticText13.Caption:='в обработке';
application.ProcessMessages;
form1.RichEdit1.Lines.Add('('+datetostr(date)+' '+timetostr(time)+'/Старт):'+id);
if form1.CheckBox3.Checked then
begin
masopt_u(255,xf,yf);
ff:=ExtractFilePath(form1.MaskEdit1.Text)+id+'.tj7';
masw_u(255,0,yf,ff);
end;
application.ProcessMessages;
if form1.MaskEdit6.Text<>'' then
PsevdoSQL_u(form1.MaskEdit6.Text);
for i1:=0 to y-1 do
if masr_u(254,1,i1)=id then
begin
if form1.CheckBox3.Checked then
begin
i2:=pos('TId',masr_u(254,0,i1));
if i2>0 then
masw_u(254,0,i1,copy(masr_u(254,0,i1),1,i2-1)+id+copy(masr_u(254,0,i1),i2+3,255));
end;
// *** И дальше в том же духе
Автор сего поделия, кусок которого приведён выше (привёл бы полностью, но там 160 строк), называет ЭТО "сервером распределённых вычислений" и "самой прогрессивной СУБД в мире, которая лучше всех этих ваших ораклов. При этом автор вроде как и не школьник...
+145
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
int Sum (int x, int y)
{
cout << "Принято " << x << " и " << y << "\n";
return (x+y);
}
int Frac (int x, int y)
{
cout << "Принято " << x << " и " << y << "\n";
return 0;
}
int Diff (int x, int y)
{
cout << "Принято " << x << " и " << y << "\n";
return (x-y);
}
int Multiplic (int x, int y)
{
cout << "Принято " << x << " и " << y << "\n";
return (x*y);
}
void Exiting ()
{
cout << "\nДля выхода из приложения нажмите любую клавишу...";
_getch();
}
void Call ()
{
cout << "\nВведите 2 числа через пробел и нажмите Enter: ";
}
int main()
{
setlocale(LC_ALL,"RUS");
int a,b,c,k;
cout << "Данный калькулятор может выполнять операции только над целыми числами.\n(c) 2010 - Конфиденциальность. All Rights Reserved.\n";
cout << "\nВыберите, что вы хотите сделать с числами: \n1-Сложить, 2-Вычесть, 3-Умножить, 4-Разделить \n"; cin >> k;
switch (k)
{
case 1: int Sum(); break;
case 2: int Diff(); break;
case 3: int Multiplic(); break;
case 4: int Frac(); break;
default: cout << "Вариант не выбран! \n"; return 1;
}
if (k==1){
Call();
cin >> a;
cin >> b;
c=Sum(a,b);
cout << "\nРЕЗУЛЬТАТ: " << c;
cout << "\n";
Exiting ();
return 0;
}
if (k==2){
Call();
cin >> a;
cin >> b;
c=Diff(a,b);
cout << "\nРЕЗУЛЬТАТ: " << c;
cout << "\n";
Exiting ();
return 0;
}
if (k==3){
Call();
cin >> a;
cin >> b;
c=Multiplic(a,b);
cout << "\nРЕЗУЛЬТАТ: " << c;
cout << "\n";
Exiting ();
return 0;
}
if (k==4){
Call();
cin >> a;
cin >> b;
if (b==0){
cout << "\nДеление на 0 невозможно!\n";
Exiting ();
return 0;
}
Frac(a,b);
cout << "\nРЕЗУЛЬТАТ: " << (float) a/b;
cout << "\n";
Exiting ();
return 0;
}
}
я только учусь языку C++.
и это один из первых моих кодов)
это примитивный калькулятор
возможно спецы вдоволь поржут с такого кода.. :))