- 1
- 2
- 3
int platform = (int) Environment.OSVersion.Platform;
if (platform != 4 && platform != 128)
return;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+125
int platform = (int) Environment.OSVersion.Platform;
if (platform != 4 && platform != 128)
return;
Из gbrainy (входит в поставку Ubuntu 10.04), причём это рекомендованный самим Мигелем де Иказой подход.
Экскурс: в кроссплатформенном™ фреймворке MS .NET 1.0/1.1® в энумерации PlatformID не было ничего кроме Windows'ов (Linux в паре мест официально числился Invalid). Ребята из моно кустарно добавили PlatformID.Unix == 128. Затем в MS. NET 2.0 всё-таки открыли для себя Mac OS X и Unix, но проставили PlatformID.Unix == 4. Благими намерениями вымощена дорога в к говнокоду :)
+79
public String FormatDocumentNumber(String docNum)
{
int len = docNum.length();
int lenDiff = len - Integer.toString(this.document_num).length();
char[] arr = docNum.toCharArray();
char[] number = Integer.toString(this.document_num).toCharArray();
for(int i=0; i<len; i++)
{
arr[i] = '0';
}
for(int i=0; i<number.length; i++ )
{
arr[lenDiff+i] = number[i];
}
StringBuffer sb = new StringBuffer();
for(int i=0; i<len; i++)
{
sb.append(arr[i]);
}
return sb.toString();
}
Как сделать красивую функцию, которая формирует строку определенной длины с числом с ведущими нулями?
+143
// народ на протяжении 5+ лет жаловался что постоянно что-то в этой библиотеке Х
// криво потому что часто (с их слов) попытки вызова ее функций просто обламываются:
int module_main_function()
{
int rc = 0;
// ...
rc = libX_do_work( ... )
if (rc != OK) {
// error!!!
}
// ...
}
// теперь заглянем в инициализацию этого модуля:
int module_init()
{
int rc;
// ... кучи дежурного копи-паста для инициализации скипнуты ...
rc = libZ_init();
if (rc != OK)
{
/* error handling */
}
rc = libY_init();
if (rc != OK)
{
/* error handling */
}
libX_init(); /* лопата */
if (rc != OK)
{
/* error handling */
}
rc = libA_init();
if (rc != OK)
{
/* error handling */
}
// ... и т.д. и т.п.
}
меня жалобы одного отдела начали потиху доставать что наша библиотека (назовем ее libX) у них в модуле постоянно не работает и шо ваабще за херня. как встроили ее - так и не работает. иногда. в 80+ модулях работает как часы - ни один другой отдел не жалуется - а вот в ихнем очень специальном модуле нет.
ну я к ним подвалил. они меня сразу в рабочую функцию тыкать стали - вот тут дескать не работает. я им методично: покаж где инициализация. я когда в инициализацию заглянул, почти сразу начал роготять (давно так не смеялся, наболело за годы).
им минут пять понадобилось что бы в своем копи-паст параде рассмотреть эту глюку.
ЗЫ ответ: на строке с лопатой, не хватает "rc = ". у библиотеки есть внешняя конфигурация на отсутствии коей она у них обламывалась постоянно. и исправить скрипты свои что бы чужая конфигурация не убивалясь им похоже религия не позволяет.
+163.8
function translit($valstr){
for($i=0;$i<strlen($valstr); $i++){
switch(ord($valstr[$i])){
case 192: { $newstr.=chr(97); break; }
case 193: { $newstr.=chr(98); break; }
case 194: { $newstr.=chr(118); break; }
case 195: { $newstr.=chr(103); break; }
case 196: { $newstr.=chr(100); break; }
case 197: { $newstr.=chr(101); break; }
case 198: { $newstr.=chr(122).chr(104); break; }
case 199: { $newstr.=chr(122); break; }
case 200: { $newstr.=chr(105); break; }
case 201: { $newstr.=chr(106); break; }
case 202: { $newstr.=chr(107); break; }
case 203: { $newstr.=chr(108); break; }
case 204: { $newstr.=chr(109); break; }
case 205: { $newstr.=chr(110); break; }
case 206: { $newstr.=chr(111); break; }
case 207: { $newstr.=chr(112); break; }
case 208: { $newstr.=chr(114); break; }
case 209: { $newstr.=chr(115); break; }
case 210: { $newstr.=chr(116); break; }
case 211: { $newstr.=chr(117); break; }
case 212: { $newstr.=chr(102); break; }
case 213: { $newstr.=chr(120); break; }
case 214: { $newstr.=chr(99); break; }
case 215: { $newstr.=chr(99).chr(104); break; }
case 216: { $newstr.=chr(115).chr(104); break; }
case 217: { $newstr.=chr(119); break; }
case 218: { break; }
case 219: { $newstr.=chr(121); break; }
case 220: { break; }
case 221: { $newstr.=chr(106).chr(101); break; }
case 222: { $newstr.=chr(106).chr(117); break; }
case 223: { $newstr.=chr(121).chr(97); break; }
case 224: { $newstr.=chr(97); break; }
case 225: { $newstr.=chr(98); break; }
case 226: { $newstr.=chr(118); break; }
case 227: { $newstr.=chr(103); break; }
case 228: { $newstr.=chr(100); break; }
case 229: { $newstr.=chr(101); break; }
case 230: { $newstr.=chr(122).chr(104); break; }
case 231: { $newstr.=chr(122); break; }
case 232: { $newstr.=chr(105); break; }
case 233: { $newstr.=chr(106); break; }
case 234: { $newstr.=chr(107); break; }
case 235: { $newstr.=chr(108); break; }
case 236: { $newstr.=chr(109); break; }
case 237: { $newstr.=chr(110); break; }
case 238: { $newstr.=chr(111); break; }
case 239: { $newstr.=chr(112); break; }
case 240: { $newstr.=chr(114); break; }
case 241: { $newstr.=chr(115); break; }
case 242: { $newstr.=chr(116); break; }
case 243: { $newstr.=chr(117); break; }
case 244: { $newstr.=chr(102); break; }
case 245: { $newstr.=chr(120); break; }
case 246: { $newstr.=chr(99); break; }
case 247: { $newstr.=chr(99).chr(104); break; }
case 248: { $newstr.=chr(115).chr(104); break; }
case 249: { $newstr.=chr(119); break; }
case 250: { break; }
case 251: { $newstr.=chr(121); break; }
case 252: { break; }
case 253: { $newstr.=chr(106).chr(101); break; }
case 254: { $newstr.=chr(106).chr(117); break; }
case 255: { $newstr.=chr(121).chr(97); break; }
default: { $newstr.=$valstr[$i]; break; }
}
}
return $newstr;
}
+164.6
<?php
if (isset ($_POST['logform'])) {$logform = $_POST['logform'];} else {$logform = $_POST['logform'];}
echo $logform;
if (isset ($_POST['pasform'])) {$pasform = $_POST['pasform'];} else {$pasform = $_POST['pasform'];}
echo $pasform;
?>
Контрольный в голову
+144.8
<?php
if(!@isset($_POST[submit]))
{
...
?>
+144.8
/**
* Helper classes for computing window query on rectangles
*/
class VerticalSegmentIntersect : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
VerticalSegmentIntersect ( ptrdiff_t top, ptrdiff_t bottom ) throw() : m_Lhs(top+top), m_Rhs(bottom+bottom) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->bottom() + area->top(), y = area->bottom() - area->top();
if (y < x - m_Rhs ) return 0;
if (y < m_Lhs - x ) return 0;
return 1;
}
};
class HorisontalSegmentIntersect : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
HorisontalSegmentIntersect ( ptrdiff_t left, ptrdiff_t right ) throw() : m_Lhs(left+left), m_Rhs(right+right) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->right() + area->left(), y = area->right() - area->left();
if (y < x - m_Rhs ) return 0;
if (y < m_Lhs - x ) return 0;
return 1;
}
};
/**
* Helper classes for computing containment query on rectangles
*/
class VerticalSegmentContains : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
VerticalSegmentContains ( ptrdiff_t top, ptrdiff_t bottom ) throw() : m_Lhs(top+top), m_Rhs(bottom+bottom) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->bottom() + area->top(), y = area->bottom() - area->top();
if ( y > x - m_Lhs ) return 0;
if ( y > m_Rhs - x ) return 0;
return 1;
}
};
class HorisontalSegmentContains : public std::unary_function < PRGlyph, ptrdiff_t > {
ptrdiff_t m_Lhs;
ptrdiff_t m_Rhs;
public:
HorisontalSegmentContains ( ptrdiff_t left, ptrdiff_t right ) throw() : m_Lhs(left+left), m_Rhs(right+right) {}
ptrdiff_t operator() ( PRGlyph inpGlyph ) const throw() {
QRect const* area = inpGlyph->GetGlyphArea();
ptrdiff_t x = area->right() + area->left(), y = area->right() - area->left();
if ( y > x - m_Lhs ) return 0;
if ( y > m_Rhs - x ) return 0;
return 1;
}
};
// compute the window query on m_GlyphData rectangles
QVector<PRGlyph> :: iterator windowq = m_Selection.isValid() ?
std::partition ( m_GlyphData.begin(),
std::partition ( m_GlyphData.begin(), m_GlyphData.end(), VerticalSegmentIntersect ( m_Selection.top(), m_Selection.bottom() ) ),
HorisontalSegmentIntersect ( m_Selection.left(), m_Selection.right() )
) : m_GlyphData.begin();
// compute the containment query on window query rectangles (the containment query resuls is always subset of window query )
QVector<PRGlyph> :: iterator containq = std::partition ( m_GlyphData.begin(),
std::partition ( m_GlyphData.begin(), windowq, VerticalSegmentContains ( m_Selection.top(), m_Selection.bottom() ) ),
HorisontalSegmentContains ( m_Selection.left(), m_Selection.right() )
);
Способ быстренько находить прямоугольники, пересекающиеся с входным и содержимые им же. Применимо для прямоугольных параллелепипедов любой размерности.
+167.8
function returnDate($stamp){
global $settings;
$day = strftime("%d",$stamp+($settings['timeoffset']*3600));
$month = strftime("%m",$stamp+($settings['timeoffset']*3600));
$year = strftime("%Y",$stamp+($settings['timeoffset']*3600));
switch ($month){
case 01 : $month = "01"; break;
case 02 : $month = "02"; break;
case 03 : $month = "03"; break;
case 04 : $month = "04"; break;
case 05 : $month = "05"; break;
case 06 : $month = "06"; break;
case 07 : $month = "07"; break;
case 08 : $month = "08"; break;
case 09 : $month = "09"; break;
case 10 : $month = "10"; break;
case 11 : $month = "11"; break;
case 12 : $month = "12"; break;
}
return "$day.$month.$year";
}
Взято из чешского шаблона под одну цмску. Автору, наверно, платят как Маяковскому - за каждую строчку :-)
+109.3
<script type="text/javascript">
<!--
if (window.screen)
{
if (screen.width < 1024)
{
document.write('<td height="35" width="11"><img src="img0800/indx/indx_0_0.png" title="" alt="" style="width: 11px; height: 35px;"></td>\n');
document.write('<td height="35" width="43"><a href="en/index.html"><img src="img0800/indx/indx_1_0.png" title="" alt="" style="width: 43px; height: 35px;"></a></td>\n');
document.write('<td height="35" width="76"><img src="img0800/indx/indx_2_0.png" title="" alt="" style="width: 76px; height: 35px;"></td>\n');
document.write('<td height="35" width="32"><img src="img0800/indx/indx_3_0.png" title="" alt="" style="width: 32px; height: 35px;"></td>\n');
document.write('<td height="35" width="27"><img src="img0800/indx/indx_4_0.png" title="" alt="" style="width: 27px; height: 35px;"></td>\n');
document.write('<td height="35" width="39"><img src="img0800/indx/indx_5_0.png" title="" alt="" style="width: 39px; height: 35px;"></td>\n');
document.write('<td height="35" width="103"><img src="img0800/indx/indx_6_0.png" title="" alt="" style="width: 103px; height: ................
document.write('<td height="31" width="21"><img src="img1024/indx/indx_15_19.png" title="" alt="" style="width: 21px; height: 31px;"></td>\n');
}
else if (screen.width < 1600)
{
document.write('<td height="59" width="18"><img src="img1280/indx/indx_0_0.png" title="" alt="" style="width: 18px; height: 59px;"></td>\n');
document.write('<td height="59" width="72"><a href="en/index.html"><img src="img1280/indx/indx_1_0.png" title="" alt="" style="width: 72px; height: 59px;"></a></td>\n');
document.write('<td height="59" width="127"><img src="img1280/indx/indx_2_0.png" title="" alt="" style="width: 127px; height: 59px;"></td>\n');
document.write('<td height="59" width="53"><img src="img1280/indx/indx_3_0.png" title="" alt="" style="width: 53px; height: 59px;"></td>\n');
document.write('<td height="59" width="46"><img src="img1280/indx/indx_4_0.png" title="" alt="" style="width: 46px; height: 59px;"></td>\n');
document.write('<td height="59" width="64"><img src="img1280/indx/indx_5_0.png" title="" alt="" style="width: 64px; height: 59px;"></td>\n');
.......
Сайт с фоном из таблицы с картинками. Картинки нарезаны на мелкие кусочки и, внимание, сайт подстраивается под разные разрешения мониторов! Есть наборы картинок для ширины 800, 1024, 1280 и 1600. Посмотреть можно на http://old.abvi.redsolution.ru/
+167.7
$('div[id="myid"]')