- 1
- 2
- 3
- 4
- 5
- 6
- 7
~Guard(){
if(std::uncaught_exception())
try{
}catch(...){
error_output<<"prevented exception!!!"<<endl;
};
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+17
~Guard(){
if(std::uncaught_exception())
try{
}catch(...){
error_output<<"prevented exception!!!"<<endl;
};
}
−107
import System.Exit
import Graphics.UI.GLUT
import Control.Monad
import Control.Applicative
import Control.Arrow
import Control.Concurrent
import Graphics.Rendering.OpenGL
import Data.IORef
import Data.List
import Data.Maybe
initial = ((0,0),(0.005,-0.03),(0,0),([(-0.4,-0.9),(-0.4,-0.85),(0.4,-0.85),(0.4,-0.9),(-0.4,-0.9)],(0,0)),liftM2 (,) [-0.9,-0.7..0.9] [0.5,0.7,0.9])
ws = dzip [(-1,-1),(-1,1),(1,1),(1,-1)] ; r = 0.1 :: GLfloat
main = initialWindowSize $= Size 777 777 >> initialWindowPosition $= Position 100 100 >> initialDisplayMode $= [DoubleBuffered] >> createWindow "ursula" >>
newIORef initial >>= \ior -> keyboardMouseCallback $= Just (kbd ior) >> displayCallback $= dlay ior >> idleCallback $= Just (anime ior) >> mainLoop
dlay ior = clearColor $= Color4 1 1 1 1 >> clear [ColorBuffer] >> readIORef ior >>= drawDoxyq >> swapBuffers
kbd _ (Char 'q') Down _ _ = exitWith ExitSuccess
kbd s (Char x) Down _ _ = modifyIORef' s $ \(a,b,t,(d,e),cs) -> (a,b,t,(d,(if x == '[' then -0.05 else if x == ']' then 0.05 else fst e,0)),cs)
kbd _ _ _ _ _ = return ()
draw c = renderPrimitive c . mapM_ (vertex . uncurry Vertex2)
touch xy s xy' = guard ((xy ==== xy') <= r+r && (s .*. (xy.-.xy')) <= 0) >> Just (xy.-.xy')
drawDoxyq ((x,y),_,(t,_),(bd,_),cs) = currentColor $= Color4 0.3 0.4 0.8 0 >> mapM_ (mapM_ (draw LineLoop) . sta) cs >>
currentColor $= Color4 0.7 0.1 0.2 1 >> mapM_ (draw LineStrip) swa >> currentColor $= Color4 0 0 0 1 >> draw Polygon bd where
swa = [[(x,y),(x + r/1.8*cos (th+pi/4),y + r/1.8*sin (th+pi/4)),(x + r/1.2*cos th,y + r/1.2*sin th)] | th <- [t,t+pi/2..t+1.6*pi]]
sta (x,y) = [[(x,y+r/2),(x-r/2,y-r/2),(x+r/2,y-r/2)],[(x+r/2,y+r/2-0.03),(x-r/2,y+r/2-0.03),(x,y-r/2-0.03)]]
frame (xy,v,(tt,tr),(b,s),cs) = if snd xy <= r-0.99 || null cs then error "GAME OVER" else (xy.+.v',v',(tt+tr',tr'),(b',s'),cs') where
v' = listy v (\us -> rV (2*negv v .>. foldl1' (.+.) us + tr/11) $ negv v) $ mapMaybe (cutSect xy v) (ws ++ dzip b') ++ mapMaybe (touch xy v) cs
s' = 0.93 *. if any ((1<=) . (*signum (fst s)) . fst) b then negv s else s
b' = map (.+.s') b ; cs' = filter (isNothing . touch xy v) cs
tr' = if v .=. v' then tr else (v' .>. v)/19
listy d f x = if null x then d else f x
rV t (x,y) = (x*cos t - y*sin t,y*cos t + x*sin t)
anime ior = modifyIORef' ior frame >> threadDelay 30000 >> postRedisplay Nothing
cutSect xy s c@(u,v) = guard (xy ./ l <= r && w `oncut` c && (s .*. (xy.-.w)) <= 0) >> Just (xy.-.w) where
l = ln u (u.-.v) ; w = xy .-| l
oncut u (v,w) = 0 <= (u.-.v) .*. (w.-.u) && 0 <= (u.-.w) .*. (u.-.w) && ((u.-.w) .<>. (v.-.w)) # 0
ln xy w = (snd w,-fst w,w.<>.xy)
(x,y) .-| (a,b,c) = ((b^2*x - a*c - a*b*y)/(a^2 + b^2),-(b*c + a*b*x - a^2*y)/(a^2 + b^2))
p ./ ln = p ==== p .-| ln ; pop f (a,b) (c,d) = (f a c,f b d)
(.+.) = pop (+) ; (.-.) = pop (-) ; (.=.) = (uncurry (&&) .) . pop (#)
(*.) = tmap . (*) ; (.*.) = (uncurry (+) .) . pop (*)
(.<>.) = (uncurry (-) .) . (. uncurry (flip (,))) . pop (*) ; v .>. u = atan2 (v .<>. u) (v .*. u)
norm = sqrt . join (.*.) ; a ==== b = norm $ a.-.b ; negv = tmap negate
infix 4 #,*. ; infix 3 .+.,==== ; infix 8 .>.
x # y = abs (x-y) < 0.00001 ; tmap = join (***)
dzipWith = (<*> drop 1) . zipWith ; dzip = dzipWith (,)
Вся суть выразительности Haskell
+158
function commerce_auction_dividable($big, $small) {
$div = $big / $small;
if (!is_numeric(strpos($div, '.')) === TRUE) {
return TRUE;
}
return FALSE;
}
https://drupal.org/node/1721568
+70
qDebug() << QString("%1-%2").arg("%1").arg("foo");
+81
program matr;
uses
crt;
var
mas:array [1..100] of integer;
i,n,imin,imax,min,max,razn:integer;
begin
clrscr;
imax:=1;
imin:=1;
randomize;
write('Введите количество элементов: ');
readln(n);
for i:=1 to n do
begin
mas[i]:=random(10)-5;
write(mas[i]:4);
if mas[i]>mas[imax] then
begin
imax:=i;
end
else
if (mas[i]<mas[imin]) then
begin
imin:=i;
end;
end;
writeln;
writeln('MAX[',imax,']:=',mas[imax]);
writeln('MIN[',imin,']:=',mas[imin]);
razn:=mas[imax]+mas[imin];
writeln('Сумма MAX и MIN:=',razn);
end.
Написано by "ТАМБОВСКИЙ ВОЛК. Профессионал".
Знатное говнецо нынче пишут "профессионалы".
http://www.programmersforum.ru/showthread.php?t=98747
+100
<?php
$a=0;
$b=null;
echo $a==$b?1:0; //1
Разрабы пхп троллят.
+70
public class ImportException extends Exception {
public static final int NOT_CRITICAL = 1;
public static final int CRITICAL = 2;
private int criticality = NOT_CRITICAL;
public ImportException(String message) {
this.message = message;
}
/**
* С критичностью
* @param message
* @param criticality
*/
public ImportException(String message, int criticality) {
this.message = message;
this.criticality = criticality;
}
public int getCriticality() {
return criticality;
}
public void setCriticality(int criticality) {
this.criticality = criticality;
}
}
изобретение типа bool
+21
template <int N>
void Ololo ()
{
var
i : integer;
begin
for i := 0 to N-1 do begin
WriteLn(i, ' ');
end;
end;
}
int main ()
{
return 0;
}
Compiling...
Test.cpp
Linking...
Build log was saved at "file://c:\Users\TarasB\Documents\Visual Studio Projects\Test\Debug\BuildLog.htm"
Test - 0 error(s), 0 warning(s)
---------------------- Done ----------------------
Build: 1 succeeded, 0 failed, 0 skipped
MSVS2003
+83
// java.io.FilterOutputStream
public void close() throws IOException {
try {
flush();
} catch (IOException ignored) {
}
out.close();
}
// тестовый код
try (OutputStream os = new BufferedOutputStream(new FileOutputStream("/tmp/little_virtual_fs/1.txt"))) {
byte[] buf = new byte[2028544];
os.write(buf, 0, 2028544); // максимальный размер файла, который влезает на нашу фс
os.write(buf, 0, 5); // и еще немножко
//os.flush();
}
А сейчас, на арене нашего цирка - очередная жабопроблема!
Как думаете, каков результат выполнения тестовой программы?
Запишет 2028549 байт? Хрен там, места маловато.
Выдаст IOException на write()? Хрен там, буферизация.
Выдаст IOException на close()? Хрен там, его сожрала реализация FilterOutputStream.
Результат: файл не дописался, исключения нет.
Решение: всегда дергать flush() перед close() самому или не юзать буферизованный поток.
+166
if (substr(json_encode($row['list']), 0, 1) == '[') {
Такой вот аналог is_array()