- 1
cooldownTime.add(14, (int)(cooldown * 1000.0D % 1000.0D));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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.
+128
if (f > 1) { }
else
chart5.Series[1].Points.AddXY(i, f);
Было замечено за коллегой
+81
// -1 esli NotFound, snachala massiv potom element
static int najtiElementVMassive(Object massiv,Object element){
if(massiv instanceof int[]) {
for(int i=0; i<((int[])massiv).length; ++i)
if(((int[])massiv)[i]==(int)element)
return i;
} else if(massiv instanceof byte[]) {
for(int i=0; i<((byte[])massiv).length; ++i)
if(((byte[])massiv)[i]==(byte)element)
return i;
} else if(massiv instanceof boolean[]) {
for(int i=0; i<((boolean[])massiv).length; ++i)
if(((boolean[])massiv)[i]==(boolean)element)
return i;
} else if(massiv instanceof char[]) {
for(int i=0; i<((char[])massiv).length; ++i)
if(((char[])massiv)[i]==(char)element)
return i;
} else if(massiv instanceof float[]) {
for(int i=0; i<((float[])massiv).length; ++i)
if(((float[])massiv)[i]==(float)element)
return i;
} else if(massiv instanceof double[]) {
for(int i=0; i<((double[])massiv).length; ++i)
if(((double[])massiv)[i]==(double)element)
return i;
} else if(massiv instanceof short[]) {
for(int i=0; i<((short[])massiv).length; ++i)
if(((short[])massiv)[i]==(short)element)
return i;
} else if(massiv instanceof long[]) {
for(int i=0; i<((long[])massiv).length; ++i)
if(((long[])massiv)[i]==(long)element)
return i;
} else {
try {
for(int i=0; i<((Object[])massiv).length; ++i)
if(sravnitMassivi(((Object[])massiv)[i],element))
return i;
} catch (Exception e) {
for(int i=0; i<((Object[])massiv).length; ++i)
if((((Object[])massiv)[i]).equals(element))
return i;
}
}
return -1;
}
static boolean sravnitMassivi(Object massiv1,Object massiv2) {
try {
if((((Object[])massiv1)).length!=(((Object[])massiv2)).length) return false;
boolean ravni=true;
for(int i=0; i<(((Object[])massiv1)).length; ++i)
ravni=ravni&&sravnitMassivi((((Object[])massiv1))[i],(((Object[])massiv2))[i]);
return ravni;
} catch (Exception e) {
if(massiv1 instanceof int[]) {
return Arrays.equals((int[])massiv1,(int[])massiv2);
} else if(massiv1 instanceof byte[]) {
return Arrays.equals((byte[])massiv1,(byte[])massiv2);
} else if(massiv1 instanceof boolean[]) {
return Arrays.equals((boolean[])massiv1,(boolean[])massiv2);
} else if(massiv1 instanceof char[]) {
return Arrays.equals((char[])massiv1,(char[])massiv2);
} else if(massiv1 instanceof float[]) {
return Arrays.equals((float[])massiv1,(float[])massiv2);
} else if(massiv1 instanceof double[]) {
return Arrays.equals((double[])massiv1,(double[])massiv2);
} else if(massiv1 instanceof short[]) {
return Arrays.equals((short[])massiv1,(short[])massiv2);
} else if(massiv1 instanceof long[]) {
return Arrays.equals((long[])massiv1,(long[])massiv2);
} else {
return massiv1.equals(massiv2);
}
}
}
поиск элемента в массиве
http://ideone.com/iqNA7l
+150
public function responsive()
{
$month = array("1" => "Responsive", "2" => "Unresponsive");
for ($i = 1; $i <= 2; $i++)
{
$data[] = array('text' => $month[$i], 'value' => $i);
}
echo json_encode($data);
}
Мне кажеться индусы пишут лучше