- 1
- 2
- 3
- 4
for i in for i in itertools.count():
# ...
if i >= x:
break
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
for i in for i in itertools.count():
# ...
if i >= x:
break
+1
#include <iostream>
#include <functional>
#include <array>
#include <iterator>
template <class T>
class Filter : public std::iterator<
std::input_iterator_tag,
typename std::iterator_traits<T>::value_type,
typename std::iterator_traits<T>::difference_type,
typename std::iterator_traits<T>::pointer,
typename std::iterator_traits<T>::reference
>
{
private:
typedef typename std::iterator_traits<T>::value_type value_type;
std::function<bool(value_type)> m_predicate;
T m_begin, m_end;
value_type m_current;
public:
Filter(T t_begin, T t_end, std::function<bool(value_type)> t_predicate)
: m_begin(t_begin), m_end(t_end), m_predicate(t_predicate)
{
}
Filter<T>& begin()
{
return ++*this;
}
Filter<T>& end()
{
return *this;
}
value_type operator* ()
{
return m_current;
}
Filter<T>& operator++ ()
{
do {
m_current = *m_begin;
++m_begin;
} while (m_begin != m_end && !m_predicate(m_current));
return *this;
}
bool operator!= (Filter<T>& t_right)
{
return m_begin != t_right.m_end;
}
};
int main()
{
std::array<int, 10> arr{ {4, 35, 0, 23, 0, 0, 5} };
for (auto i : Filter<typename std::array<int,10>::iterator>(arr.begin(), arr.end(), [](int x){return x != 0;})) {
std::cout << i << " ";
}
}
+1
function getCartMiniViewDisplayString($cart_entries) {
$count = $cart_entries->getProductCount();
$suffix = "";
$remainder = $count % 10;
switch($remainder) {
case 1:
$suffix = " товар";
break;
case 2:
case 3:
case 4:
$suffix = " товара";
break;
case 5:
case 6:
case 7:
case 8:
case 9:
case 0:
$suffix = " товаров";
break;
}
return $count . $suffix;
}
Мой, переписывать с if в лень.
+1
else {
// на всякий случай возвращаем true в случае некоторых экзотических браузеров
flashinstalled = true;
}
return flashinstalled;
https://csdrop.org/
main.js
Просто из за комментария ☺
+1
https://en.cppreference.com/w/cpp/language/lambda
> Explanation
> > <tparams>
> Like in a template declaration, the template parameter list may be followed by an optional requires-clause, which specifies the constraints on the template arguments.
> optional requires-clause
небязательные обязательные пункты.
Переводил почти час.
+1
Вы такого еще не видали
https://paste.ubuntu.com/p/gpsMVPnd6T/
Отформатировано: https://paste.ubuntu.com/p/vF8hCGN6Z3/
20 уровней индентации, адовый копипаст.
+1
foreach ($result->getDataCollection() as $data) {
if (!$data->getStatus() === Status::PAID)
continue;
// ACTIONS
}
Зачем использовать !== если есть ===
P/s
Смотрим на if (
+1
Страйкер приде — почту почине!
Грустно без уведомлений из любимой соцсети.
+1
with conn:
cursor = conn.cursor()
cursor.execute('UPDATE users SET creferals = creferals + 1 WHERE cid = ?', (inviter,))
cursor.execute('INSERT INTO users VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(datetime.strftime(datetime.now(),"%H:%M:%S %d.%m.%Y"), cid, username, 'main', 0, 0, 0, 0, 0, 0, 0, inviter, 'RUS'))
conn.commit()
+1
!DOCTYPE html>
<html>
<%c++
auto para=@@.get<std::map<std::string,std::string>>("parameters");
%>
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<%view header %>
<%c++ if(para.size()>0){%>
<H1>Parameters</H1>
<table border="1">
<tr>
<th>name</th>
<th>value</th>
</tr>
<%c++ for(auto iter:para){%>
<tr>
<td>{%iter.first%}</td>
<td><%c++ $$<<iter.second;%></td>
</tr>
<%c++}%>
</table>
<%c++ }else{%>
<H1>no parameter</H1>
<%c++}%>
</body>
C++ шаблонизатор
https://github.com/an-tao/drogon/blob/master/examples/simple_example/ListParaView.csp