- 1
Ура, WCT
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+5
Ура, WCT
https://habrahabr.ru/post/305190/
+3
assertArrayEquals("f g h i j k l m n o".split("\\s"), actualValuesArray);
assertArrayEquals(Lists.reverse(Arrays.asList("l m n o p q r s t u".split("\\s"))).toArray(), actualValuesArray);
Когда лень руками создавать массив строк и сложно перечислить буквы в обратном порядке
+1
public void testGetInactiveSessionIds() throws Exception {
Session inactive1 = createTestSession();
Session inactive2 = createTestSession();
Thread.sleep(1001);
Date timestamp = new Date();
Thread.sleep(1001);
List<String> inactiveSessions = sessionDAO.getSessionsWithLastAccessTimeBefore(timestamp);
assertEquals(2, inactiveSessions.size());
assertTrue(inactive1.getId().equals(inactiveSessions.get(0)) || inactive1.getId().equals(inactiveSessions.get(1)));
assertTrue(inactive2.getId().equals(inactiveSessions.get(0)) || inactive2.getId().equals(inactiveSessions.get(1)));
}
Юнит тест поиск неактивных сессий перед их закрытием. Тут прекрасны задержки на секунду и проверка что сессия содержится в списке inactive
−4
public static int opposite(int number)
{
if(number>0){
return number - number - number;
} if (number<0){
return number - number - number;
}return opposite(number);
}
}
Это так я по фасту решил задачу из положительных чисел сделать отрицательные и наоборот :D
0
do {
if ( array_key_exists( 'smd', $_GET ) ) {
$this->response[] = $this->getServiceMap();
$this->hasCalls = TRUE;
break;
}
$error = $this->getRequest();
if ( $error ) {
$this->response[] = $this->getError( $error );
$this->hasCalls = TRUE;
break;
}
foreach( $this->calls as $call ) {
$error = $this->validateCall( $call );
if ( $error ) {
$this->response[] = $this->getError( $error[0], $error[1], $error[2] );
$this->hasCalls = TRUE;
} else {
$result = $this->processCall( $call );
if ( $result ) {
$this->response[] = $result;
$this->hasCalls = TRUE;
}
}
}
} while(FALSE);
Угадайте, зачем?
+2
<? if (mail($mail, $subject, $text, $headers))
{
?>
<?=('<div class="container"><div class="row"><div class="block-header col-lg-12 col-md-12 col-sm-12 col-xs-12"><h2>Благодарим Вас за обращение, в ближайшее время с вами свяжется наш сотрудник.</h2></div></div></div>')?>
<?
} else {
?>
<?=('<br><b>Возникли проблемы при отправке почты</b>')?>
<?
} ?>
попросили поправить код после предыдущего разраба )
+1
if ($can_null || $can_unnull) {
...
}
Когда удачно назвал переменную.
+8
#include <iostream>
using namespace std;
class Boolean {
public:
Boolean() : m_flag(false), m_val(0) {}
Boolean(bool flag) : m_flag(flag), m_val(0) {}
Boolean(bool flag, int val) : m_flag(flag), m_val(val) {}
Boolean operator || (int val) {
return Boolean(m_flag || val == m_val, m_val);
}
operator bool() { return m_flag; }
private:
bool m_flag;
int m_val;
};
class Integer {
public:
Integer() : m_val(0) {}
Integer(int val) : m_val(val) {}
operator int() { return m_val; }
Boolean operator == (int val) { return Boolean(val == m_val, m_val); }
Boolean operator == (const Integer & val) { return Boolean(val.m_val == m_val, m_val); }
private:
int m_val;
};
int main() {
Integer a(10);
cout << bool(a == 15 || 10) << endl;
cout << bool(a == 15 || 11) << endl;
cout << bool(a == 15 || 11 || 13 || 11 || 0 || 10 || 5) << endl;
cout << bool(a == 15 || 11 || 13 || 11 || 0 || 9 || 5) << endl;
return 0;
}
https://ideone.com/xwMvx7
+6
$redir_url = $_conf['www_patch'].str_replace("//////","/",$path[0]);
$redir_url = $_conf['www_patch'].str_replace("/////","/",$path[0]);
$redir_url = $_conf['www_patch'].str_replace("////","/",$path[0]);
$redir_url = $_conf['www_patch'].str_replace("///","/",$path[0]);
$redir_url = $_conf['www_patch'].str_replace("//","/",$path[0]);
Ну ниасилили ребята регулярки...
+4
$aProductType = [];
$productName = $conn->query("SELECT value FROM catalog_product_entity_varchar WHERE entity_id = '" . $value['entity_id'] . "' AND attribute_id = 71")->fetch();
$productUrl = $conn->query("SELECT value FROM catalog_product_entity_varchar WHERE entity_id = '" . $value['entity_id'] . "' AND attribute_id = 98")->fetch();
$productImage = $conn->query("SELECT value FROM catalog_product_entity_media_gallery WHERE entity_id = '" . $value['entity_id'] . "'")->fetchAll();
$productPrice = $conn->query("SELECT value FROM catalog_product_entity_decimal WHERE entity_id = '" . $value['entity_id'] . "' AND attribute_id = 75")->fetch();
$productType = $conn->query('SELECT category_id FROM catalog_category_product WHERE product_id = ' . $value['entity_id'])->fetchAll();
$productAvailable = $conn->query('SELECT qty FROM cataloginventory_stock_item WHERE product_id = ' . $value['entity_id'])->fetch();
$productDesc = $conn->query('SELECT value FROM catalog_product_entity_text WHERE entity_id = "' . $value['entity_id'] . '"')->fetch();
Magento, controller, indexAction, front