- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
class ANameCreator
{
public:
virtual void Create(const std::string& /*name*/)
{
throw std::runtime_error("<ANameCreator::Create()> : abstract method stub call");
}
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+23
class ANameCreator
{
public:
virtual void Create(const std::string& /*name*/)
{
throw std::runtime_error("<ANameCreator::Create()> : abstract method stub call");
}
};
+18
//main.cpp:
#define THREAD_COUNT 2
#include "winparallel.h"
main1()
{
lock(1);
int i=0; while(i++<10)
printf("1: %d\n", i);
unlock(1);
}
main2()
{
lock(1);
int i=0; while(i++<10)
printf("2: %d\n", i);
unlock(1);
}
main3(){};
main4(){};
main5(){};
main6(){};
main7(){};
main8(){};
//=====================================================================================
//winparallels.h:
#include <windows.h>
#define _MAX_CORES 8
LPVOID _void;
#define main1() DWORD WINAPI _main1(LPVOID lpParam)
#define main2() DWORD WINAPI _main2(LPVOID lpParam)
#define main3() DWORD WINAPI _main3(LPVOID lpParam)
#define main4() DWORD WINAPI _main4(LPVOID lpParam)
#define main5() DWORD WINAPI _main5(LPVOID lpParam)
#define main6() DWORD WINAPI _main6(LPVOID lpParam)
#define main7() DWORD WINAPI _main7(LPVOID lpParam)
#define main8() DWORD WINAPI _main8(LPVOID lpParam)
DWORD WINAPI _main1(LPVOID);
DWORD WINAPI _main2(LPVOID);
DWORD WINAPI _main3(LPVOID);
DWORD WINAPI _main4(LPVOID);
DWORD WINAPI _main5(LPVOID);
DWORD WINAPI _main6(LPVOID);
DWORD WINAPI _main7(LPVOID);
DWORD WINAPI _main8(LPVOID);
HANDLE _locks[_MAX_CORES];
int _argc; char **_argv;
void lock(int n) { DWORD res = WaitForSingleObject(_locks[n], INFINITE); }
void unlock(int n) { ReleaseMutex(_locks[n]); }
int main(int argc,char **argv) {
HANDLE threads[_MAX_CORES];
DWORD id;
int THREADS = THREAD_COUNT;
if (THREADS<=0) {
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
THREADS = sysinfo.dwNumberOfProcessors;
if (THREADS>_MAX_CORES) THREADS = _MAX_CORES;
}
_argc = argc; _argv = argv;
_locks[0] = CreateMutex(NULL,FALSE,NULL);
_locks[1] = CreateMutex(NULL,FALSE,NULL);
_locks[2] = CreateMutex(NULL,FALSE,NULL);
_locks[3] = CreateMutex(NULL,FALSE,NULL);
_locks[4] = CreateMutex(NULL,FALSE,NULL);
_locks[5] = CreateMutex(NULL,FALSE,NULL);
_locks[6] = CreateMutex(NULL,FALSE,NULL);
_locks[7] = CreateMutex(NULL,FALSE,NULL);
threads[0]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main1,NULL,0,&id);
if (THREADS>=2)
threads[1]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main2,NULL,0,&id);
if (THREADS>=3)
threads[2]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main3,NULL,0,&id);
if (THREADS>=4)
threads[3]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main4,NULL,0,&id);
if (THREADS>=5)
threads[4]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main5,NULL,0,&id);
if (THREADS>=6)
threads[5]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main6,NULL,0,&id);
if (THREADS>=7)
threads[6]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main7,NULL,0,&id);
if (THREADS>=8)
threads[7]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)_main8,NULL,0,&id);
WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
return 0;
}
>После этого всё что нужно освоить про потоки - работу с локами. Локи - это скандинавский бог приостановки потока.
+7
class Pa || Ra || Ll || El
{
int f || o || o; // четвертое ядро простаивает - надо длиннее переменные заводить
int b || a || r;
}
int m || a || i || n(int argc, CHAR* argv[])
{
Parallel parallel = new Pa() || Ra() || Ll() || El ();
}
+153
$_SESSION["db_options"] = array ('host' => trim($this->IP).":".trim($this->Port),
'user' => trim($this->User),
'password' => trim($this->Pass),
'database' => trim($this->DB)
);
Наследование? Не, не слышал
+114
private List<PalletePath> killDupes(List<PalletePath> pathesNew) {
List<PalletePath> noDupes = new ArrayList<PalletePath>();
for (PalletePath tp : pathesNew) {
if (!noDupes.contains(tp)) {
noDupes.add(tp);
}
}
return noDupes;
}
Set? Не, не слышали.
−122
Если ВыгружатьВзаиморасчеты тогда
Если ВыгружатьВзаиморасчеты() тогда
УспешноВзаиморасчетыВыгружено=ВыгрузитьВзаиморасчетыНаСайт(СтруктураПараметровСайта);
КонецЕсли;
КонецЕсли;
Херово, когда имен не хватает =(
+154
$code_date = strtotime($sms_action_date);
$date = date(
"Y-m-d H:i:s",
mktime(
date('H', $code_date),
date('i', $code_date) + 30,
date('s', $code_date),
date("m", $code_date),
date("d", $code_date),
date("Y", $code_date)
)
);
Определяем +30 минут грамотно.
+74
private boolean userInOneRegistrationNode() throws DfException {
String uname = OrganizationStaffStructureHelper.getCurrentUserName();
int i = 0;
IDfCollection NodesCol = DQLHelper.getCollection(DQL_GET_REGISTRATOR_DIV, new String[]{uname});
while (NodesCol.next()) {
if (!(NodesCol == null)) {
String group_name = NodesCol.getString(GROUP_NAME);
i = i + 1;
}
}
if (i == 1) {
return true;
}
return false;
}
Заменяется 2мя строками один - select count(*), вторая - полученный результат Integer.ValueOf(...).
+140
[WebMethod]
public void runCompareService(string mAuthToken, int documentId, int origVerNum, int revisedVerNum)
{
//string result = null;
DirectoryInfo tmpDirInfo = getTempDirectoryPath(documentId);
try
{
//authToken = authClient.AuthenticateUser(username, password);
authToken = mAuthToken;
otAuth.AuthenticationToken = authToken;
try
{
string origFilePath = String.Format(tmpFilePath, tmpDirInfo.ToString(), origVerNum);
string revisedFilePath = String.Format(tmpFilePath, tmpDirInfo.ToString(), revisedVerNum);
string resultFilePath = String.Format(tmpResFilePath, tmpDirInfo.ToString(), origVerNum, revisedVerNum);
string origContextId = getDocContextId(documentId, origVerNum);
string revisedContextId = getDocContextId(documentId, revisedVerNum);
try
{
downlodFileByContextId(origContextId, origFilePath);
downlodFileByContextId(revisedContextId, revisedFilePath);
try
{
doCompare(origFilePath, revisedFilePath, resultFilePath);
try
{
DownloadToBrowser(resultFilePath);
//uploadResultToCS(targetId, resultFilePath);
}
catch (Exception e)
{
throw new Exception(String.Format("Failed to Download To Browser. Error: {0}", e.ToString()));
}
}
catch (Exception e)
{
throw new Exception(String.Format("Failed to do compare method . Error: {0}", e.ToString()));
}
}
catch (Exception e)
{
throw new Exception(String.Format("Failed to create and download file. Error: {0}", e.ToString()));
}
}
catch (Exception e)
{
throw new Exception("Failed to get Context ID for version Exeption details: " + e.ToString());
}
}
catch (Exception e)
{
throw new Exception("Failed to auth user. Exeption details: " + e.ToString());
}
finally
{
docManClient.Close();
contentServiceClient.Close();
if (Directory.Exists(tmpDirInfo.ToString()))
{
tmpDirInfo.Delete(true);
}
}
}
+106
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;
namespace SplitSpace {
class Program {
static void Main(string[] args) {
test();
}
static void test() {
if(testfun(0, 0, 3, 1020, 0.05*180/Utils.PI, 1, 40, 5.80020838542985, 5.80020838542985, 0.0125032560359095)) return;
if(testfun(0, 0, 3, 1020, 0.05*180/Utils.PI, 2, 5, 1.75, 9.85005209635745, 0.00156290700448869)) return;
if(testfun(0, 0, 3, 1020, 0.05*180/Utils.PI, 3, 1.5, 0.0375078144536192, 0.0375078144536192, 0.000468872101346607)) return;
if(testfun(0, 0, 3, 219, 0.00, 1, 15.000, 4.900000000, 4.900000000, 0.000000000)) return;
if(testfun(0, 0, 3, 219, 0.50, 1, 15.000, 4.900000415, 4.900000415, 0.000142791)) return;
if(testfun(0, 0, 3, 219, 5.00, 1, 15.000, 4.900415674, 4.900415674, 0.014290277)) return;
if(testfun(0, 0, 3, 219, 5.10, 1, 15.000, 4.900441130, 4.900441130, 0.014868082)) return;
if(testfun(0, 0, 3, 219, 5.90, 1, 15.000, 4.900683170, 4.900683170, 0.019903983)) return;
// Спустя 8369 строчек
// ...
// ...
// ...
if(testfun(2, 1, 4, 1420, 55.00, 2, 7.000, 5.512975201, 5.512975201, 1.316853521)) return;
if(testfun(2, 1, 4, 1420, 60.00, 2, 7.000, 5.817691454, 5.817691454, 1.558845727)) return;
if(testfun(2, 1, 4, 1420, 66.00, 2, 7.000, 6.589343466, 6.589343466, 1.708953962)) return;
if(testfun(2, 1, 4, 1420, 75.00, 2, 7.000, 7.385125168, 7.385125168, 2.367207113)) return;
if(testfun(2, 1, 4, 1420, 85.10, 2, 7.000, 8.438873737, 8.438873737, 3.248627191)) return;
if(testfun(2, 1, 4, 1420, 89.00, 2, 7.000, 8.848026526, 8.848026526, 3.610990132)) return;
if(testfun(2, 1, 4, 1420, 89.99, 2, 7.000, 8.932590260, 8.932590260, 3.699354242)) return;
if(testfun(2, 1, 4, 1420, 90.00, 2, 7.000, 8.932590181, 8.932590181, 3.700000000)) return;
MessageBox.Show("OK!");
}
static bool testfun(int dir, int coolType, int hotType, double dia, double angG, int angType, double Rad, double Tan1, double Tan2, double Bis) {
// тут всякие тесты
// ...
// ...
// ...
return false;
}
}
}