- 1
- 2
- 3
- 4
- 5
--Вариант 1:
SELECT round(term/2::real::integer)
--Вариант 2:
SELECT term/2+term%2
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−112
--Вариант 1:
SELECT round(term/2::real::integer)
--Вариант 2:
SELECT term/2+term%2
Цель: определить номер курса от номера семестра (term).
Просим выбрать лучший вариант.
+161
function fill(){ //
document.getElementById('email1').value = "Введіть ваш e-mail";
document.getElementById('u_name2').value = "Введіть ваше імя";
document.getElementById('u_adress1_1').value = "Введіть вашу адресу";
}
// Перевірка імен, імейла та адреси в полі
function check_name(){if (document.getElementById('u_name2').value == "Введіть ваше імя" || document.getElementById('u_name2').value.length < 3 ) {error_name();}else{checked_name();}}
function check_email(){if (document.getElementById('email1').value == "Введіть ваш e-mail") {error_email();}else{checked_email();}}
function check_adress(){if (document.getElementById('u_adress1_1').value == "Введіть вашу адресу") {error_adress();}else{checked_adress()};}
// Якщо імя .. введене неправильно
function error_name(){document.getElementById('d_name').innerHTML = "Невірно вказане імя (мінімум 3 символа)"; document.getElementById('d_name').style.color="red";}
function error_email(){document.getElementById('d_email').innerHTML = "Невірно вказаний email"; document.getElementById('d_email').style.color="red";}
function error_adress(){document.getElementById('d_adress').innerHTML = "Невірно вказана адреса"; document.getElementById('d_adress').style.color="red";}
// Якщо імя .. введене правильно
function checked_name(){document.getElementById('d_name').innerHTML = "Імя вказане вірно"; document.getElementById('d_name').style.color="green";}
function checked_email(){document.getElementById('d_email').innerHTML = "email вказаний вірно"; document.getElementById('d_email').style.color="green"}
function checked_adress(){document.getElementById('d_adress').innerHTML = "Адреса вказана вірно"; document.getElementById('d_adress').style.color="green"}
Сорри за украинский язык, думаю понятно. Сказали 30 минут писать джаваскрипт, вот и писали... :))
+173
// app/code/Core/Mage/Catalog/Model/Resource/Eav/Attribute.php:68
Mage::throwException('0_o');
Из Magento 1.4.1.0.
Когда вылетело при дебаге, решил, что пора на дурку двигать...
+144
http://nemolaboratory.ru/blog/about_a_miscellaneous/Nemo-Laboratory-About
Напишите здесь все свои замечания, буду благодарен
+129
if (obj == null)
return 0;
if (obj == DBNull.Value)
return 0;
return int.Parse (obj.ToString ());
в столбце хранится Integer...
+169
<?php
$res = "-1";
if($num>0) {
for($d=1;$d<=$num;$d++) {
$res.=",".$data[$d-1];
}
$res=substr($res,3,100000);
$res=str_replace(",",", ", $res);
}
?>
+165
$res = explode(" ", $price);
$price = trim(str_replace(".", "", str_replace(",", "", substr(trim($res[0]), 0, strlen(trim($res[0])) - 2))));
Изначально в переменной $price строка такого вида: 144.07 РУБ.
Судя по всему автор хотел таким образом получить из нее целое значение
−155
@image = (image unless image.nil?) or
(Rubygame::Surface.autoload(image_file) unless image_file.nil?) or
(Rubygame::Surface.autoload("#{@name}.png") unless @name.nil?) or
Rubygame::Surface.new([16, 16])
(c) http://stackoverflow.com/questions/3690508
+154
// $curr_page - старница, на который сейчас находимся
// $n_page - число страниц
// $count - обще число записей
// $param - site - страницы на сайте
// - adm - в админке
function genNumPage($curr_page, $n_page, $count, $param=null) {
$string = parse_url($_SERVER['REQUEST_URI']);
$query = '?'.$string['query'];
$num_page = ceil($count / $n_page);
if (isset($param)) $table = new my_Page("site/site_interface.html", "num_page");
else $table = new my_Page("interface/interface.html", "num_page");
if ($num_page < 2) return null;
for ($i = 1; $i <= $num_page; $i++) {
if ($i != $curr_page) {
if (preg_match('/\?p\=[0-9]{1,3}/', $query)) $href = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.$i, $query);
elseif (preg_match('/\&p\=[0-9]{1,3}/', $query)) $href = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.$i, $query);
elseif ($string['query'] != '') $href = '?'.$string['query'].'&p='.$i;
else $href = '?p='.$i;
if ((!$param) || ($param == 'adm')) $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> ";
else $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> | ";
}
elseif ((!$param) || ($param == 'adm')) $str .= "<span>".$i."</span>";
else $str .= "<span>".$i."</span> | ";
}
if ($curr_page > 1) {
if (preg_match('/\?p\=[0-9]{1,3}/', $query)) $prev = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page - 1), $query);
elseif (preg_match('/\&p\=[0-9]{1,3}/', $query)) $prev = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page - 1), $query);
elseif ($string['query'] != '') $prev = '?'.$string['query'].'&p='.($curr_page - 1);
else $prev = '?p='.($curr_page - 1);;
if ((!$param) || ($param == 'adm')) $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">←</a> ";
else $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">Предыдущая</a> ";
}
if ($curr_page < $num_page) {
if (preg_match('/\?p\=[0-9]{1,3}/', $query)) $next = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page + 1), $query);
elseif (preg_match('/\&p\=[0-9]{1,3}/', $query)) $next = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page + 1), $query);
elseif ($string['query'] != '') $next = '?'.$string['query'].'&p='.($curr_page + 1);
else $next = '?p='.($curr_page + 1);;
if ((!$param) || ($param == 'adm')) $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">→</a> ";
else $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">Следующая</a> ";
}
$table->addValueArray(array(
"NUM" => $str,
"PREV" => $prev,
"NEXT" => $next
));
return $table->myReplace();
}
Генерирует номера страниц. Из одной CMS'ки.
+165
class microTimer {
function start() {
global $starttime;
$mtime = microtime();
$mtime = explode( ' ', $mtime );
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
}
function stop() {
global $starttime;
$mtime = microtime();
$mtime = explode( ' ', $mtime );
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = round( ($endtime - $starttime), 5 );
return $totaltime;
}
}
DLE 9.0