- 1
- 2
- 3
if (request.getDate() != null && request.getDate().after(new Date())) {
throw new ApiException(HttpStatus.SC_BAD_REQUEST, "Great Scott! Time machine not invented yet");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+119
if (request.getDate() != null && request.getDate().after(new Date())) {
throw new ApiException(HttpStatus.SC_BAD_REQUEST, "Great Scott! Time machine not invented yet");
}
+146
class User {
protected $login;
protected $password;
protected $email;
public function __construct($login, $password, $email) {
$this->login = $login;
$this->password = $password;
$this->email = $email;
}
public function __get($name) {
$reflector = new ReflectionClass($this);
return $reflector->hasProperty($name) ? $this->{$name} : null;
}
}
+152
function getTestDataById ($testid) {
$query="select * from mdl_test where id=".$testid."";
$result = mysql_query($query) or die('getTestDataById query failed: ' . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$courseid=$row['courseid'] ;
$moduleid=$row['moduleid'];
$name=$row['name'];
$maxscore=$row['maxscore'];
$successscore=$row['successscore'];
$attempts=$row['attempts'];
$dur=$row['dur'];
$showsuccessmessage=$row['showsuccessmessage'];
$successmessage=$row['successmessage'];
$showfailedmessage=$row['showfailedmessage'];
$failedmessage=$row['failedmessage'];
$showtestsuccessmessage=$row['showtestsuccessmessage'];
$testsuccessmessage=$row['testsuccessmessage'];
$showtestfailedmessage=$row['showtestfailedmessage'];
$testfailedmessage=$row['testfailedmessage'];
$freequestions=$row['freequestions'];
$questionsorder=$row['questionsorder'];
$defertest=$row['defertest'];
$totalperpage=$row['totalperpage'];
$showcorrectreply=$row['showcorrectreply'];
$showscore=$row['showscore'];
$limittype = $row['limittype'];
$annotation = $row['annotation'];
} // end while
$res=array('courseid'=>$courseid,
'moduleid'=>$moduleid,
'name'=>stripslashes($name),
'maxscore'=>$maxscore,
'successscore'=>$successscore,
'attempts'=>$attempts,
'dur'=>$dur,
'showsuccessmessage'=>$showsuccessmessage,
'successmessage'=>stripslashes($successmessage),
'showfailedmessage'=>$showfailedmessage,
'failedmessage'=>stripslashes($failedmessage),
'showtestsuccessmessage'=>stripslashes($showtestsuccessmessage),
'testsuccessmessage'=>stripslashes($testsuccessmessage),
'showtestfailedmessage'=>stripslashes($showtestfailedmessage),
'testfailedmessage'=>stripslashes($testfailedmessage),
'freequestions'=>stripslashes($freequestions),
'questionsorder'=>stripslashes($questionsorder),
'defertest'=>stripslashes($defertest),
'totalperpage'=>stripslashes($totalperpage),
'showcorrectreply'=>stripslashes($showcorrectreply),
'showscore'=>stripslashes($showscore),
'limittype' => stripslashes($limittype), // Total 21 items
'annotation' => stripslashes($annotation));
return $res;
} // end of function
От начальника отдела))) Как вам?))
+75
public Double toDouble(String str){
if ((str==null)||(str.equals(""))) str = "0.0";
if ((str.contains(","))&&(!str.contains("."))) str = str.replace(",", ".");
return new Double(str);
}
Лишняя защита никогда не бывает лишней
+19
std::vector<int> data;
std::vector<int> indexes;
// ...
for (int i = 0; i < data.size(); ++i) {
if (data[i] == to_remove) {
indexes.push_back(i);
}
}
for (int i = 0; i < indexes.size(); ++i) {
data.erase(data.begin() + i);
}
"Эффективное" удаление элементов из вектора. Об <algorithm> человек не слышал...
+93
begin
if n=15 then
begin
a:=7200*56*99*12*13*14*15;
end
else
begin
if n=16 then
begin
a:=7200*56*99*12*13*14*15*16;
end
else
begin
if n=17 then
begin
a:=7200*56*99*12*13*14*15*16*17;
end
else
begin
if n=18 then
begin
a:=7200*56*99*12*13*14*15*16*17*18;
end
else
begin
if n=19 then
begin
a:=7200*56*99*12*13*14*15*16*17*18*19;
end
else
begin
if n=20 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19;
end
else
begin
if n=21 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21;
end
else
begin
if n=22 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22;
end
else
begin
if n=23 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23;
end
else
begin
if n=24 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24;
end
else
begin
if n=25 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25;
end
else
begin
if n=26 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26;
end
else
begin
if n=27 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27;
end
else
begin
if n=28 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27*28;
end
else
begin
if n=29 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27*28*29;
end
else
begin
if n=30 then
begin
a:=144000*56*99*12*13*14*15*16*17*18*19*21*22*23*24*25*26*27*28*29*30;
end
else
begin
if n=31 then
begin
+124
import Control.Monad
import Control.Arrow
import Data.List
solve' :: [String] -> [[String]]
solve' = nub . filter (
and . uncurry (
zipWith (
(.head) . (==) . last
)
) . (id &&& tail)
) . uncurry ($) . (
last . (((
map (
last . fst &&& uncurry (++) . (init . fst &&& snd)
) . tail . uncurry (zipWith (,)) . (inits &&& tails)
) >=> (uncurry map) .
((:) *** solve')
):
) . (uncurry takeWhile) . (
const . null &&& const [const [[]]]
) &&& id
)
main = print $ solve' ["123","321","123"]
+86
Function TMainForm.PrimGenerateMaze(Width, Height: Integer): Maze;
Type Point = record
x, y: Integer;
end;
Var
TehMaze: Maze;
Todo: array of Point;
todonum: integer;
x,y,n,d: integer;
Const
dx: array [0..3] of Integer = (0, 0, -1, 1);
dy: array [0..3] of Integer = (-1, 1, 0, 0);
BEGIN
SetLength(TehMaze, Width, Height);
SetLength(Todo, (Width * Height) - 1);
For x:=0 to Width-1 do
For y:=0 to Height-1 do
If (x = 0) or (x = Width-1) or (y = 0) or (y = Height-1) then
TehMaze[x][y]:=32
Else TehMaze[x][y]:=63;
Randomize;
x := Random(Width-2)+1;
y := Random(Height-2)+1;
todonum := 0;
TehMaze[x][y]:= TehMaze[x][y] and not 48; // Пометить клетку как принадлежащую лабиринту
// Пока не обработаны все клетки
Repeat
Begin
// Занести в список todo все ближайшие необработанные клетки
For d:=0 to 3 do
if (TehMaze[x + dx[d]][y + dy[d]] and 16) <> 0 then
Begin
todo[todonum].x := x + dx[d];
todo[todonum].y := y + dy[d];
Inc(todonum);
TehMaze[x + dx[d]][y + dy[d]] := TehMaze[x + dx[d]][y + dy[d]] and not 16;
End;
// Выбрать из списка todo произвольную клетку
n:= Random(todoNum);
x:= ToDo[n].x;
y:= ToDo[n].y;
// Удалить из списка обработанную клетку
Dec(todonum);
ToDo[n]:= todo[todonum];
// Выбрать направление, которое ведет к лабиринту
Repeat
d:=Random(4);
Until ((TehMaze[x + dx[d]][y + dy[d]] and 32) = 0);
// Присоединить выбранную клетку к лабиринту
TehMaze[x][y] := TehMaze[x][y] and not ((1 shl d) or 32);
TehMaze[x + dx[d]][y + dy[d]] := TehMaze[x + dx[d]][y + dy[d]] and not (1 shl (d xor 1));
End;
Until (todonum = 0);
TehMaze[1][1] := TehMaze[1][1] and -2; // начало лабиринта - в левом верхнем углу
TehMaze[Width-2][Height-2] := TehMaze[Width-2][Height-2] and not 2; // конец лабиринта - в правом нижнем углу
Result := TehMaze;
END;
Генерация лабиринтов по алгоритму Прима.
+161
<form action="..." ...>
...
<input type="button" ... onclick="$('form').submit();" />
</form>
Живет на свете один c# девелопер, который всегда всем говорит: "я не верстальщик - я c# девелопер. я не js программист - я c# девелопер" ну и т.д. И вот однажды он решил самостоятельно сделать функционал поиска...
(На самом деле на стороне сервера еще гуще развивались события...но это уже другая история...) с серверным c# кодом вы можете ознакомится тут http://govnokod.ru/user/5616/codes
+7
#include <iostream>
namespace detail
{
class CRWO;
class CRO;
class CWO;
class CO;
}
typedef detail::CRWO& CRWO;
typedef detail::CRO& CRO;
typedef detail::CWO& CWO;
typedef detail::CO& CO;
class C
{
friend class detail::CRWO;
friend class detail::CRO;
friend class detail::CWO;
friend class detail::CO;
public:
C( int a ) : value(a) {}
~C() {};
operator CRWO() { return *static_cast<detail::CRWO*>(static_cast<void*>(this)); }
operator CRO() { return *static_cast<detail::CRO*>(static_cast<void*>(this)); }
operator CWO() { return *static_cast<detail::CWO*>(static_cast<void*>(this)); }
operator CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
void set( int newValue ) { value = newValue; }
int get() { return value; }
private:
int value;
};
class detail::CRWO
{
public:
void set( int newValue ) { static_cast<C*>(static_cast<void*>(this))->set( newValue ); }
int get() { return static_cast<C*>(static_cast<void*>(this))->get( ); }
operator ::CRO() { return *static_cast<detail::CRO*>(static_cast<void*>(this)); }
operator ::CWO() { return *static_cast<detail::CWO*>(static_cast<void*>(this)); }
operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
CRWO(); CRWO(const CRWO&);~CRWO();CRWO& operator=(const CRWO&);void operator&(); void operator*();
};
class detail::CWO
{
public:
void set( int newValue ) { static_cast<C*>(static_cast<void*>(this))->set( newValue ); }
operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
CWO(); CWO(const CWO&);~CWO();CWO& operator=(const CWO&);void operator&(); void operator*();
};
class detail::CRO
{
public:
int get() { return static_cast<C*>(static_cast<void*>(this))->get( ); }
operator ::CO() { return *static_cast<detail::CO*>(static_cast<void*>(this)); }
private:
CRO(); CRO(const CRO&);~CRO();CRO& operator=(const CRO&);void operator&(); void operator*();
};
class detail::CO
{
public:
private:
CO(); CO(const CO&);~CO();CO& operator=(const CO&);void operator&(); void operator*();
};int main(int argc, char *argv[])
{
C c(3);
CRWO rwo = c;
CRO ro = c;
CWO wo = c;
CO o = c;
std::cout << rwo.get() << std::endl;
wo.set( 5);
std::cout << ro.get() << std::endl;
return 0;
}
Оттуда.
Автор требует указывать авторство при копировании.