- 1
memcpy (stderr, stdout, sizeof (FILE));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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 релиз
+157
$var = null;
// Не вызовет: "Notice: Undefined Index 0"
var_dump($var[0][1][2][3]['route']); // NULL
PHP не показывает Notic'ы если переменная или значение является NULL'ом при попытки получить доступ к элементам массива (заметил это когда функция могла возвратить null или массив). Нашел это интересным.
+137
Чуваки! Ну не надо постить уныние. Да, тупой goto, или куча вложенных ifов, или тупой css - это клёво, но в остроумии поупражняться особо желающих, как правило, не бывает - а ведь комменты ценны более всего.
Я бы тут ещё паучка нарисовал, но я уже в пижаме.
алсо, никто не работал с j2me-polish? (да, я некрофил)
+143
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned int board[4][4];
void firstblood(); void drawboard(); int turn(); void changeup(); void changedown(); void changeleft(); void changeright(); int numbofpos(); void gameover();
int pow2 ( int n ) { return 1<<n; }
int main ()
{ do{ firstblood(); drawboard(); while ( turn() ); puts("New game? (y,n)"); fflush(stdin); char c=getchar(); if (c!='y') return 0; for (int i=0;i<4;i++) for (int j=0;j<4;j++) board[i][j]=0; } while (1);
}
void firstblood()
{ srand((unsigned int)time); board[rand()%4][rand()%4]=pow2(rand()%3+1); board[rand()%4][rand()%4]=pow2(rand()%4+1); }
void drawboard ()
{ system("CLS"); puts(" 2048 "); int i,j; for (i=0;i<4;i++, printf("\n\n") ) for (j=0;j<4;j++) printf("%5u",board[i][j]); puts("\nw,a,s,d and r to move and new game");
}
int numbofpos()
{ int i,j,n=0; for (i=1;i<4;i++ for (j=0;j<4;j++){if (board[i][j] && board[i][j]==board[i-1][j]) n++; if (board[j][i] && board[j][i]==board[j][i-1]) n++; }for (i=0;i<4;i++) for (j=0;j<4;j++) if (!board[i][j]) n++;
return n ;
}
void gameover()
{
system("CLS"); puts(" 2048 "); int i,j; for (i=0;i<4;i++, printf("\n\n") ) for (j=0;j<4;j++) printf("%5u",board[i][j]); puts("\n Game over ");
}
int turn()
{
char c=getchar(); int i,j,n=0, nulls[16][2];
switch(c)
{ case 'w' : changeup(); break;
case 'a' : changeleft(); break;
case 's' : changedown(); break;
case 'd' : changeright(); break;
case 'r' : return 0;
}
for (i=0;i<4;i++)
for (j=0;j<4;j++)
if ( !board[i][j] ) { nulls[n][0]=i; nulls[n++][1]=j; }
if (n)
{
int t=rand()%n;
board[ nulls[t][0] ][ nulls[t][1] ] = pow2(rand()%2+1);
}
if ( !numbofpos() )
{ gameover(); return 0; }
drawboard();
return 1;
}
void changeleft()
{
int i,j,k;
for (i=0;i<4;i++)
{
int f= ( !board[i][3] )?0:1 ;
for (j=2;j>=0;j--)
{ if (board[i][j] && !f) f=1;
if (!board[i][j] && f==1) { for (k=j+1;k<4;board[i][k-1]=board[i][k],k++); board[i][3]=0; }
}
for (j=0;j<3;j++)
if ( board[i][j] && board[i][j]==board[i][j+1])
{
board[i][j] *= 2;
for (k=j+1;k<3; board[i][k]=board[i][k+1], k++ );
board[i][3]=0;
}
}
}
void changeright()
{
int i,j,k;
for (i=0;i<4;i++)
{
int f= ( !board[i][0] )?0:1 ;
for (j=1;j<4;j++)
{ if (board[i][j] && !f) f=1;
if (!board[i][j] && f==1) { for (k=j;k>0;board[i][k]=board[i][k-1],k--); board[i][0]=0; }
}
for (j=3;j>0;j--)
if ( board[i][j] && board[i][j]==board[i][j-1])
{
board[i][j] *= 2;
for (k=j-1;k>0; board[i][k]=board[i][k-1], k-- );
board[i][0]=0;
}
}
}
void changeup()
{ int i,j,k; for (i=0;i<4;i++) { int f= ( !board[3][i] )?0:1 ; for (j=2;j>=0;j--) { if (board[j][i] && !f) f=1; if (!board[j][i] && f==1) { for (k=j+1;k<4;board[k-1][i]=board[k][i],k++); board[3][i]=0; } }
for (j=0;j<3;j++) if ( board[j][i] && board[j][i]==board[j+1][i]) {board[j][i] *= 2; for (k=j+1;k<3; board[k][i]=board[k+1][i], k++ ); board[3][i]=0; }}}
void changedown()
{int i,j,k; for (i=0;i<4;i++) { int f= ( !board[0][i] )?0:1 ; for (j=1;j<4;j++) { if (board[j][i] && !f) f=1; if (!board[j][i] && f==1) { for (k=j;k>0;board[k][i]=board[k-1][i],k--); board[0][i]=0; } } for (j=3;j>0;j--) if ( board[j][i] && board[j][i]==board[j-1][i]) board[j][i] *= 2;
for (k=j-1;k>0; board[k][i]=board[k-1][i], k-- ); board[0][i]=0;
} }}
2048 только с библиотеками stdio.h, stdlib.h (srand,rand) и time.h (тоже для рандома)
Пожалуйста, уберите ограничение в 100 строк