- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
if (needParce)
{
try
{
count = decimal.Parse(tb_count.Text.Replace(".", ","));
}
catch
{
count = decimal.Parse(tb_count.Text.Replace(",", "."));
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+108
if (needParce)
{
try
{
count = decimal.Parse(tb_count.Text.Replace(".", ","));
}
catch
{
count = decimal.Parse(tb_count.Text.Replace(",", "."));
}
}
−127
Function Розница()
If Покупатель.Выбран() = 1 Then
If Покупатель.Вид() = "ПунктДоставки" Then
If Покупатель.Владелец.ТипЦенОтгрузки = Enum.ТипыОтпускныхЦен.Розничные Then
Return 1;
Else
Return 0;
EndIf;
Else
Return 0;
EndIf;
Else
Return 0;
EndIf;
EndFunction
Сегодня наткнулся на такой вот кусок кода
+136
// Определить тип ОС
string OSVersion = null;
try
{
try
{
OSVersion = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\", "ProductName", "").ToString();
}
catch (NullReferenceException)
{
OSVersion = "";
}
}
catch (SecurityException)
{
OSVersion = "";
}
finally {} // иначе при вложенном try ошибка
Говницо собственного производства, когда учился программировать на первой работе.
+75
cooldownTime.add(14, (int)(cooldown * 1000.0D % 1000.0D));
...
+160
elem.innerPHP
Интересно, почему же не работает?..
+74
class A {
public String[] newString = new String[0];
}
Пользуйтесь на здоровье :)
+96
Var
h : THandle;
procedure TMain.FormCreate(Sender: TObject);
begin
begin
h := CreateMutex(nil, True, PChar(ExtractFileName(Application.ExeName)));
if WaitForSingleObject(h, 0)<>0 then
begin
ShowMessage(‘Программа уже запущена!’);
Application.Terminate;
CloseHandle(h);
end;
end;
http://moron.1side.ru/programmirovanie/delphi/zapret-povtornogo-zapuska-programmy.php
+83
initialization
//done this way so we can have a separate stack just for FPC under Unix systems
GStackClass :=
{$IFDEF USE_VCL_POSIX}
TIdStackVCLPosix
{$ELSE}
{$IFDEF UNIX}
{$IFDEF KYLIXCOMPAT}
TIdStackLibc
{$ENDIF}
{$IFDEF USE_BASEUNIX}
TIdStackUnix
{$ENDIF}
{$ENDIF}
{$IFDEF WINDOWS}
TIdStackWindows
{$ENDIF}
{$IFDEF DOTNET}
TIdStackDotNet
{$ENDIF}
{$ENDIF}
;
GStackCriticalSection := TIdCriticalSection.Create;
{$IFNDEF DOTNET}
{$IFDEF REGISTER_EXPECTED_MEMORY_LEAK}
IndyRegisterExpectedMemoryLeak(GStackCriticalSection);
{$ENDIF}
{$ENDIF}
finalization
// Dont Free. If shutdown is from another Init section, it can cause GPF when stack
// tries to access it. App will kill it off anyways, so just let it leak
{$IFDEF FREE_ON_FINAL}
FreeAndNil(GStackCriticalSection);
{$ENDIF}
end.
Выдержка из IdStack.pas. Без комментариев.
Предыcтория.
fastmm постоянно сообщал об утечках памяти в моих программах, использующих Indy: решил разобраться.
Оказалось, что ошибки возникали при использовании IdStack, по умолчанию этот модуль используют почти все компоненты из палитры.
+160
var a = [1,2,3,4,5,6,7,8,9];
document.write('1' + '!='+ a[0] + '<br>');
document.write('2' +'!=' + a[0] * a[1] + '<br>');
document.write('3' +'!=' + a[0] * a[1] * a[2] + '<br>');
document.write('4' +'!=' + a[0] * a[1] * a[2] * a[3] + '<br>');
document.write('5' +'!=' + a[0] * a[1] * a[2] * a[3] * a[4] + '<br>');
document.write('6' +'!=' + a[0] * a[1] * a[2] * a[3] * a[4] * a[5] + '<br>');
document.write('7' +'!=' + a[0] * a[1] * a[2] * a[3] * a[4] * a[5] * a[6] + '<br>');
document.write('8' +'!=' + a[0] * a[1] * a[2] * a[3] * a[4] * a[5] * a[6] * a[7] + '<br>');
document.write('9' +'!=' + a[0] * a[1] * a[2] * a[3] * a[4] * a[5] * a[6] * a[7] * a[8] + '<br>');
Таблица факториалов до 9
−136
/**
* @private
* Calculates the height needed for heightInLines lines using the default
* font.
*/
private function calculateHeightInLines():Number
{
var height:Number = getStyle("paddingTop") + getStyle("paddingBottom");
if (_heightInLines == 0)
return height;
var effectiveHeightInLines:int;
// If both height and width are NaN use 10 lines. Otherwise if
// only height is NaN, use 1.
if (isNaN(_heightInLines))
effectiveHeightInLines = isNaN(_widthInChars) ? 10 : 1;
else
effectiveHeightInLines = _heightInLines;
// Position of the baseline of first line in the container.
value = getStyle("firstBaselineOffset");
if (value == lineHeight)
height += lineHeight;
else if (value is Number)
height += Number(value);
else
height += ascent;
// Distance from baseline to baseline. Can be +/- number or
// or +/- percent (in form "120%") or "undefined".
if (effectiveHeightInLines > 1)
{
var value:Object = getStyle("lineHeight");
var lineHeight:Number =
RichEditableText.getNumberOrPercentOf(value, getStyle("fontSize"));
// Default is 120%
if (isNaN(lineHeight))
lineHeight = getStyle("fontSize") * 1.2;
height += (effectiveHeightInLines - 1) * lineHeight;
}
// Add in descent of last line.
height += descent;
return height;
}
Внимательно следим за жизненным циклом переменной lineHeight.