- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
bool exit = false;
while (!exit)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
exit = true;
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+135
bool exit = false;
while (!exit)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
exit = true;
}
}
Православная замена Console.ReadKey();
−133
yum remove python
Еще один способ "отпилить ветку под собой"
http://www.linux.org.ru/forum/admin/8946020
+16
char tab1[22][8]={"program","var","begin","end","int","float","bool","if","then","else","for","to","do","while","readln","writeln","as","||","!","&&","true","false"};
char tab2[18][3]={"==","<",">","+","-","*","/","(",")",".",",",";"," ","!=","<=",">=",10};
//Много кода
if(!strcmp("program",st.top())&&!strcmp("program",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("var",st.top())&&!strcmp("var",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("begin",st.top())&&!strcmp("begin",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("end",st.top())&&!strcmp("end",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("int",st.top())&&!strcmp("int",&mas[j][0]))
{
st.pop();
j++;
}
else
if(!strcmp("float",st.top())&&!strcmp("float",&mas[j][0]))
{
st.pop();
j++;
}
//Еще строк 200 такого
−101
- (void)viewDidLoad
{
// ...
float os_verson = [[[UIDevice currentDevice] systemVersion] floatValue];
NSString* dev_ver_str = [[UIDevice currentDevice] systemVersion];
if (os_verson >= 4 || [dev_ver_str hasPrefix:@"3.2"]) {
[self viewWillAppear:NO];
[self viewDidAppear:NO];
}
}
Костыли наше всё
+10
for (int i = 0; i < 15; i++) {
// Прикольное место, надо прокомментировать
// Если наша функция Fork() вернула true, то мы
// в дочернем процессе и форкаться больше не надо
// Форканье - это задача родителя
// Дети этим заниматься не должны
if (Fork()) break;
}
Создание дочерних процессов. Вот такой костыль. Есть идеи, как улучшить?
+19
//generate the new objects
EnterCriticalSection(&csWinEvent);
value arr = alloc_array(windowStates.size());
int i=0;
for(
std::tr1::unordered_map<int,windowState>::const_iterator it = windowStates.begin();
it!=windowStates.end();
++it )
{
value o = alloc_empty_object();
//int hwnd
//int x,y,w,h
//int minimized,maximized,restored,closed
alloc_field(o, val_id("hwnd"), alloc_int(it->first));
alloc_field(o, val_id("window"), *(value*)GetWindowLongPtr((HWND)it->first,GWLP_USERDATA) );
alloc_field(o, val_id("x"), alloc_int(it->second.x));
alloc_field(o, val_id("y"), alloc_int(it->second.y));
alloc_field(o, val_id("w"), alloc_int(it->second.w));
alloc_field(o, val_id("h"), alloc_int(it->second.h));
alloc_field(o, val_id("minimized"), alloc_int(it->second.minimized));
alloc_field(o, val_id("maximized"), alloc_int(it->second.maximized));
alloc_field(o, val_id("restored"), alloc_int(it->second.restored));
alloc_field(o, val_id("closed"), alloc_int(it->second.closed));
val_array_set_i(arr,i,o);
++i;
}
windowStates.clear();
LeaveCriticalSection(&csWinEvent);
Casts ;]
+100
procedure TDetailForm.GridPanel1Click(Sender: TObject);
var
i: Integer;
s: String;
begin
//set title and subtitle
if Pos('Item', TControl(Sender).Name) > 0 then begin
if Sender.ClassName = 'TImage' then begin
i := Length(TControl(Sender).Name) - Length('ItemImage') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemTitle.Caption := TLabel(DetailForm.FindComponent('ItemTitle' + s)).Caption;
ItemSubtitle.Caption := TLabel(DetailForm.FindComponent('ItemSubTitle' + s)).Caption;
end else if Pos('ItemSubTitle', TControl(Sender).Name) > 0 then begin
ItemSubtitle.Caption := TLabel(Sender).Caption;
i := Length(TControl(Sender).Name) - Length('ItemSubTitle') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemTitle.Caption := TLabel(DetailForm.FindComponent('ItemTitle' + s)).Caption;
end else if Pos('ItemDescription', TControl(Sender).Name) > 0 then begin
i := Length(TControl(Sender).Name) - Length('ItemDescription') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemTitle.Caption := TLabel(DetailForm.FindComponent('ItemTitle' + s)).Caption;
ItemSubtitle.Caption := TLabel(DetailForm.FindComponent('ItemSubTitle' + s)).Caption;
end else begin
ItemTitle.Caption := TLabel(Sender).Caption;
i := Length(TControl(Sender).Name) - Length('ItemTitle') - 1;
s := Copy(TControl(Sender).Name, Length(TControl(Sender).Name) - i, Length(TControl(Sender).Name));
ItemSubTitle.Caption := TLabel(DetailForm.FindComponent('ItemSubTitle' + s)).Caption;
end;
end;
end;
Код из шаблона New Metropolis UI Application в новом Delphi XE3. Рефлексия так и прет.
+99
// Получение имени выполняемого метода, вызывать можно только из Published-методов класса.
// Для обычных методов: FindClassMethodNames(ClassType()), для статических методов FindClassMethodNames(self).
{$optimization OFF}
function FindClassMethodNames(obj: TClass): string;
var _AdrPtr: Pointer;
begin
asm
mov eax, obj
mov edx, dword ptr [esp + 272]
push ebx
push esi
push edi
push $7FFFFFFF
xor edi, edi
jmp @@haveVMT
@@outer:
mov eax, dword ptr [eax]
@@haveVMT:
mov esi, dword ptr [eax].vmtMethodTable
test esi, esi
je @@parent
movzx ecx, word ptr [esi]
add esi, 2
@@inner:
pop ebx
push edx
sub edx, dword ptr [esi + 2]
jl @@no1
cmp edx, ebx
jg @@no1
mov ebx, edx
mov edx, dword ptr [esi + 2]
mov edi, edx
@@no1:
pop edx
push ebx
movzx ebx, word ptr [esi]
add esi, ebx
dec ecx
jnz @@inner
@@parent:
mov eax, dword ptr [eax].vmtParent
test eax, eax
jne @@outer
mov _AdrPtr, edi
pop edi
pop esi
pop ebx
end;
Result := obj.MethodName(_AdrPtr);
end;
{$optimization ON}
// пример использования
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FindClassMethodNames(ClassType()));
end;
А есть нормальный способ получить имя выполняемого метода, и строку кода заодно?
−51
void a()
{
}
void b()
{
return a();
}
Компилится.
http://ideone.com/8eP1w
+152
String.prototype.startsWith=function(b){
if(this.length<b.length){
return false
}
for(var a=0;a<b.length;++a){
if(this.charAt(a)!==b.charAt(a)){
return false
}
}
return true
};
String.prototype.endsWith=function(b){
if(this.length<b.length){
return false
}
var c=b.length-1;
for(var a=this.length-1;a>this.length-1-b.length;--a){
if(b.charAt(c--)!==this.charAt(a)){
return false
}
}
return true
};
String.prototype.contains=function(a){
return this.indexOf(a)!==-1
};
String.prototype.LastIndexOf=function(d,c){
if(this.length===0||d===null){
return -1
}
if(d.length>this.length){
return -1
}
if(isNaN(c)){
c=this.length-d.length
}
var a=false;
for(var b=c;b>=0;--b){
a=true;
for(var e=0;e<d.length;++e){
if(this.charAt(b+e)!==d.charAt(e)){
a=false;
break
}
}
if(a){
return b
}
}
return -1
};
String.prototype.LastIndexOf_char=function(a){
for(var b=this.length-1;b>=0;--b){
if(this.charAt(b)===a){
return b
}
}
return -1
};
String.prototype.setCharAt=function(b,a){
if(b>this.length-1){
return str
}
return this.substr(0,b)+a+this.substr(b+1)
};
String.prototype.countCharAppearances=function(a){
var b=0;
for(var c=0;c<this.length;++c){
if(this.charAt(c)==a){
++b
}
}
return b
};
Сорри, что много буков, но тут каждую функцию можно воспринимать как отдельное произведение.
Разбираю бред какого-то безымянного идиота :(