- 1
- 2
- 3
- 4
- 5
- 6
</td>
</tr>
<br style="clear:both" />
<tr id="rand_<?=$cc?>">
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+116
</td>
</tr>
<br style="clear:both" />
<tr id="rand_<?=$cc?>">
а вдруг строки - это не совсем строки о_О
+116
var result = resultDate.ToString("yyyy-MM-dd");
result = result.Replace("-", "");
+116
public void Parse(string sqlScript)
{
batches = new List<string>();
State state = State.WaitingGO;
StartNewBatch();
for(position = 0; position < sqlScript.Length; position++)
{
char c = sqlScript[position];
if(state == State.WaitingGO)
{
PutToBuffer(c);
if(IsWhiteSpace(c) || IsEndOfLineCharacter(c)) continue;
else if(c == 'g' || c == 'G') state = State.ReadingGO;
else
{
state = State.ReadingBatch;
FlushBuffer();
}
}
else if(state == State.ReadingGO)
{
PutToBuffer(c);
if(c == 'o' || c == 'O') state = State.ReadedGO;
else if(IsEndOfLineCharacter(c))
{
state = State.WaitingGO;
FlushBuffer();
}
else
{
state = State.ReadingBatch;
FlushBuffer();
}
}
else if(state == State.ReadedGO)
{
if(IsWhiteSpace(c) || IsEndOfLineCharacter(c))
{
state = State.WaitingGO;
FinishBatch();
StartNewBatch();
}
else
{
state = State.ReadingBatch;
PutToBuffer(c);
FlushBuffer();
}
}
else if(state == State.ReadingBatch)
{
PutToBatch(c);
if(IsEndOfLineCharacter(c)) state = State.WaitingGO;
}
}
if(state != State.ReadedGO) FlushBuffer();
FinishBatch();
}
private enum State
{
WaitingGO,
ReadingGO,
ReadedGO,
ReadingBatch
}
Требовалось распарсить string с sql-текстом на отдельные транзакции (т.е. просто разбить текст по go).
Функции для работы с Batch-ем не привожу и так уйма говнокода
+116
for m:=0 to 9 do
mas[m]:=inttostr(m);
if ((Form1.edit1.text='')or(Form1.Memo2.text='')) then begin
if Form1.Memo2.text='' then
ShowMessage('Ошибка! Введите пожалуйста текст или подключите файл,который необходимо расшифровать!!!');
if Form1.edit1.text='' then
ShowMessage('Ошибка! Введите пожалуйста ключ,которым будет расшифрован текст!!!');
end
else begin
//проверка ключа
key:=Form1.edit1.text;
k:=length(key);
c:=0;
k_p:=true;
for j:=1 to k do
for m:=0 to 9 do begin
if (key[j]=mas[m]) then
inc(c)
else Begin
if (m=9) then
if (c=0) then Begin
ShowMessage('Ошибка!!!Введите пожалуйста ключ,которым будет расшифрован текст-целые числа');
k_p:=false;
end
else
c:=0;
end;
end;
end;
говнокриптография...
+116
class DllContainer
{
DllContainer()
{
// тут грузятся дллки в количестве N.
// LoadLibrary() + некоторые операции
}
~DllContainer()
{
// FreeLibrary() и т.п.
}
template <class T>
T* GetComponent(ComponentID id)
{
// аналог QueryInterface.
// ищет компонент, проверяет можно ли статик_кастить
// и вертает указатель нужного типа
}
};
class ComponentUser
{
void Method1()
{
DllContainer loader;
SomethingDoer* comp = loader.GetComponent<SomethingDoer>(ID1);
comp->DoSomething();
}
void Method2()
{
DllContainer loader;
SomethingElseDoer* comp = loader.GetComponent<SomethingElseDoer>(ID2);
comp->DoSomethingElse();
}
void MethodN()
{
DllContainer loader;
ShitPerformer* comp = loader.GetComponent<ShitPerformer>(IDN);
comp->PerformSomeShit();
}
};
недавно обнаружил код примерно такого плана.
крупный коммерческий проект...
+116
struct Epica
{
public:
signed int Value;
};
//...
Epica* ValEp[10][17];
//...
ValEp[i][jj][0].Value;
Угадайте, что с автором?
+115.9
function TFilesStrings.LastSlash(FileString: string): byte;
{*
Функция для вычисления положения последнего слеша в строке
*}
var
i: byte;
begin
Result := 0;
for i := 1 to Length(FileString) do
if (FileString[i] = #92) then Result := i;
end;
{==============================================================================}
{******************************************************************************}
function TFilesStrings.GetPath(FullFileName: string): string;
{*
Функция возвращает оконечный путь у заданному Файлу
*}
var
SlNum: byte;
begin
Result := '';
SlN um := LastSlash(FullFileName);
Result := Copy(FullFileName, 1, SlNum);
end;
Вот ещё вспомнил... Не мог понять почему у меня не работает функция ExtractFilePath, пришлось писать вручную :)
+115.7
(defun create (a) ;; список из составляющих атомов списка A
(cond
((null a) nil)
((atom a) (list a))
(T (append (create (car a)) (create (cdr a))))
)
)
(defun uniq (a) ;; оставить только уникальные атомы
(cond
((null a) nil)
((member (car a) (cdr a)) (uniq (cdr a)))
(t (cons (car a) (uniq (cdr a))))
)
)
(defun compare (a b) ;; сравнение состава списков
(if (= (length a) (length b))
(diff a b)
nil
)
)
(defun diff (a b) ;; проверка состава 2x списков
(cond
((null a) T)
(T (if (member (car a) b)
(diff (cdr a) b)
nil )
)
)
)
(defun main (a b)
(compare
(uniq (create a))
(uniq (create b))
)
)
а нужно было всего то проверить состоят ли 2 списка из одних и тех же атомов
+115.4
public partial class AbstractPickerBrw : Form
{
//...
public AbstractPickerBrw ()
{
this.Shown += new System.EventHandler(this.AbstractPickerBrw_Shown);
}
//...
private void AbstractPickerBrw_Shown(object sender, System.EventArgs e)
{
Width = Width % 2 == 0 ? Width + 1 : Width - 1;
}
}
Это мой код, просто не мог добиться перерисовки диалога при смене данных в WinForms и решил не заморачиваться.
+115.2
class TReadWrapper<TItemType>
{
public static object item(string ItemString)
{
if (typeof(TItemType) == typeof(double))
return Convert.ToDouble(ItemString);
TDbg.Assert(false);
return null;
}
};
class TRead<TItemType>
{
public static TItemType item(StreamReader BinaryStream)
{
string ItemString = BinaryStream.ReadLine();
if (ItemString == null)
throw new Exception();
return (TItemType)TReadWrapper<TItemType>.item(ItemString);
}
};
class TFileToList<TListItem> : List<TListItem>
{
public TFileToList(string FileName)
{
if(typeof(TListItem)==typeof(char))
{
StreamReader file = new StreamReader(FileName, Encoding.Unicode);
string FileData = file.ReadToEnd();
foreach (char item in FileData)
this.Add((TListItem)(object)item);
file.Close();
return;
};
StreamReader fileSource = new StreamReader(FileName, Encoding.Unicode);
try
{
for (;;)
this.Add(TRead<TListItem>.item(fileSource));
}
catch
{
};
fileSource.Close();
}
}
class TListToFile<TListItem>
{
static public void rewrite(string NameOfDestinationFile, List<TListItem> Source)
{
if(typeof(TListItem)==typeof(char))
{
StreamWriter file = new StreamWriter(NameOfDestinationFile, false, Encoding.Unicode);
foreach (TListItem item in Source)
file.Write(item);
file.Flush();
file.Close();
return;
};
StreamWriter fileDestination = new StreamWriter(NameOfDestinationFile, false, Encoding.Unicode);
foreach (TListItem item in Source)
fileDestination.WriteLine(Convert.ToString(item));
fileDestination.Flush();
fileDestination.Close();
}
}