- 1
- 2
- 3
- 4
- 5
- 6
- 7
function attribute( $attr ) {
if( method_exists( $this, $attr ) ) {
return $this->$attr();
}
return $this->$attr();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+57
function attribute( $attr ) {
if( method_exists( $this, $attr ) ) {
return $this->$attr();
}
return $this->$attr();
}
Видимо сначало было без проверки.
+56
function isAvailable( $args ) {
$available = fetchAvailability( $args );
return $available ? 'yep' : 'noup';
}
// Где-то в javascript после вызова isAvailable()
function isAvailableCallback( result ) {
if ( result === 'yep' ) {
...
}
}
Альтернативный способ работы с логическим типом данных. Используется как и в javascript так и в php.
+68
/*
* Todo Гавнокод
* Надо как то поуниверсальнее сделать
* А то когда модель вмешавается в отображение, это криворукость
*/
private static String ___recurGet(Dir dir){
MorphiaQuery dirs = dir.getDirList();
String id = dir.getIdAsStr(),
name = dir.name;
String html = "<div class=\"bottom-line\">";
html += "<a href=\"#\" onclick=\"setPrnt('"+id+"')\" id=\""+id+"\">";
html += name;
html += "</a>";
html += "<div class=\"pull-right\">";
html += "<a href=\"#\" class=\"icon-trash\" onclick=\"deleteNode('"+id+"')\"></a>";
html += "</div>";
html += "</div>";
if(dirs.count() < 1)
return html;
html += "<ul>";
for(int i = 0; i < dirs.count(); i++){
html += "<li>";
html += ___recurGet((Dir)dirs.offset(i).first());
html += "</li>";
}
html += "</ul>";
return html;
}
public static String getTreeAsHtml(String _typ){
MorphiaQuery dirs = getRootDirList().filter("typ",Type.valueOf(_typ));
if(dirs.count() < 1)
return "Категорий нет";
String html = "<ul id=\"treeView\">";
for(int i = 0; i < dirs.count(); i++){
html += "<li>";
html += ___recurGet((Dir)dirs.offset(i).first());
html += "</li>";
}
html += "</ul>";
return html;
}
В модели "категория" написал метод для получения дерева категории в виде html кода...
Причем такая генерация должна происходить в view, а сделал как обычно через ж
+54
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex) {
$isValid = false;
} else {
$domain = substr($email, $atIndex + 1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64) {
// local part length exceeded
$isValid = false;
} else if ($domainLen < 1 || $domainLen > 255) {
// domain part length exceeded
$isValid = false;
} else if (!strrpos($domain, ".")) {
// domain part does not have .
$isValid = false;
} else if ($domain[0] == '.' || $domain[$domainLen - 1] == '.') {
// domain part starts or ends with '.'
$isValid = false;
} else if ($local[0] == '.' || $local[$localLen - 1] == '.') {
// local part starts or ends with '.'
$isValid = false;
} else if (preg_match('/\\.\\./', $local)) {
// local part has two consecutive dots
$isValid = false;
} else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) {
// character not valid in domain part
$isValid = false;
} else if (preg_match('/\\.\\./', $domain)) {
// domain part has two consecutive dots
$isValid = false;
} else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\", "", $local))) {
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\", "", $local))) {
$isValid = false;
}
}
/* if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) {
// domain not found in DNS
$isValid = false;
} */
}
return $isValid;
}
Интересно а автор когдата слишал про filter_var?
Это все можна заменить на filter_var($input, FILTER_VALIDATE_EMAIL);
Товаришь программист! Не умеешь срать - не мучай жопу!
+54
$postitle = str_replace (' ', '-', $title);
$postitle = str_replace ('/', '', $postitle);
$postitle = str_replace ('\\', '', $postitle);
$postitle = str_replace (':', '', $postitle);
$postitle = str_replace ('<', '', $postitle);
$postitle = str_replace ('>', '', $postitle);
$postitle = str_replace ('*', '', $postitle);
$postitle = str_replace ('?', '', $postitle);
$postitle = str_replace ('|', '', $postitle);
$postitle = str_replace ('"', '', $postitle);
$postitle = preg_replace ('#\[.*?\]#isu', '', $postitle);
+43
public static function create(AdGroupVO $vo)
{
UtilLog::debug('FUCK');
...
+160
jQuery('#text div.catalog_light div.num input[type="text"]').spinner({max: 999, min: 1});
jQuery('#text div.catalog_light div.num .ui-spinner-up').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog_light div.num .ui-spinner-down').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog_item_right div.line div.spinner input[type="text"]').spinner({max: 999, min: 1});
jQuery('#text div.catalog_item_right div.line div.spinner .ui-spinner-up').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog_item_right div.line div.spinner .ui-spinner-down').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog_item_additional div.double table div.spinner input[type="text"]').spinner({max: 999, min: 1});
jQuery('#text div.catalog_item_additional div.double table div.spinner .ui-spinner-up').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog_item_additional div.double table div.spinner .ui-spinner-down').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog div.content div.text div.spinner input[type="text"]').spinner({max: 999, min: 1});
jQuery('#text div.catalog div.content div.text div.spinner .ui-spinner-up').html('').css({'width' : '22px'}).css({'height' : '22px'});
jQuery('#text div.catalog div.content div.text div.spinner .ui-spinner-down').html('').css({'width' : '22px'}).css({'height' : '22px'});
+175
public static IEnumerable<float> Single(float from, float to, float step)
{
if (step <= 0.0f) step = (step == 0.0f) ? 1.0f : -step;
if (from <= to)
{
for (float f = from; f <= to; f += step) yield return f;
}
else
{
for (float f = from; f >= to; f -= step) yield return f;
}
}
public static IEnumerable<double> Double(double from, double to, double step)
{
if (step <= 0.0) step = (step == 0.0) ? 1.0 : -step;
if (from <= to)
{
for (double d = from; d <= to; d += step) yield return d;
}
else
{
for (double d = from; d >= to; d -= step) yield return d;
}
}
Такие методы накопированы для всех типов данных, которые известны поциенту.
Но особо интересны эти джва метода
Unlike some other programmimg languages (notably F#), C# doesn't have any built-in support for dealing with ranges of numbers. The .NET Framework does have the Enumerable.Range() method.
- It can only deal with Int32's.
- You can't specify a 'step' from one element of the range to the next. In effect, the step is always one. In this article, I'd therefore like to present a static Range class to deal with these deficiencies.
http://www.c-sharpcorner.com/uploadfile/b942f9/dealing-with-ranges-of-numbers-in-C-Sharp
+63
Лех, разве код <?php CREATE DATABASE tbl_name; ?> не должен создать БД?
Пришло в аське
+34
void
XmlRpcDispatch::work(double timeout)
{
...
nEvents = select(maxFd+1, &inFd, &outFd, &excFd, NULL);
...
}
void XmlRpcDispatch::terminate() {
...
XmlRpcSocket::connect(_cmd_sock, "127.0.0.1", port);
...
}
Не то чтобы говнокод, но забавный костыль. А как еще корректно выйти из select'a, ждущего входящих соединений? Создать соединение самому.