- 1
- 2
- 3
- 4
- 5
if(!empty($_POST['action']) && !empty($_POST['product_id']))
{
$product_id=$_POST['product_id']+0;
etc...
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+154
if(!empty($_POST['action']) && !empty($_POST['product_id']))
{
$product_id=$_POST['product_id']+0;
etc...
}
Наткнулся вот!)
+12
class Thread
{
public:
Thread(const Thread&);
Thread() : handle(NULL), running(false), finished(false)
{
handle = (HANDLE)(_beginthreadex(NULL, 0, &(Thread::threadRun), this, CREATE_SUSPENDED, NULL));
}
~Thread()
{
if(isRunning()) {
TerminateThread(handle, 0);
}
CloseHandle(handle);
}
void start(void* arg)
{
if(isRunning() || isFinished()) {
throw Exception("Thread is running or finished!");
} else {
this->arg = arg;
ResumeThread(handle);
}
}
void pause()
{
if(isRunning()) {
SuspendThread(handle);
} else {
throw Exception("Thread is not running or finished!");
}
}
void resume()
{
if(!(isRunning())) {
throw Exception("Thread is finished!");
} else {
ResumeThread(handle);
}
}
void stop()
{
if(isRunning()) {
TerminateThread(handle, 0);
running = false;
finished = true;
throw Exception("Thread stopped!");
} else {
throw Exception("Thread is not running or finished!");
}
}
void setPriority(ThreadPriority priority)
{
if(isFinished()) {
throw Exception("Thread is finished!");
} else {
switch(priority) {
case ThreadPriorityLow:
SetThreadPriority(handle, THREAD_PRIORITY_LOWEST);
break;
case ThreadPriorityNormal:
SetThreadPriority(handle, THREAD_PRIORITY_NORMAL);
break;
case ThreadPriorityHigh:
SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
break;
default:
throw Exception("Invalid priority!");
break;
}
}
}
bool isRunning()
{
return (running);
}
bool isFinished()
{
return (finished);
}
protected:
virtual void run(void *arg) = 0;
private:
static unsigned int __stdcall threadRun(void *arg)
{
Thread *thread = static_cast<Thread*>(arg);
thread->running = true;
thread->run(thread->arg);
thread->running = false;
thread->finished = true;
_endthreadex(0);
return (0);
}
void *arg;
HANDLE handle;
bool running;
bool finished;
};
Из предыдущей оперы.
−116
СтрокаСуммаСРазделителями = Строка(ТекСсылка.СуммаДокумента);
СтрокаСуммаБезРазделителей = СтрЗаменить(СтрокаСуммаСРазделителями, СимволРазделительСуммы, "");
Видать, использование "Формат" запрещено внутренней политикой =(
+160
$("#pastas").on('change', function () {
var myString = $("#pastas").val();
var myArray = myString.split('');
// display the result in myDiv
for (var i = 0; i < myArray.length; i++) {
if (myArray[i] == "@") {
skai++;
} else if (myArray[i] == ".") {
skai++;
}
}
if (skai == 2) {
$('#pastas').removeClass('blogai');
console.log('gerai');
} else {
$('#pastas').addClass('blogai');
console.log('blogai');
}
});
Валидность почты по Литовски...
+152
var retriesLeft = 100;
while (true)
{
try
{
return SetRestorePoint(0, pointType, enentType, description);
}
catch (Win32Exception ex)
{
if (ex.NativeErrorCode != ErrorServiceDisabled || retriesLeft < 0)
throw;
Thread.Sleep(500);
retriesLeft--;
}
}
+128
wr = new StreamWriter(fs);
wr.WriteLine(string.Format("{0}", toPrint));
+136
http://odnoklassniki.ru/dk
?cmd=PopLayer
&tkn=9739
&st.cmd=error
&st.stid=anonymPasswordRecovery
&st.eclass=java.lang.IllegalStateException
&st.layer.cmd=PopLayerSystemError
Парсер тоже видит ЭТО и предлагает положить в не «Кучу», а в «Java».
+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 и сделал двумерный императивный цыкл.
−167
SELECT
slave.*,
-- ...
FROM
(SELECT * FROM driver WHERE id = '$driverID') as slave
LEFT JOIN
-- ...
Отыскал в работающем проекте
+54
<?php
class ArrObj implements ArrayAccess, Countable, Iterator
{
protected $_data = array();
protected $_indexes = array();
protected $_pos = 0;
public function __construct($data = array())
{
$this->_data = $data;
}
public function offsetGet($name)
{
if($isset = isset($this->_data[$name])) return $this->_data[$name];
$this->_data[$name] = new self();
return $isset ? $this->_data[$name] : null;
}
public function offsetSet($name, $value)
{
if(is_array($value)) $value = new self($value);
$this->_data[$name] = $value;
$this->_indexes[] = $name;
return $value;
}
public function offsetUnset($name)
{
unset($this->_data[$name]);
$this->_indexes = array_merge(array_diff($this->_indexes, array($name)));
}
public function offsetExists($name)
{
return isset($this->_data[$name]);
}
public function count()
{
return count($this->_data);
}
public function rewind()
{
$this->_pos = 0;
}
public function current()
{
return $this->_data[$this->_indexes[$this->_pos]];
}
public function key()
{
return $this->_indexes[$this->_pos];
}
public function next()
{
++$this->_pos;
}
public function valid()
{
return isset($this->_indexes[$this->_pos]);
}
}
?>