- 1
- 2
- 3
- 4
- 5
private int GenerateRandom(int MaxValue)
{
var mas = Guid.NewGuid().ToByteArray();
return BitConverter.ToInt32(mas, 4) % MaxValue;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+113
private int GenerateRandom(int MaxValue)
{
var mas = Guid.NewGuid().ToByteArray();
return BitConverter.ToInt32(mas, 4) % MaxValue;
}
....
+41
public static function getById( $id )
{
$model = new self;
$data = $model->load();
foreach( $data AS $item ){
if( $item->id == $id ){
return $item;
}
}
return null;
}
Нашел в текущем проекте.
+142
if ($options->get('registrationSetup', 'requireDob')) {
// dob required
Без ДОБ-а не пущу.
+22
list<int> list;
...
for(auto i=0;i<list.size();i++){
auto item = *next(list.begin(), i);
Вчера у меня появился каллега.
http://liveworkspace.org/code/1AWg24$5
Кажется я знаю, кто следующий будет сидеть на табуретке. Думаете стоит сказать ему?
+130
import std.stdio;
class Parent{ }
class Another{ }
class Child: Parent
{
Another data;
alias data this;
this()
{
data = new Another;
}
}
void test(Parent t){writeln("Parent: ", t);}
void test(Another t){writeln("Another: ", t);}
void main() {
auto Me = new Child();
test(Me);
}
Интуитивного свежачка вам.
http://ideone.com/qEDzz
http://ideone.com/9mB8S
+18
template <typename Derived>
class Base {
public:
void doSmth() {
// ...
static_cast<Derived*>(this)->OnParseAndHandle();
//...
}
};
class MyClass: public Base<MyClass> {
public:
void OnParseAndHandle() {
// ...
}
};
Если Вы не верите в виртуальные методы, то шаблоны Вам в помощь.
А может я идиот и чего-то не понял?
+32
// *.h
class MyClass {
public:
MyClass ();
~MyClass ();
// ..etc
};
// *.cpp
#include "*.h"
MyClass *mycl;
MyClass::MyClass ()
{
mycl=this; // эту строчку не удалять без нее не работает, точнее не всегда работает иногда сбоит
}
MyClass::~MyClass ()
{
}
Простите меня пожалуйста. Я уныл чуть мене чем полностью, но почему человек которые это написал хороший программист. Это писал не я. Извините пожалуйста за беспокойство :( ..
+81
var
sMem: String;
.......
case Byte(sMem[len]) of
Word('k'): { Что то делаем };
Word('m'): { Что то делаем };
Word('g'): { Что то делаем };
end;
Вот такой вот гавнокод
+54
public function accuire($array = array()) {
return $this->acquire($array);
}
public function acquire($array = array()) {
Spell-master
+124
buildTree sentence graph =
(M.lookup (0, length sentence - 1, DirLeft) finalGraph, finalGraph)
where finalGraph = execState runEisner (M.fromList elementaryPathes)
elementaryPathes =
map (\(i, word) -> ((i, i, DirLeft), elementaryPath DirLeft word)) indexed ++
map (\(i, word) -> ((i, i, DirRight), elementaryPath DirRight word)) indexed
indexed = zip [0..] sentence
runEisner = do
let len = length sentence
forM_ [1 .. len - 1] $ \l -> do
forM [0 .. len - 1 - l] $ \i -> do
matrix <- get
let j = i + l
let w1 = sentence !! i
let w2 = sentence !! j
let buildConcat dir = (catMaybes $ (zipWith (\p1 p2 -> join $ (liftM2 concatenatePath) p1 p2)
[M.lookup (i, k, dir) matrix | k <- [i + 1 .. j - 1]]
[M.lookup (k, j, dir) matrix | k <- [i + 1 .. j - 1]])) :: [Path]
let buildJoin dir key = fromMaybe [] $ M.lookup key graph >>= \link ->
return (catMaybes (zipWith (\p1 p2 -> join $ (liftM2 (\f c -> joinPath f c link)) p1 p2)
[M.lookup (i, k, dir) matrix | k <- [i .. j - 1]]
[M.lookup (k, j, rev dir) matrix | k <- [i + 1 .. j]]))
let posR = (buildConcat DirRight ++ buildJoin DirRight (w1, w2)) :: [Path]
let newMatrix = if (not . null) posR
then M.insert (i, j, DirRight) (minimumBy compWeight posR) matrix
else matrix
let posL = buildConcat DirLeft ++ buildJoin DirRight (w2, w1)
let newMatrix' = if (not . null) posL
then M.insert (i, j, DirLeft) (minimumBy compWeight posL) matrix
else newMatrix
put newMatrix'
Кусок из диплома по NLP. Yuuri неделю как познал монаду State и сделал двумерный императивный цыкл.