- 1
preg_match('/(.*?)[.,!|]/',ltrim(preg_replace('/[\n\r]+/','|',strip_tags($item[$this->tooltip])),'|'),$regs);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+168
preg_match('/(.*?)[.,!|]/',ltrim(preg_replace('/[\n\r]+/','|',strip_tags($item[$this->tooltip])),'|'),$regs);
жонглирование регулярками
+145
this.getRgbaAtColor = function(color)
{
color = (color.charAt(0)=="#") ? color.substring(1,9):color;
color = (color.substring(0,2)=="0x") ? color.substring(2,10):color;var r = parseInt(color.substring(0,2),16);
var g = parseInt(color.substring(2,4),16);
var b = parseInt(color.substring(4,6),16);
var a = color.substring(6,8);
a = (a=="") ? 255:parseInt(a,16);
return "rgba("+r+","+g+","+b+","+(a/255)+")";
}
геймдев..
+159
//так было до
<?php
// дневной/ночной фон
$now=date("G");
if (($now > 8) and ($now<21))
{echo "странице задаётся дневной фон";}
else
{echo "странице задаётся ночной фон";}
//время на сервере
echo date("Время на сервере H:i");
//Выводятся знаменательные события в истории за этот день (ps: просто из папки events берётся фйл с названием $today
$today=date("d_M");
$event=file("event/$today");
$line=count($event);
echo "<center>",$event[rand(0,$line-1)],"</center>";
$mon=explode("_",$today);
$rus=array("Dec"=>"декабря");
echo "<a href=\"http://ru.wikipedia.org/wiki/",$mon[0],"_",$rus[$mon[1]]>Подробнее о этом дне в Истории</a>";
//история посещений
$ip=$_SERVER['REMOTE_ADDR']." | ".date("d M H:i:s")."\n";
?>
//так стало после
<?php
// дневной/ночной фон
$now=date("d_M_G:i:s");
$time=explode("_",$now);
$hour=explode(":",$time[2]);
if (($hour[0] > 8) and ($hour[0]<21))
{echo "странице задаётся дневной фон";}
else
{echo "странице задаётся ночной фон";}
//время на сервере
echo "Время на сервере ",$hour[0],":",$hour[1];
//Выводятся знаменательные события в истории за этот день (ps: просто из папки events берётся фйл с названием $today
$today=$time[0]." ".$time[1];
$event=file("event/$today");
$line=count($event);
echo "<center>",$event[rand(0,$line-1)],"</center>";
$rus=array("Dec"=>"декабря");
echo "<a href=\"http://ru.wikipedia.org/wiki/",$time[0],"_",$rus[$time[1]]>Подробнее о этом дне в Истории</a>";
//история посещений
$ip=$_SERVER['REMOTE_ADDR']." | ".$now."\n";
?>
Так сказать попытка оптимизировать код. Был первый вариант, где функция date использовалась 4 раза с разными параметрами.
Ну и я решил свести всё к одной date... уж и не знаю... был ли смысл) быстрее ли от этого всё будет работать...))
−109
end;
create or replace package body "MUT_TABLE" is
type a_table is table of number index by pls_integer;
position a_table;
empty a_table;
procedure SET_INITIAL_STATE
as
begin
position:=empty;
end SET_INITIAL_STATE;
procedure BEF_TR( ID IN NUMBER, A IN NUMBER)
as
begin
position (ID):= A;
end BEF_TR;
procedure AFT_TR
is
v number;
begin
v:=position.FIRST;
while v is not null loop
update A set
A=1,
B='!!!!!!!!!'
where A = 1;
v:= position.next(v);
end loop;
end AFT_TR;
end "MUT_TABLE";
−100
module ModelHelper
extend ActiveSupport::Concern
module InstanceMethods
def prepare_url
"http://#{Banjo::Application.config.short_url_host}"
end
def adjust_comment(text, url, max_len)
maximum_text_length = max_len - url.length - 1
if text.length > maximum_text_length
text = text[0, maximum_text_length - 3] + "..."
end
if url.present?
message = [text, url].join(' ')
else
message = text
end
message
end
def fullname_to_first_last_initial(fullname)
name_token = fullname.split(/ /)
last_initial = (name_token.length > 1) ? name_token.pop.first : nil
first = name_token.join(' ')
return (last_initial.nil?) ? first : "#{first} #{last_initial}"
end
end
module ClassMethods
def adjust_comment(text, url, max_len)
maximum_text_length = max_len - url.length - 1
if text.length > maximum_text_length
text = text[0, maximum_text_length - 3] + "..."
end
if url.present?
message = [text, url].join(' ')
else
message = text
end
message
end
def fullname_to_first_last_initial(fullname)
name_token = fullname.split(/ /)
last_initial = (name_token.length > 1) ? name_token.pop.first : nil
first = name_token.join(' ')
return (last_initial.nil?) ? first : "#{first} #{last_initial}"
end
end
end
DRY principle in action
+162
function url_rewriter(){
$rules=file_get_contents("system/static/rewrite_rules.conf");
$rules=explode("\n",$rules);
for ($i=0;$i<count($rules);$i++){
$z=explode(" ",$rules[$i]);
$r[$z[0]]=$z[1];
}
foreach ($r as $n => $v)
{
if ("si".$_GET['url']==$n or "si".$_GET['url']==$n."/") { $_GET['page']=$v; $ok=1;}
if ("ab".$_GET['url']==$n or "ab".$_GET['url']==$n."/") { $_GET['page']=$v; $ok=1;}
if ("inter".$_GET['url']==$n or "inter".$_GET['url']==$n."/") {$_GET['page']=$v; $ok=1;}
if ("he".$_GET['url']==$n or "he".$_GET['url']==$n."/") {$_GET['page']=$v; $ok=1;}
}
if ("inter".$_GET['url']=="internet-service/cabinet/basket/mobileterminal"||
"inter".$_GET['url']=="internet-service/cabinet/basket/mobileterminal/"){
$_GET['page']=14;
$ok=1;
$_GET['mobileterminal']="on";
unset($_GET['url']);
}
return $ok;
}
Реализация ЧПУ...
+159
$t2 = db_query("SELECT
COUNT(*)
FROM
order_delivery_offers AS odf,
uc_orders AS uo
WHERE
odf.order_id = uo.order_id AND
uo.uid = $uid AND
uo.order_status = 'accepted' AND
odf.status = 'accepted' AND
odf.visible = 1 AND
odf.active = 1
GROUP BY odf.order_id");
$count_rows2 = 0;
while ($r2 = db_fetch_array($t2)){
$count_rows2++;
}
Подсчет количества записей в запросе.
+168
case IDC_LED1_ZERO:
if (::IsDlgButtonChecked (hWnd,IDC_LED1_ZERO) )
{
if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_POSITION) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_POSITION) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_POSITION) )
::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
::CheckDlgButton(hWnd,IDC_LED2_ZERO,0);
::CheckDlgButton(hWnd,IDC_LED3_ZERO,0);
::CheckDlgButton(hWnd,IDC_LED4_ZERO,0);
}
break;
case IDC_LED1_ANYSPEED:
if (::IsDlgButtonChecked (hWnd,IDC_LED1_ANYSPEED) )
{
if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_POSITION) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_POSITION) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_POSITION) )
::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
::CheckDlgButton(hWnd,IDC_LED2_ANYSPEED,0);
::CheckDlgButton(hWnd,IDC_LED3_ANYSPEED,0);
::CheckDlgButton(hWnd,IDC_LED4_ANYSPEED,0);
}
break;
case IDC_LED1_POSITION:
if (::IsDlgButtonChecked (hWnd,IDC_LED1_POSITION) )
{
if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
::CheckDlgButton(hWnd,IDC_LED1_TURN_UNDER,0);
::CheckDlgButton(hWnd,IDC_LED2_POSITION,0);
::CheckDlgButton(hWnd,IDC_LED3_POSITION,0);
::CheckDlgButton(hWnd,IDC_LED4_POSITION,0);
}
break;
case IDC_LED1_TURN_UNDER:
if (::IsDlgButtonChecked (hWnd,IDC_LED1_TURN_UNDER) )
{
if (::IsDlgButtonChecked (hWnd,IDC_LED2_ZERO) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_ZERO) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_ZERO) )
::CheckDlgButton(hWnd,IDC_LED1_ZERO,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_ANYSPEED) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_ANYSPEED) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_ANYSPEED) )
::CheckDlgButton(hWnd,IDC_LED1_ANYSPEED,0);
if (::IsDlgButtonChecked (hWnd,IDC_LED2_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED3_DIGITAL_INPUT) ||
::IsDlgButtonChecked (hWnd,IDC_LED4_DIGITAL_INPUT) )
::CheckDlgButton(hWnd,IDC_LED1_DIGITAL_INPUT,0);
::CheckDlgButton(hWnd,IDC_LED1_POSITION,0);
::CheckDlgButton(hWnd,IDC_LED2_TURN_UNDER,0);
::CheckDlgButton(hWnd,IDC_LED3_TURN_UNDER,0);
::CheckDlgButton(hWnd,IDC_LED4_TURN_UNDER,0);
}
Понадобилось добавить ещё один чек бокс. Зашёл в обработчик - а там такое. И это только начало, всё не поместилось. Чтобы представить масштабы скажу, что чекбоксов 16..., я должен добавить ещё 4.
+147
function rating() {
@session_start();
session_register ("set_ms");
if (isset($_SESSION['set_ms'])) {
return false; // старый посетитель
} else {
@session_start();
session_register ("set_ms");
$_SESSION['set_ms'] = rand(10000, 99999);
return true; // новый посетитель
};
}
−117
private function dateLabel(item:Object, column:AdvancedDataGridColumn):String
{
var df:DateFormatter = new DateFormatter();
df.formatString = "DD.MM.YYYY JJ:SS"
return df.format(item[column.dataField]);
}
перепутал минуты с секундами, тестер долго понять не мог, на сколько часы на сервере спешат )