-
Лучший говнокод
- В номинации:
-
- За время:
-
-
+160
- 1
- 2
- 3
{if $smarty.foreach.categories.iteration == 2 || $smarty.foreach.categories.iteration == 4 || $smarty.foreach.categories.iteration == 6 || $smarty.foreach.categories.iteration == 8 || $smarty.foreach.categories.iteration == 10 || $smarty.foreach.categories.iteration == 12 || $smarty.foreach.categories.iteration == 14 || $smarty.foreach.categories.iteration == 16}
<div class="clear"></div>
{/if}
Smarty
uadeveloper,
26 Декабря 2013
-
+10
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
#include <iostream>
#include <list>
#include <queue>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <type_traits>
#include <assert.h>
using namespace std;
template<class Data>
class UnboundedQueueForNonThrowMovable
{
static_assert(std::is_nothrow_move_constructible<Data>::value, "Data must be nonthrow movable type.");
static_assert(!std::is_array<Data>::value, "Data must not be c-array.");
public:
typedef Data value_type;
private:
typedef std::queue<Data, std::list<Data>> Queue;
typedef std::unique_lock<std::mutex> Lock;
Queue _queue;
std::mutex _lockQueue;
std::condition_variable _pushToQueue;
UnboundedQueueForNonThrowMovable(const UnboundedQueueForNonThrowMovable&) = delete;
UnboundedQueueForNonThrowMovable(UnboundedQueueForNonThrowMovable&&) = delete;
UnboundedQueueForNonThrowMovable& operator=(const UnboundedQueueForNonThrowMovable&) = delete;
UnboundedQueueForNonThrowMovable& operator=(UnboundedQueueForNonThrowMovable&&) = delete;
public:
UnboundedQueueForNonThrowMovable(void){}
void push(Data&& data)
{
Lock lockerQueue(this->_lockQueue);
this->_queue.push(std::move(data));
this->_pushToQueue.notify_all();//_condition.notify_one(); most optimal, but can cause deadlock.
}
void push(Data& data)
{
this->push(std::move(data));
}
bool emptyUnstable(void) const
{
Lock lockerQueue(this->_lockQueue);
return this->_queue.empty();
}
Data pop(void)
{
Lock lockerQueue(this->_lockQueue);
this->_pushToQueue.wait(lockerQueue, [this](void){return !this->_queue.empty();});
assert(!this->_queue.empty());
Data result = std::move(this->_queue.front());
this->_queue.pop();
return result;
}
template< class Rep, class Period>
Data pop(const std::chrono::duration<Rep, Period> WaitDuration)
{
Lock lockerQueue(this->_lockQueue);
if(!this->_pushToQueue.wait(lockerQueue, WaitDuration, [this](void){return !this->_queue.empty();}))
return Data();
assert(!this->_queue.empty());
Data result = std::move(this->_queue.front());
this->_queue.pop();
return result;
}
};
template<class Data>
using UnboundedQueueForUniquePtr = UnboundedQueueForNonThrowMovable<std::unique_ptr<Data>>;
template<class Data>
using UnboundedQueueForSharedPtr = UnboundedQueueForNonThrowMovable<std::shared_ptr<const Data>>;
template<class Data>
using UnboundedQueue = UnboundedQueueForUniquePtr<Data>;
int main() {
cout<<"ok"<<endl;
{
//UnboundedQueueForSharedPtr<int>::value_type == std::shared_ptr<const int>
UnboundedQueueForSharedPtr<int> queueSharedPtr;
//auto a = std::make_shared<const int>(45);
auto a = std::make_shared<int>(45);
assert(a);
queueSharedPtr.push(a);
assert(!a);//Fired if you use "auto a = std::make_shared<int>(45)" below. It is compiler bug, I think, because previus code line must cause compile error.
auto b = queueSharedPtr.pop();//std::shared_ptr<const int>
assert(b);
cout<<*b<<endl;
assert(*b==45);
http://ideone.com/qdsWJi
Немного глупый вопрос, почему в 90 строчке не получаем ошибку компиляции если закомментировать 87-ую строку и разкомментировать 88-ую?
laMer007,
16 Декабря 2013
-
+161
- 1
- 2
- 3
- 4
- 5
- 6
- 7
//надо показать элемент каталога во всей красе
$_CENTER="show_category_item(".$newParts[0].");";
eval($_CENTER);
// ...
$_LEFT='get_main_category($cat_id, $new_path);';
$_CENTER="show_category_item_list($".'newParts'.");";
Вот с таким адом мне приходится работать.
oooZinka,
16 Декабря 2013
-
+136
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
countDigits :: (Integral a) => a -> Int
{-# INLINE countDigits #-}
countDigits v0 = go 1 (fromIntegral v0 :: Word64)
where go !k v
| v < 10 = k
| v < 100 = k + 1
| v < 1000 = k + 2
| v < 1000000000000 =
k + if v < 100000000
then if v < 1000000
then if v < 10000
then 3
else 4 + fin v 100000
else 6 + fin v 10000000
else if v < 10000000000
then 8 + fin v 1000000000
else 10 + fin v 100000000000
| otherwise = go (k + 12) (v `quot` 1000000000000)
fin v n = if v >= n then 1 else 0
Хаскельная магия из исходников Data.Text.
Yuuri,
12 Декабря 2013
-
+14
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
Node<maxCnt> n[sizeY][sizeX], on;
//...
auto EachConvex = [](auto f, Body& b)
{
for (auto g : b.g)
{
auto cp = Body::ConvexPtr(&b, g);
auto bounds = cp.bounds();
auto max = Rect(0, 0, sizeX - 1, sizeY - 1);
auto out = max.intersect(bounds);
auto b = max & bounds;
for (auto x = b.left; x < b.right; ++i)
for (auto y = b.top; x < b.bottom; ++i)
f(n[y][x], cp);
if (out)
f(on, cp);
}
return true;
}
LispGovno,
03 Декабря 2013
-
+168
- 1
- 2
- 3
- 4
- 5
- 6
function FileExists($file) {
if(file_exists($file))
return true;
else
return false;
}
Гениальная функция, используемая в одном из расширений Джумлы.
undeletable,
18 Октября 2013
-
+141
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
public class SimpleTest {
class A {}
class B extends A {};
class C extends B {};
public void doIt() {
A a = new A();
B b = new B();
C c = new C();
List<B> lst = new ArrayList<B>();
lst.add(a);
lst.add(b);
lst.add(c);
a = lst.get(0);
b = lst.get(0);
c = lst.get(0);
List<? extends B> lstExtends = lst;
lstExtends.add(a);
lstExtends.add(b);
lstExtends.add(c);
a = lstExtends.get(0);
b = lstExtends.get(0);
c = lstExtends.get(0);
List<? super B> lstSuper = lst;
lstSuper.add(a);
lstSuper.add(b);
lstSuper.add(c);
a = lstSuper.get(0);
b = lstSuper.get(0);
c = lstSuper.get(0);
}
}
Какие строки вызовут ошибку компиляции?
huitka,
16 Октября 2013
-
+70
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
// there is class PlayerExt, which extends class Player...
// min >= 0
// max <= players.size()
List<PlayerExt> players = playerManager.getPlayers(contestId);
Player[] response = new Player[players.size()];
for (int i = min; i < max; i++) {
response[i] = players.get(i);
if (!players.get(i).isQualified()) {
response[i].setChipStack(BigDecimal.valueOf(-1));
}
response[i].setPosition(i + 1);
response[i].setCustomerId(players.get(i).getCustomerId());
}
Для таких начальных условий, как обозначено в комментарии в начале кода, формируем список игроков.
Особенно вдохновляет самая последняя инструкция в теле цикла.
wissenstein,
09 Октября 2013
-
+8
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
const Registry & Registry::getInstance()
{
Registry *instance = RegistrySingleton::instance();
if (!instance->mRootNode) {
instance->load();
}
return *instance;
}
void Registry::load()
{
try {
// ...
if (!mReader) {
mReader = XMLReaderFactory::createXMLReader();
}
// ...
mReader->parse( ... );
} catch (...) {
// ...
throw; // удачи всем пользователям обрабатывать исключения xerces...
}
}
боян синглтонно-абстрактный для чтения xml конфигурации с помощью xerces.
и не только ошибки не обрабатаешь (потому что getInstance() их бросает, угадай какой именно вызов из сотен загружает конфигурацию), но и в добавок народ не впечатал как многопоточность сделать правильно (RegistrySingleton это специализация шаблона который синхронизирует инициализацию mInstance переменной, и только).
Dummy00001,
07 Октября 2013
-
+159
- 1
try{while(confirm("The result is "+(1/prompt("a*x=b\n\nEnter a").split().join()*prompt("a*x=b\n\nEnter b").split().join())+"\n\nOnce again?"));}catch(e){}
Qwertiy,
31 Августа 2013