- 1
- 2
- 3
- 4
- 5
#!/bin/bash
cmd='SHELL="/bin/tcsh -e ~/bin/start_emulator";'
sshcmd="/bin/bash -c '$cmd /proj/bin/set_proj_clearcase_view $view'"
host=`~/bin/find_free_host`
ssh $host -t $sshcmd
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 91
−47
#!/bin/bash
cmd='SHELL="/bin/tcsh -e ~/bin/start_emulator";'
sshcmd="/bin/bash -c '$cmd /proj/bin/set_proj_clearcase_view $view'"
host=`~/bin/find_free_host`
ssh $host -t $sshcmd
хотите страшную историю на ночь?
ClearCase
+2
%%% O(n log n)
nub([]) -> [];
nub([H|T]) ->
case lists:member(H, T) of
true ->
nub(T);
false ->
[H|nub(T)]
end.
кто-то услышал про логлинейный nub, и решил, что у него тоже получится
+2
#include <memory>
#include <list>
struct ListNode;
using List = std::unique_ptr<const ListNode>;
struct ListNode {
const int data;
const List next;
~ListNode()
{
if(!next)
return;
else {
std::list<ListNode*> nodes;
for(auto pn = next.get(); pn->next; pn = pn->next.get()) {
nodes.push_back(const_cast<ListNode*>(pn));
}
for(decltype(nodes)::reverse_iterator in = nodes.rbegin(); in != nodes.rend(); ++in) {
const_cast<List&>((*in)->next).reset();
}
}
}
};
List Cons(int head, List tail)
{
return List(new ListNode{head, std::move(tail)});
}
List Nil()
{
return List();
}
size_t len(const List & self)
{
if (!self) {
return 0;
}
return 1 + len(self->next);
}
#include <iostream>
void test(size_t n)
{
auto p = Nil();
for (size_t i = 0; i < n; ++i) {
auto x = std::move(p);
p = Cons(1, std::move(x));
}
std::cout << "done: " << std::endl;
}
int main()
{
test(131028);
}
односвязный список против джависта
источник: https://www.linux.org.ru/forum/development/11752940?cid=11755489
−72
'(haskell-ask-also-kill-buffers nil)
'(haskell-interactive-popup-errors nil)
'(haskell-process-suggest-add-package nil)
'(haskell-process-suggest-language-pragmas nil)
'(haskell-process-suggest-no-warn-orphans nil)
'(haskell-process-suggest-overloaded-strings nil)
не говнокод, но говнофичи
дёрнуло меня обновить haskell-mode
я вас скажу, это просто ад и Израль, глад и мор, и семь казней египетских
−11
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances, FlexibleContexts, MultiParamTypeClasses, OverlappingInstances #-}
class Filtering c a b where
(/-) :: c -> [a] -> [b]
class Containing a b | a -> b where
getter :: a -> [b]
instance (Containing a b, Containing b c) => Containing a c where
getter l = getter l >>= getter
instance Filtering (a -> Bool) a a where
p /- l = filter p l
instance (Filtering (a -> Bool) a a, Containing b a) => Filtering (a -> Bool) b b where
p /- l = filter (not . null . filter p . getter) l
instance (Filtering (c -> Bool) b b, Containing a b) => Filtering (c -> Bool) a b where
p /- l = p /- (l >>= getter)
data A = A { _ap :: Bool, _ab :: [B] } deriving (Show)
instance Containing A B where
getter = _ab
data B = B { _bp :: Bool, _bc :: [C] } deriving (Show)
instance Containing B C where
getter = _bc
data C = C { _cp :: Bool } deriving (Show)
test = [ A True [B True [C False]]
, A False [B True [C True, C False]]
]
main = do print ((_cp /- test) :: [B])
print ((_bp /- test) :: [A])
print ((_cp /- test) :: [C])
вы мечтали об операторах, жрущих любой тип a la PHP, в своём любимом статическом языке?
всего пара расширений GHC, и они уже в вашем проекте!
−52
erl -run moduleful_of_elaborate_business_logic validate_data -noshell > erl.log
if grep -E '(CRASH REPORT|ERROR REPORT|Error|Crash)' erl.log
then
echo "Validation failed"
exit 1
fi
Найдено в продакшне.
+165
ID3DBlob* pErrorBlob;
hr = D3DX11CompileFromFile( szFileName, NULL, NULL, szEntryPoint, szShaderModel,
dwShaderFlags, 0, NULL, ppBlobOut, &pErrorBlob, NULL );
if( FAILED(hr) )
{
if( pErrorBlob != NULL )
OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
if( pErrorBlob ) pErrorBlob->Release();
return hr;
}
if( pErrorBlob ) pErrorBlob->Release();
Текст примера из MS DXSDK. Проверка - а вдруг pErrorBlob самоуничтожается после прочтения?
+157
struct Event
{
int priority;
bool operator<(Event e) const
{
return e.priority>priority;
}
virtual void operator() () = 0;
};
priority_queue<Event*, deque<Event*> > eventQueue;
template <typename T, void (T::*g)()>
struct TEvent : Event
{
T* parent;
virtual void operator() ()
{
(parent->*g)();
}
TEvent (T* _parent) : parent(_parent){}
};
struct Entity
{
int foo;
void AFunc()
{
cout<<foo;
}
void BFunc()
{
cout<<"Ololo";
}
typedef TEvent<Entity,&Entity::AFunc> someEvent;
Entity(int _foo): foo(_foo){}
void addEvent()
{
eventQueue.push(new someEvent(this));
}
};
int main()
{
Entity foo(10);
foo.addEvent();
(*eventQueue.top())();
return 0;
}
Один из самых сложных и неочевидных способов вывести в консоль число 10.
(Этот код - проверка, будет ли работать прототип велосипедного делегата)
+93
for i:=1 to 100 do
begin
for j:=1 to f do
begin
...
end;
f:=f+1000;
end;
Бедные дельфины, им не повезло с циклами.
+159
try
{
for(..)
{
for(..)
{
if(...)
throw;//генерация исключения
}
}
}
catch(..)
{
}
Кому-то религия не позволяет юзать goto. Сорри, если было.