- 1
- 2
- 3
- 4
- 5
with (VirNode^) do
begin
VirNode^.ImageIndex := vir.iNum;
VirNode^.Txt := vir.sAttr[1] + ' - ' + vir.sAttr[3];
end;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+86.2
with (VirNode^) do
begin
VirNode^.ImageIndex := vir.iNum;
VirNode^.Txt := vir.sAttr[1] + ' - ' + vir.sAttr[3];
end;
сначала было без with а потом забыл убрать "VirNode^." :)
+148.7
// Any fool can write code that a computer can understand. Good programmers write code that humans can understand. (C) Martin Fowler.
function changeLogo() {
var pane = document.getElementById("pane");
if(pane != null) {
pane.height = 240;
pane.width = document.body.clientWidth;
} else {
alert("it's sad, so sad...");
}
var logo = document.getElementById("logoJpg");
if(logo != null) {
logo.height = 50;
logo.width = document.body.clientWidth * 0.23;
} else {
alert(" ...it's a sad, sad situation, and it's getting more and more absurd");
}
}
Код совсем ничего, но камменты рулят
+54.7
<div style="padding: 2px;">
<div class="go_left">
<font color="#777777">Account balance:</font> <span id="js_total_hours" style="margin: 0px; padding: 0px;">2</span> hours
</div>
<div class="clear"></div>
</div>
go_left - стиль с float: left
clear - стиль с clear: both
как минимум спрашивается зачем давать флоэт лефт единстенному элементу в диве.
+153
<?php
$thelist = array();
$dir = './upload/ftp/';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file !="index.php" && $file !=".ftpquota") {
$file = $file;
$thelist[] = array('file' => $file, 'filemtime' => filemtime($file), 'filesize' => filesize($file));
}
}
closedir($handle);
}
?>
<?php
for($i = 0; $i < count($thelist); $i++) {
?><a href="sitename/<?=$thelist[$i]['file']?>"><?=$thelist[$i]['file']?></a><?php
}
?>
+12.1
DateTime get_date(const char * _sz_date, bool _b_trunc_year)
{
DateTime _obj_dt;
// "01/02/2003" - format of the data
string _str_date = _sz_date;
//--------------
string _str_month;
string _str_year;
int _n_day;
int _n_month;
int _n_year;
///--------------
bool _b_1 = false;
bool _b_2 = false;
size_t _n_pos_1 = 0;
size_t _n_pos_2 = 0;
///--------------
for (size_t _un_num = 0; _un_num < _str_date.size(); _un_num++)
{
if(_str_date[_un_num] == '/')
{
///-----------------
if(!_b_1)
{
_b_1 = true;
_n_pos_1 = _un_num;
continue;
}
///-----------------
if(_b_1 && !_b_2)
{
_b_2 = true;
_n_pos_2 = _un_num;
}
///-----------------
}
}
///--------------
if(!_b_1 || !_b_2)
{
return _obj_dt;
}
///--------------
_str_month = _str_date.substr( _n_pos_1 + 1, ( _n_pos_2 - _n_pos_1 ) - 1 );
_str_year = _str_date.substr( _n_pos_2 + 1, ( _str_date.size() - 1 ) - _n_pos_2 );
if(_b_trunc_year)
{
if(_str_year.size() >=4)
{
_str_year = _str_year.substr(2,2);
}
}
sscanf(_str_month.c_str(), "%d", &_n_month);
sscanf(_str_year .c_str(), "%d", &_n_year);
_n_day = 1;
_obj_dt = DateTime(_n_year,_n_month,_n_day);
return _obj_dt;
}
Парсим дату формата mm/dd/yyyy. Не все так просто в этой жизни.
+5
//...
string m_str_datum, m_str_zeit;
m_str_datum.assign(m_str_data , 22 , 6 );
m_str_zeit.assign(m_str_data , 28 , 6 );
m_str_datum = remove_spaces(m_str_datum) ;
m_str_zeit = remove_spaces(m_str_zeit);
string _str_year;
string _str_month;
string _str_day;
int _n_year;
int _n_month;
int _n_day;
_n_year = 0;
_n_month = 0;
_n_day = 0;
_str_day.assign(m_str_datum,0,2);
_str_month.assign(m_str_datum,2,2);
_str_year.assign(m_str_datum,4,2);
sscanf( _str_day.c_str() , "%d", &_n_day );
sscanf( _str_month.c_str(), "%d", &_n_month );
sscanf( _str_year.c_str() , "%d", &_n_year );
if (_n_year > 0 && _n_year < 50)
_n_year += 2000;
else if (_n_year >= 50 && _n_year < 100)
_n_year += 1900;
//...
string _str_hours;
string _str_minutes;
string _str_seconds;
int _n_hours;
int _n_minutes;
int _n_seconds;
_n_hours = 0;
_n_minutes = 0;
_n_seconds = 0;
_str_hours.assign(m_str_zeit,0,2);
_str_minutes.assign(m_str_zeit,2,2);
_str_seconds.assign(m_str_zeit,4,2);
sscanf( _str_hours.c_str() , "%d", &_n_hours );
sscanf( _str_minutes.c_str() , "%d", &_n_minutes );
sscanf( _str_seconds.c_str() , "%d", &_n_seconds );
DateTime _obj_start_time;
try {
_obj_start_time = DateTime(_n_year, _n_month, _n_day, _n_hours, _n_minutes, _n_seconds);
}
//...
Парсим дату ddmmyyhhnnss не по-детски. Код функции которая обрабатывает несколько сотен тысяч строк.
−166.2
SELECT DISTINCT B.TYPE_SID, B.ID BANNER_ID, B.WEIGHT BANNER_WEIGHT,
B.SHOWS_FOR_VISITOR, B.FIX_CLICK, B.FIX_SHOW, B.KEYWORDS BANNER_KEYWORDS,
C.ID CONTRACT_ID, C.WEIGHT CONTRACT_WEIGHT, C.KEYWORDS CONTRACT_KEYWORDS
FROM b_adv_type T
INNER JOIN b_adv_banner B ON ( B.ACTIVE='Y' and B.TYPE_SID = T.SID
and B.STATUS_SID = 'PUBLISHED'
and (B.FOR_NEW_GUEST is null or B.FOR_NEW_GUEST='N')
and (ifnull(B.MAX_SHOW_COUNT,0)>ifnull(B.SHOW_COUNT,0)
or ifnull(B.MAX_SHOW_COUNT,0)=0) and (ifnull(B.MAX_CLICK_COUNT,0)>ifnull(B.CLICK_COUNT,0)
or ifnull(B.MAX_CLICK_COUNT,0)=0) and (ifnull(B.MAX_VISITOR_COUNT,0)>ifnull(B.VISITOR_COUNT,0)
or ifnull(B.MAX_VISITOR_COUNT,0)=0) and (B.DATE_SHOW_FROM<=now() or B.DATE_SHOW_
FROM is null or length(B.DATE_SHOW_FROM)<=0) and (B.DATE_SHOW_TO>=now()
or B.DATE_SHOW_TO is null or length(B.DATE_SHOW_TO)<=0))
INNER JOIN b_adv_banner_2_site BS ON ( BS.BANNER_ID = B.ID and BS.SITE_ID = 'ru')
INNER JOIN b_adv_contract C ON ( C.ID = B.CONTRACT_ID and C.ACTIVE='Y'
and (ifnull(C.MAX_SHOW_COUNT,0)>ifnull(C.SHOW_COUNT,0)
or ifnull(C.MAX_SHOW_COUNT,0)=0) and (ifnull(C.MAX_CLICK_COUNT,0)>ifnull(C.CLICK_COUNT,0)
or ifnull(C.MAX_CLICK_COUNT,0)=0) and (ifnull(C.MAX_VISITOR_COUNT,0)>ifnull(C.VISITOR_COUNT,0)
or ifnull(C.MAX_VISITOR_COUNT,0)=0) and (C.DATE_SHOW_FROM<=now() or C.DATE_SHOW_
FROM is null or length(C.DATE_SHOW_FROM)<=0) and (C.DATE_SHOW_TO>=now() or C.DATE_SHOW_TO is null
or length(C.DATE_SHOW_TO)<=0))
INNER JOIN b_adv_contract_2_site CS ON ( CS.CONTRACT_ID = B.CONTRACT_ID and CS.SITE_ID = 'ru')
INNER JOIN b_adv_contract_2_type CT ON ( CT.CONTRACT_ID = C.ID
and (CT.TYPE_SID = 'ALL' or CT.TYPE_SID = T.SID))
INNER JOIN b_adv_banner_2_weekday BW ON ( BW.BANNER_ID = B.ID
and BW.C_WEEKDAY='SUNDAY' and BW.C_HOUR = '11')
INNER JOIN b_adv_contract_2_weekday CW ON ( CW.CONTRACT_ID = C.ID
and CW.C_WEEKDAY='SUNDAY' and CW.C_HOUR = '11')
LEFT JOIN b_adv_banner_2_group UG1 ON ( (UG1.BANNER_ID = B.ID and UG1.GROUP_ID in (2,1,21)) )
LEFT JOIN b_adv_banner_2_page BP1 ON ( BP1.BANNER_ID = B.ID and BP1.SHOW_ON_PAGE='Y')
LEFT JOIN b_adv_banner_2_page BP2 ON ( BP2.BANNER_ID = B.ID and BP2.SHOW_ON_PAGE='N'
and '/e-store/books/index.php?SECTION_ID=145' like concat(BP2.PAGE, '%'))
LEFT JOIN b_adv_contract_2_page CP1 ON ( CP1.CONTRACT_ID = C.ID and CP1.SHOW_ON_PAGE='Y')
LEFT JOIN b_adv_contract_2_page CP2 ON ( CP2.CONTRACT_ID = C.ID and CP2.SHOW_ON_PAGE='N'
and '/e-store/books/index.php?SECTION_ID=145' like concat(CP2.PAGE, '%'))
LEFT JOIN b_adv_banner_2_stat_adv BA ON BA.BANNER_ID = B.ID
LEFT JOIN b_adv_banner_2_country BC ON BC.BANNER_ID = B.ID WHERE T.ACTIVE = 'Y'
and BP2.ID is null and CP2.ID is null
and (BP1.ID is null or '/e-store/books/index.php?SECTION_ID=145' like concat(BP1.PAGE, '%'))
and (CP1.ID is null or '/e-store/books/index.php?SECTION_ID=145' like concat(CP1.PAGE, '%'))
and (BA.STAT_ADV_ID is null or BA.STAT_ADV_ID='0')
and (BC.COUNTRY_ID is null or BC.COUNTRY_ID='N0')
and ( (B.SHOW_USER_GROUP = 'Y' and UG1.GROUP_ID is not null)
or (B.SHOW_USER_GROUP <> 'Y' and UG1.GROUP_ID is null))
ORDER BY B.TYPE_SID desc, C.ID desc
SQL-запрос из Битрикса
http://ekimoff.ru/165/
+155.7
function clean(str, pat){
var m = len(pat);
var l="", r = "";
var t = 0;
while(str.indexOf(pat)!=-1){
t = str.indexOf(pat);
l = str.slice(0, t);
r = str.slice(t+m);
str = l+r;
}
return str;
}
+156
<?
$i=$var = null;
function NullPointerShare(&$vv)
{
for (;;)
{
$i=$vv;
$i++;
if ($i==20)
{
$i=null;
die (NullPointerShare($i));
}else if ($i<20){
$ix=19;
die (NullPointerShare($ix));
}
}
return $vv;
}
die ("--> ".NullPointerShare($var));
?>
Без коментов:)
+20.7
.....
int i;
.....
int b=i/2;
if(i==b*2)//проверка на четность
{
.....