- 1
- 2
- 3
public static void assertAlmostEquals(final double actual, final double expected) {
Assert.assertTrue(Math.abs(actual - expected) < 0.000001);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+113
public static void assertAlmostEquals(final double actual, final double expected) {
Assert.assertTrue(Math.abs(actual - expected) < 0.000001);
}
−160
Процедура ЗАЕБАШИТЬЧТОБВСЕРАБОТАЛО ()
СООБЩИТЬ("Так не бывает!");
КонецПроцедуры
Из реального проекта крупного торгового дома.
+125
class OneAtATimePlease
{
private static object lok = new object();
static void Main()
{
Dictionary<int, string> d = new Dictionary<int, string>();
Thread t = new Thread(new ParameterizedThreadStart(Fill));
Thread t2 = new Thread(new ParameterizedThreadStart(Fill));
t.Start(d);
t2.Start(d);
t.Join();
t2.Join();
foreach (var i in d)
{
Console.WriteLine(i.Key + " " + i.Value);
}
}
public static void Fill(object lo)
{
Dictionary<int, string> d = (Dictionary<int, string>)lo;
for (int i = 0; i < 10; i++)
{
Random r = new Random(i*4);
int v = r.Next(0, 10);
if (!d.ContainsKey(v))
{
lock (lok)
{
d.Add(v, "Hello from thread: " + Thread.CurrentThread.ManagedThreadId);
}
}
}
}
}
+154
if(!empty($_POST['action']) && !empty($_POST['product_id']))
{
$product_id=$_POST['product_id']+0;
etc...
}
Наткнулся вот!)
+12
class Thread
{
public:
Thread(const Thread&);
Thread() : handle(NULL), running(false), finished(false)
{
handle = (HANDLE)(_beginthreadex(NULL, 0, &(Thread::threadRun), this, CREATE_SUSPENDED, NULL));
}
~Thread()
{
if(isRunning()) {
TerminateThread(handle, 0);
}
CloseHandle(handle);
}
void start(void* arg)
{
if(isRunning() || isFinished()) {
throw Exception("Thread is running or finished!");
} else {
this->arg = arg;
ResumeThread(handle);
}
}
void pause()
{
if(isRunning()) {
SuspendThread(handle);
} else {
throw Exception("Thread is not running or finished!");
}
}
void resume()
{
if(!(isRunning())) {
throw Exception("Thread is finished!");
} else {
ResumeThread(handle);
}
}
void stop()
{
if(isRunning()) {
TerminateThread(handle, 0);
running = false;
finished = true;
throw Exception("Thread stopped!");
} else {
throw Exception("Thread is not running or finished!");
}
}
void setPriority(ThreadPriority priority)
{
if(isFinished()) {
throw Exception("Thread is finished!");
} else {
switch(priority) {
case ThreadPriorityLow:
SetThreadPriority(handle, THREAD_PRIORITY_LOWEST);
break;
case ThreadPriorityNormal:
SetThreadPriority(handle, THREAD_PRIORITY_NORMAL);
break;
case ThreadPriorityHigh:
SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
break;
default:
throw Exception("Invalid priority!");
break;
}
}
}
bool isRunning()
{
return (running);
}
bool isFinished()
{
return (finished);
}
protected:
virtual void run(void *arg) = 0;
private:
static unsigned int __stdcall threadRun(void *arg)
{
Thread *thread = static_cast<Thread*>(arg);
thread->running = true;
thread->run(thread->arg);
thread->running = false;
thread->finished = true;
_endthreadex(0);
return (0);
}
void *arg;
HANDLE handle;
bool running;
bool finished;
};
Из предыдущей оперы.
−116
СтрокаСуммаСРазделителями = Строка(ТекСсылка.СуммаДокумента);
СтрокаСуммаБезРазделителей = СтрЗаменить(СтрокаСуммаСРазделителями, СимволРазделительСуммы, "");
Видать, использование "Формат" запрещено внутренней политикой =(
+160
$("#pastas").on('change', function () {
var myString = $("#pastas").val();
var myArray = myString.split('');
// display the result in myDiv
for (var i = 0; i < myArray.length; i++) {
if (myArray[i] == "@") {
skai++;
} else if (myArray[i] == ".") {
skai++;
}
}
if (skai == 2) {
$('#pastas').removeClass('blogai');
console.log('gerai');
} else {
$('#pastas').addClass('blogai');
console.log('blogai');
}
});
Валидность почты по Литовски...
+152
var retriesLeft = 100;
while (true)
{
try
{
return SetRestorePoint(0, pointType, enentType, description);
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode != ErrorServiceDisabled || retriesLeft < 0)
throw;
Thread.Sleep(500);
retriesLeft--;
}
}
+128
wr = new StreamWriter(fs);
wr.WriteLine(string.Format("{0}", toPrint));
+136
http://odnoklassniki.ru/dk
?cmd=PopLayer
&tkn=9739
&st.cmd=error
&st.stid=anonymPasswordRecovery
&st.eclass=java.lang.IllegalStateException
&st.layer.cmd=PopLayerSystemError
Парсер тоже видит ЭТО и предлагает положить в не «Кучу», а в «Java».