- 1
- 2
- 3
- 4
@echo off
chcp 1251
mygame.exe
chcp 866
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+126
@echo off
chcp 1251
mygame.exe
chcp 866
Оттуда.
+162
$count = count($array);
// Говорю коллеге: "У тебя там деление на ноль, исправь".
// После этого появилось следующее...
if ( $count == 0 ) $count = 1;
$result = (int) ((1/$count) * SOME_VALUE1 + SOME_VALUE2);
Код, блять, Хемминга
−1
#include <iostream>
using namespace std;
struct NG
{
template<class T>
struct get
{
typedef typename T::f type;
};
};
template <typename T, typename NameGetter>
struct has_member_impl
{
typedef char matched_return_type;
typedef long unmatched_return_type;
template <typename C>
static matched_return_type f(typename NameGetter::template get<C>*);
template <typename C>
static unmatched_return_type f(...);
public:
static const bool value = (sizeof(f<T>(0)) == sizeof(matched_return_type));
};
template <typename T, typename NameGetter>
struct has_member{
enum { value = has_member_impl<T, NameGetter>::value };
};
class T{};
int main() {
cout<<has_member<T, NG>::value;
return 0;
}
http://ideone.com/4LDGhZ
+9
HRESULT hr = ReadGenericXMLFile(srcStorage, pagePath, result);
if (hr == S_FALSE) return STG_E_FILENOTFOUND; // File must exist
if (FAILED(hr)) return hr;
Могу понять, обратное, когда вызывающая функция просто возвращает "false" при любом неудачном вызове внутренней функции: нет файла / нет доступа / runtime error и т.д. Здесь же наоборот, при "общем" неудачном вызове внутренней функции возвращается "конкретное" сообщение об ошибке.
+135
switch (curWpn)
{
case WeaponType.Doublegun: DrawNumber(doublegunAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, doublegunAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(doublegunI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
case WeaponType.Grenade: DrawNumber(grenadeCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, grenadeCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(grenadeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), grenadeTimeout > 0.0f ? Color.Red : Color.White); break;
case WeaponType.Knife: spriteBatch.Draw(knifeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
case WeaponType.Launcher: DrawNumber(rocketCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, rocketCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(launcherI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), launchTimeout > 0.0f ? Color.Red : Color.White); break;
case WeaponType.Revolver: spriteBatch.Draw(revolverI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
case WeaponType.Cannon: DrawNumber(cannonAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, cannonAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(cannonI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), cannonTimeout > 0.0f ? Color.Red : Color.White); break;
case WeaponType.Laser: DrawNumber(laserAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, laserAmmoCnt > 0 ? Color.White : Color.Red); break;
case WeaponType.Minigun: DrawNumber(minigunAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, minigunAmmoCnt > 0 ? Color.White : Color.Red); break;
}
//в другом месте
switch (curWpnIndex)
{
case 0: curWpn = WeaponType.Knife; break;
case 1: curWpn = WeaponType.Revolver; break;
case 2: curWpn = WeaponType.Doublegun; break;
case 3: curWpn = WeaponType.Laser; break;
case 4: curWpn = WeaponType.Minigun; break;
case 5: curWpn = WeaponType.Rifle; break;
case 6: curWpn = WeaponType.Grenade; break;
case 7: curWpn = WeaponType.Launcher; break;
case 8: curWpn = WeaponType.Cannon; break;
}
Это неописуемо. Нашел у себя...
Видимо, придется снова идти мыться.
+83
while (today.before(endTrial)) {
today.add(Calendar.DAY_OF_MONTH, 1);
daysBetween++;
}
считаем разницу между двумя датами
+76
function IPP (var i: integer): integer;
begin
Result := i;
Inc(i);
end;
−108
- (void) fixUIAfterRotation: (UIInterfaceOrientation) interfaceOrientation
{
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:UIInterfaceOrientationIsPortrait(interfaceOrientation)? @"bg_new.png":@"bg_new_90.png"]]];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *htmlStr;
webError = NO;
orient = UIInterfaceOrientationIsPortrait(interfaceOrientation)? 1:2;
float width_ = [[UIScreen mainScreen] bounds].size.height;
viewNews.frame = isRotation? (UIInterfaceOrientationIsPortrait(interfaceOrientation)?
CGRectMake(0, 0, width_, 240):CGRectMake(0, 0, width_, width_ - 90)):(UIInterfaceOrientationIsPortrait(interfaceOrientation)? CGRectMake(0, 0, 320, width_ - 81):CGRectMake(0, 0, width_, 240));
isRotation = isRotation? NO:isRotation;
#if defined(PRO_PROJECT)
if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
htmlStr = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">
<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title>
<style>body {margin:0px; padding:0px; font:13px arial; background:none;}
a {text-decoration:underline; color:#fbcf04; font-weight:bold; !important;} a:hover {text-decoration:none;}
.title{background:#575757 left top repeat-x; font:bold 15px Arial; color:#FFF; padding:14px 30px 0px 0px; height:31px;
border-bottom:1px solid #000000; line-height:14px}.titleIm{background:#575757 left top repeat-x; padding:13px 8px 13px 13px; height:31px;
border-bottom:1px solid #000000;}.news_body {border-top:1px solid #414141; padding:10px 14px 14px 14px;
color:#FFF; line-height:19px; background:#3d3d3d;}.news_body p {padding-top:0px;}</style></head>
<body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"320\" height=\"388\"><tr><td width=\"75\" valign=\"top\" class=\"titleIm\">
<img src=%@ height=\"70\" width=\"70\"></td><td valign=\"top\" class=\"title\">%@
<div style=\"font:11px Arial; color:#858585; line-height:18px;\">%@</div></td></tr><tr>
<td colspan=\"2\" valign=\"top\" class=\"news_body\">%@</td></tr></table></body></html>",
imageName, [newsDescription objectForKey:@"titleNews"],
[CORENewsTitleList getDataString:[newsDescription objectForKey:@"dateNews"]],
[newsDescription objectForKey:@"discriptionNews"]];
}
else
{
htmlStr = [NSString stringWithFormat:@"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\">
<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title>
<style>body {margin:0px; padding:0px; font:13px arial; background:none;}
a {text-decoration:underline; color:#fbcf04; font-weight:bold; !important;}a:hover {text-decoration:none;}
.title {background:#575757 left top repeat-x; font:bold 15px Arial; color:#FFF; padding:14px 30px 0px 0px; height:31px;
border-bottom:1px solid #000000; line-height:14px}.titleIm {background:#575757 left top repeat-x; padding:13px 8px 13px 13px; height:31px;
border-bottom:1px solid #000000;}.news_body {border-top:1px solid #414141; padding:10px 14px 14px 14px;
color:#FFF; line-height:19px; background:#3d3d3d;}.news_body p {padding-top:0px;}</style></head>
<body><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"%f\" height=\"240\"><tr><td width=\"75\" valign=\"top\" class=\"titleIm\">
<img src=%@ height=\"70\" width=\"70\"></td><td valign=\"top\" class=\"title\">%@
<div style=\"font:11px Arial; color:#858585; line-height:18px;\">%@</div></td></tr><tr>
<td colspan=\"2\" valign=\"top\" class=\"news_body\">%@</td></tr></table></body></html>",
width_, imageName, [newsDescription objectForKey:@"titleNews"],
[CORENewsTitleList getDataString:[newsDescription objectForKey:@"dateNews"]],
[newsDescription objectForKey:@"discriptionNews"]];
}
#else
if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
// тот же упоротый код, что и выше, за исключением цветов для бэкграунда и надписей.
}
else
{
// тот же упоротый код, что и выше, за исключением цветов для бэкграунда и надписей.
}
#endif
[viewNews loadHTMLString:htmlStr baseURL:baseURL];
}
Поворачиваем вебвью во вью-контроллере, который может использоваться в 2 проектах, имеющих различные темы (отличается бэкграунд и цвет надписей).
+110
int strnlen(const char *s, int size)
{
int i;
for(i=0; i<size; i++) if(!*s) break;
return i;
}
+135
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSIZE 512
typedef struct word
{
char wordBody[MAXSIZE];
int count;
struct word* next;
} Word;
Word* alloc(char* incomeWord)
{
Word* ret;
ret = (Word*)malloc(sizeof(Word));
ret->count=1;
ret->next=NULL;
strcpy(ret->wordBody, incomeWord);
}
void insert(Word **n, char* incomeWord)
{
Word** p_p_n;
int h=0;
if(*n==NULL)
{
*n = alloc(incomeWord);
return;
}
for(p_p_n = n; *p_p_n!=NULL; p_p_n = &(*p_p_n)->next)
{
if((strcmp(incomeWord,&(*p_p_n)->wordBody))==0)
{
(*p_p_n)->count++;
return;
}
}
for(p_p_n = n; *p_p_n!=NULL; p_p_n = &(*p_p_n)->next)
{
Word* ins = alloc(incomeWord);
Word* temp = *p_p_n;
Word** tt;
int is=0;
tt=p_p_n;
ins->next=temp;
*p_p_n = ins;
break;
}
}
void print(Word* n)
{
while(n!=NULL) {
if(n->count > 1)
{
printf("%s %d\n", n->wordBody, n->count);
}
n=n->next;
}
}
int main(void)
{
char buf[MAXSIZE]={'\0'};
FILE *fr;
Word* sez=NULL;
fr=fopen("Text1.txt", "r");
while(!feof(fr))
{
fscanf(fr,"%s",buf);
insert(&sez,buf);
}
print(sez);
printf("\n%d\n", sizeof(sez));
fclose(fr);
return 0;
}
Считаем сколЬко раз каждое слово встречается в текстовом файле. Программа выполняется 6.5 минут с файлом размером 850 килобайт.