- 1
- 2
- 3
Сайт оптимизирован под
браузер GooGle Chrome
Разрешение: 1280х1024
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+125
Сайт оптимизирован под
браузер GooGle Chrome
Разрешение: 1280х1024
http://anidream.net/
+12
void EllipticPoint::Add(const EllipticPoint &b, const EllipticCoord &a, const EllipticCoord &p, EllipticPoint &res) {
if (!x.IsNotZero() && !y.IsNotZero()) {
res = b;
} else if (!b.x.IsNotZero() && !b.y.IsNotZero()) {
res = *this;
} else if (x.Compare(b.x)!=0) {
EllipticCoord tmp1, tmp2, lambda;
b.x.Sub(x,p,tmp1); tmp1.Invert(p,tmp2);
b.y.Sub(y,p,tmp1); tmp1.Mul(tmp2,p,lambda);
lambda.Mul(lambda,p,tmp1);
tmp1.Sub(x,p,tmp2); tmp2.Sub(b.x,p,res.x);
x.Sub(res.x,p,tmp1); lambda.Mul(tmp1,p,tmp2); tmp2.Sub(y,p,res.y);
} else if (y.Compare(b.y)==0) {
EllipticCoord tmp1, tmp2, tmp3, lambda;
x.Mul(x,p,tmp1); tmp1.Add(tmp1,p,tmp3); tmp1.Add(tmp3,p,tmp2); tmp2.Add(a,p,tmp1);
y.Add(y,p,tmp2); tmp2.Invert(p,tmp3); tmp1.Mul(tmp3,p,lambda);
lambda.Mul(lambda,p,tmp1); tmp1.Sub(x,p,tmp2); tmp2.Sub(x,p,res.x);
x.Sub(res.x,p,tmp1); lambda.Mul(tmp1,p,tmp3); tmp3.Sub(y,p,res.y);
} else {
res.x.SetZero();
res.y.SetZero();
}
}
Из моего велосипеда четырехлетней давности.
Кусочек реализации ГОСТ Р 34.10-2001.
+142
while (true)
{
try
{
ProductService.Invoke(method);
return;
}
catch(Exception ex)
{
if (ex is System.ServiceModel.CommunicationException)
{
if (currentRetryCount == RetryCount)
throw new CommunicationException(CommunicationFailureMessage, ex);
System.Threading.Thread.Sleep(RetryWait);
currentRetryCount++;
}
}
}
+148
$("#select_id :selected").attr("selected", false);
$("#select_id option[value='" + new_value + "']").attr("selected", true);
вместо
$("#select_id").val(new_value);
+56
$cur_url=$_SERVER['REQUEST_URI'];
if ($cur_url=='/') {
$cur_url=$_SERVER['REQUEST_URI'];
if ($cur_url=='/') { // Точно-точно адрес не равен слэшу
echo '';// После всех проверок можно с уверенностью вывести пустую строку
}
}
$cur_url2=$_SERVER['REQUEST_URI'];// И ещё разок
if ($cur_url2!='/') {
echo '';
}
Из движка одного московского портала, директор которого пытается нас убедить что там нормальный код
+140
FileInfo file = new FileInfo(fileName);
FileSecurity fSecurity = File.GetAccessControl(fileName);
foreach (FileSystemAccessRule permissions in fSecurity.GetAccessRules(true, true, typeof(NTAccount)))
{
string login = permissions.IdentityReference.Translate(typeof(NTAccount)).Value.ToString();
string permiss = permissions.FileSystemRights.ToString();
if ((login != "логин") && (login != "логин") && (login != "логин"))
{
fSecurity.SetAccessRuleProtection(true, false);
fSecurity.RemoveAccessRule(new FileSystemAccessRule(login, permissions.FileSystemRights, AccessControlType.Allow));
}
fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
}
File.SetAccessControl(fileName, fSecurity);
+90
public enum TimeUnit {
NANOSECONDS {
public long toNanos(long d) { return d; }
public long toMicros(long d) { return d/(C1/C0); }
public long toMillis(long d) { return d/(C2/C0); }
public long toSeconds(long d) { return d/(C3/C0); }
public long toMinutes(long d) { return d/(C4/C0); }
public long toHours(long d) { return d/(C5/C0); }
public long toDays(long d) { return d/(C6/C0); }
public long convert(long d, TimeUnit u) { return u.toNanos(d); }
int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
}
....
public long convert(long sourceDuration, TimeUnit sourceUnit) {
throw new AbstractMethodError();
}
public long toNanos(long duration) {
throw new AbstractMethodError();
}
public long toMicros(long duration) {
throw new AbstractMethodError();
}
public long toMillis(long duration) {
throw new AbstractMethodError();
}
public long toSeconds(long duration) {
throw new AbstractMethodError();
}
public long toMinutes(long duration) {
throw new AbstractMethodError();
}
public long toHours(long duration) {
throw new AbstractMethodError();
}
public long toDays(long duration) {
throw new AbstractMethodError();
}
abstract int excessNanos(long d, long m);
}
Но зачем?
−92
public function xor(lhs:Boolean, rhs:Boolean):Boolean {
return !( lhs && rhs ) && ( lhs || rhs );
}
Из http://as3snippets.blogspot.com/2010/09/logical-xor.html
Как известно, в AS3 есть численный оператор XOR ^, а вот для логических значений ^^ нет. Поэтому ребята придумали такую конструкцию (и ещё вариант return Boolean(int(a) ^ int(b)); в комментах), и только через год какой-то чувак догадался что XOR для логических значений всё-таки есть и называется !=
+141
foreach (var item in text.Split(' ')) {
if (!string.IsNullOrEmpty(item)) {
text = item;
break;
}
}
переменная text всегда содержит несколько пробелов и затем идентификатор.
+20
class TCP1251ToUTF16StringConverter
{
public:
static WideChar convert(Char Source)
{
WideChar Result=static_cast<unsigned char>(Source);
const WideChar Russian_YO=static_cast<unsigned char>('Ё');
const WideChar Russian_yo=static_cast<unsigned char>('ё');
const WideChar RussianWide_YO=L'Ё';
const WideChar RussianWide_yo=L'ё';
const WideChar Russian_A=static_cast<unsigned char>('А');
const WideChar RussianWide_A=L'А';
const unsigned int AmountOfSymbols=0x40;
if(Result==Russian_YO)
return RussianWide_YO;
if(Result==Russian_yo)
return RussianWide_yo;
if(Result>=Russian_A&&Result<Russian_A+AmountOfSymbols)
return (Result-Russian_A+RussianWide_A);
return Result;
};
static void convert(PwideChar UTF16StringDestination, PChar CP1251WinEngRusStringSource, const size_t TextLength)
{
assert(CP1251WinEngRusStringSource!=NULL);
size_t i=0;
for(;;)
{
if(i>=TextLength)
break;
assert(i<TextLength);
Char CP1251SourceChar=CP1251WinEngRusStringSource[i];
if(CP1251SourceChar=='\0')
break;
UTF16StringDestination[i]=convert(CP1251SourceChar);
++i;
};
UTF16StringDestination[i]=L'\0';
assert(i<=TextLength);
};
static std::wstring convert(const std::string& CP1251WinEngRusStringSource)
{
assert(CP1251WinEngRusStringSource.c_str()!=NULL);
std::wstring UTF16StringDestination;
std::transform(CP1251WinEngRusStringSource.begin(), CP1251WinEngRusStringSource.end(), std::inserter(UTF16StringDestination, UTF16StringDestination.end())/*std::back_inserter(UTF16StringDestination)*//*VC 6.0 compatible*/, makePointerToFunction(convertChar));
return UTF16StringDestination;
};
private:
static WideChar convertChar(char Source)
{
return convert(Source);
};
};
template<const size_t MaxAmountOfChar>
class TCP1251ToUTF16StringInPlaceConverter
{
public:
TCP1251ToUTF16StringInPlaceConverter(PChar CP1251WinEngRusStringSource)
{
STATIC_ASSERT(MaxAmountOfChar>0, MaxAmountOfChar_must_be_above_zero);
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, MaxAmountOfChar);
};
TCP1251ToUTF16StringInPlaceConverter(PChar CP1251WinEngRusStringSource, const size_t TextLength)
{
STATIC_ASSERT(MaxAmountOfChar>0, MaxAmountOfChar_must_be_above_zero);
assert(TextLength<=MaxAmountOfChar);
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, TextLength);
};
void convert(PChar CP1251WinEngRusStringSource)
{
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, MaxAmountOfChar);
};
void convert(PChar CP1251WinEngRusStringSource, const size_t TextLength)
{
assert(TextLength<=MaxAmountOfChar);
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, TextLength);
};
PWideChar Get(void) const
{
return &(_buffer[0]);
};
PwideChar Get(void)
{
return &(_buffer[0]);
};
wideChar _buffer[MaxAmountOfChar+1];
};