- 1
- 2
- 3
- 4
- 5
- 6
- 7
...
$personInfos = $query->getResult();
foreach ($personInfos as $personInfo) {
return $personInfo;
}
/* we lost our person */
return false;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+159
...
$personInfos = $query->getResult();
foreach ($personInfos as $personInfo) {
return $personInfo;
}
/* we lost our person */
return false;
Ребята-оутсорсеры насмешили наш отдел))
+57
template <class T>
T checked_signed_add(T a, T b) {
if (a >= 0) {
if (b >= 0 && std::numeric_limits<T>::max() - a < b)
throw std::runtime_error("Integer overflow");
} else {
if (b < 0 && std::numeric_limits<T>::min() - a > b)
throw std::runtime_error("Integer overflow");
}
return a + b;
}
Кресты. Знаковые числа. Сложение.
http://ideone.com/qxyAoG
+57
static int lowercase(const char *s) {
return tolower(* (const unsigned char *) s);
}
Byte-fuck
+109
memcpy (stderr, stdout, sizeof (FILE));
+78
for (int i = 0; i < 100 && components.isEmpty(); i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
/* shouldn't happen */
}
components = parent.getChildrenByObjType(type);
LOG.debug("Iteration " + i +"components = " + components);
}
if (components.isEmpty()) {
throw new RuntimeException(COMPONENT_NOT_FOUND);
}
зуб, что через 100 итераций со слипом в 1 секунду, коллекция components точно будет заполнена!
+81
try {
// долго и упорно делаем что-то полезное
} catch (Exception e) {
}
После увольнения говнопрограммиста разбираю его творчество.
Выскочил непонятный Exception? Не беда! Пустой блок catch легко исправит ситуацию и избавит пользователя от неприятных эмоций :)
+57
char val;
//...
switch(val)
{
case '0': mOn = true; break;
default: mOn = false; break;
}
+70
public class ConcurrentStringStatsProvider implements StringStatsProvider {
private final ExecutorService executor;
private final ExecutorCompletionService<CharCounter> service;
private final int threadNum;
public ConcurrentStringStatsProvider() {
//http://stackoverflow.com/questions/13834692/threads-configuration-based-on-no-of-cpu-cores
threadNum = Runtime.getRuntime().availableProcessors() + 1;
executor = Executors.newFixedThreadPool(threadNum);
this.service = new ExecutorCompletionService<CharCounter>(executor);
}
@Override
public synchronized CharCounter countChars(String str) {
int length = str.length();
if (length == 0)
return new CharCounter();
int chunk = length / threadNum;
if (chunk == 0)
chunk = length;
for (int i = 0; i < threadNum; i++) {
int start = i * chunk;
int end = (i + 1) * chunk - 1;
if (end > length) {
end = length - 1;
}
service.submit(new SubstringTask(start, end, str));
if (end == length - 1)
break; //break early
}
CharCounter result = null;
while (true) {
Future<CharCounter> future = service.poll();
if (future == null) {
if (result != null && result.getTotalCount() == length)
break;
else
continue;
}
CharCounter subResult = null;
try {
subResult = future.get();
} catch (InterruptedException e) {
log.error("Failed to calculate. Interrupted: ", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
log.error("Calculation error", e);
throw new IllegalStateException("Calculation error: ", e);
}
if (result == null) {
result = subResult;
} else if (result.equals(subResult)) {
break; //!!
} else {
service.submit(new MergeTask(result, subResult));
result = null;
}
}
return result;
}
private class SubstringTask implements Callable<CharCounter> {
private final int start;
private final int end;
private final String str;
public SubstringTask(int start, int end, String str) {
this.start = start;
this.end = end;
this.str = Objects.requireNonNull(str);
}
@Override
public CharCounter call() throws Exception {
return doJob();
}
private CharCounter doJob() {
CharCounter charCounter = new CharCounter(end - start + 1);
for (int i = start; i <= end; i++) {
charCounter.increment(str.charAt(i));
}
return charCounter;
}
}
private class MergeTask implements Callable<CharCounter> {
private final CharCounter cc1, cc2;
public MergeTask(CharCounter cc1, CharCounter cc2) {
this.cc1 = Objects.requireNonNull(cc1);
this.cc2 = Objects.requireNonNull(cc2);
}
@Override
public CharCounter call() throws Exception {
return CharCounter.merge(cc1, cc2);
Первое знакомство с ExecutorCompletionService, решал задачку подсчета количества символов в строке в несколько потоков.
+159
var saveButtonStatus = (saveBtn.length != 0 && (!saveBtn.hasClass('disabled') && !saveBtn.is(':disabled') && !saveBtn.hasClass('ignore')) ) ? true : false;
if(saveButtonStatus) {
return true;
}
....
Валидация
+135
descriptions[result].Append(tblib::Format("%").i(0x12345678, 0xBB));
0040E729 push 0BBh
0040E72E push 12345678h ; ага, запихали параметры для Format::i, заебись; теперь esp=0x0012f1f4
0040E733 lea eax,[esp+38h]
0040E737 push eax ; esp=0x0012f1f0
0040E738 lea ecx,[esp+1Ch]
0040E73C mov dword ptr [esp+3Ch],offset USER32_NULL_THUNK_DATA+40h (43C1A8h)
0040E744 mov dword ptr [esp+40h],ebp
0040E748 mov dword ptr [esp+44h],1
0040E750 call tblib::HeapCArray<char>::HeapCArray<char><tblib::StringRef> (4161B0h) ; esp=0x0012f1f4
0040E755 push 400h ; esp=0x0012f1f0
0040E75A mov ecx,offset tbAlloc (18B0C88h)
0040E75F mov dword ptr [esp+2Ch],ebp
0040E763 mov dword ptr [esp+28h],ebp
0040E767 mov dword ptr [esp+24h],ebp
0040E76B call tblib::Allocator::Malloc (42C500h) ; esp=0x0012f1f4
0040E770 mov dword ptr [esp+20h],eax
0040E774 neg eax
0040E776 sbb eax,eax
0040E778 and eax,400h
0040E77D lea ecx,[esp+18h]
0040E781 mov dword ptr [esp+24h],eax
0040E785 mov dword ptr [esp+2Ch],0FFFFFFFFh
0040E78D call tblib::Format::PassToNext (41BC00h) ; хуй знает почему, но после этой функции esp не меняется, конвенция такая видимо
0040E792 sub esp,0Ch ; БЛЯДЬ СУКА НАХУЙ ЁБАНЫЙ ПИЗДЕЦ ТЫ ЧЁ СУКА ТВОРИШЬ ААААААААА!!!!!!!!!!!!!!!!!!!!!!!!
0040E795 lea ecx,[esp+24h]
0040E799 mov edi,esp
0040E79B call tblib::Format::i (42DBA0h) ; esp=0x0012f1e8, указывает на мусор, параметры для функции - где-то выше
...
MSVC 2003 релиз