Няшная / Говнокод #50 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
void DictionaryEnumeratorFunction(char *val, void *tag)
{
	DictionaryEnumeratorData ***data;
	data = (DictionaryEnumeratorData***) tag;

	(**data) = malloc(sizeof(DictionaryEnumeratorData));
	(**data)->val = malloc(0); /* O_o [комент добавлен много позднее] */
	strcpy((**data)->val, val);
	(**data)->next = NULL;
	*data = &((**data)->next);
}

Код, забивающий в массив данные из словаря (ассоциативного массива), путём рекурсивного обхода и вызова ЭТОГО. Писалось в 3 часа ночи.
На утро тихо матерился и переписывал всё

guest guest, (Updated )

Комментарии (14, +14)

Кресты / Говнокод #49 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
void ListViewCtrl::SetEditableColumn(int col, bool editable)
{
	while(col >= static_cast<int>(editableCols_.size()))
	{
		editableCols_.push_back(true);
	}
    editableCols_[col] = editable;
}

std::vector<bool> editableCols_;
вектор булов используется в ListView для того чтобы указать является ли столбец редактируемым...

p.s. польские паттерны)

guest guest, (Updated )

Комментарии (7, +7)

Jawa / Говнокод #48 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
public static Date createDate(Integer iYear, Integer iMonth, Integer iDay) throws Exception
    {
        if ((!(iYear instanceof Integer))
                || (!(iMonth instanceof Integer))
                || (!(iDay instanceof Integer))
                )
        {
            throw new Exception();
        }

        Date date = null;
        String year, month, day;

        year = iYear.toString();
        month = iMonth.toString();
        day = iDay.toString();
        try
        {
            date = new SimpleDateFormat("yyyy/MM/dd").parse(year + "/" + month + "/" + day);

        } catch (ParseException e)
        {
            log.warn("Date transformation failed for year, month, day:  " + iYear + ", " + iMonth + ", " + iDay);
        }
        return date;
    }

Индусы Рулят!!!

guest guest, (Updated )

Комментарии (25, +25)

Кресты / Говнокод #47 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
QString newText=text;               
if (weShouldIgnoreSpaces())         
        newText.replace(QString(" "),QString("%"));
delete modelAnswer;                                                                                     
delete modelQuestion;                                                                                   
modelAnswer = new QSqlQueryModel(0);                                                                    
modelQuestion = new QSqlQueryModel(0);                                                                  
questionOutput->setModel(modelQuestion);                                                                
answerOutput->setModel(modelAnswer);

Кусочек кода на C++/Qt, чтобы SQLite успевал закончить обработку прошлого запроса перед новым. Как ни странно помогало...

guest guest, (Updated )

Комментарии (1, +1)

ДействиеСценарий / Говнокод #44 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
/**
* создаем RemoteObject и регестрируем слушателей его метода sayLogin
* */
public function useLogonService():void
{
	logonService = new RemoteObject();
	logonService.destination = "amfphp";
	logonService.source = "ez_report.logon";
	logonService.sayLogin.addEventListener("result",resultHandler);
	logonService.addEventListener("fault", faultHandler);				
}
	
/**
 * после запуска модуля стартуем здесь все, что необходимо.
 * */
public function logonInit():void
{
	useLogonService();
	loginInput.setFocus();
}
	
/**
 * вызываем RO метод с параметрами из textinput,
 * который возвращает объект типа User, если регистрация прошла успешно.
 * */ 
public function sayLogin():void
{
	logonService.sayLogin(loginInput.text,passInput.text);	
}
			
//todo: ПЕРЕДЕЛАТЬ НАХЕР!!! УЁ..ИЩЕ!! все сделать через интерфейсы и события!
/**
 * присваиваем переменным в main.swf соответствующие значения
 * */ 
private function resultHandler(rs:ResultEvent):void
{
	parentApplication.login=loginInput.text;
	parentApplication.password=passInput.text;
	parentApplication.removeLogonModule();
}			

//todo: прикрутить, наконец, проверку типа ошибки.			
private function faultHandler(f:FaultEvent):void
{
	Alert.show(f.fault.faultString+f.fault.faultDetail+f.message.body.toString());
}

Crazy horse
Когда-то мной писалось и такое))
кошмар, конечно, но все на чем-то учатся.
Теперь особо радуют комментарии (AsDoc, как же,)
связь с parentApplication и отсутствие прокси.

guest guest, (Updated )

Комментарии (8, +8)

Кресты / Говнокод #43 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
static HRESULT SResToHRESULT(SRes res)
{
  switch(res)
  {
    case SZ_OK: return S_OK;
    case SZ_ERROR_MEM: return E_OUTOFMEMORY;
    case SZ_ERROR_PARAM: return E_INVALIDARG;
    case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;
    // case SZ_ERROR_PROGRESS: return E_ABORT;
    case SZ_ERROR_DATA: return S_FALSE;
  }
  return E_FAIL;
}

(c) 7z

guest guest, (Updated )

Комментарии (13, +13)