- 1
- 2
СтрокаСуммаСРазделителями = Строка(ТекСсылка.СуммаДокумента);
СтрокаСуммаБезРазделителей = СтрЗаменить(СтрокаСуммаСРазделителями, СимволРазделительСуммы, "");
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−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]);
}
}
?>
+42
function test($method)
{
$picfile = 'pic1.png';
$bgfile = 'output.png';
$background = 'pic2.png';
$foreground = 'pic3.png';
if ($method == 'Imagick') {
$img = new Imagick($picfile);
$mask = new Imagick($background);
$img->compositeImage($mask, imagick::COMPOSITE_COPYOPACITY, 0, 0);
$mask->destroy();
$overlay = new Imagick($foreground);
$img->compositeImage($overlay, imagick::COMPOSITE_OVER, 0, 0);
$overlay->destroy();
$img->setImageFormat('png');
file_put_contents($bgfile, $img->getImageBlob()); // $img->writeImage($bgfile) работает медленнее
$img->destroy();
} else if ($method == 'Wand') {
$img = NewMagickWand();
MagickReadImage($img, $picfile);
$mask = NewMagickWand();
MagickReadImage($mask, $background);
MagickCompositeImage($img, $mask, MW_CopyOpacityCompositeOp, 0, 0);
DestroyMagickWand($mask);
$overlay = NewMagickWand();
MagickReadImage($overlay, $foreground);
MagickCompositeImage($img, $overlay, MW_OverlayCompositeOp , 0, 0);
DestroyMagickWand($overlay);
MagickSetImageFormat($img, 'png');
file_put_contents($bgfile, MagickGetImagesBlob($img)); // ditto
DestroyMagickWand($img);
} else {
$cmdline = 'convert -compose copy-opacity ' . $picfile . ' ' . $background . ' -composite';
$cmdline .= ' -compose src-over ' . $foreground . ' -composite ' . $bgfile;
exec($cmdline);
}
}
$methods = array('Imagick', 'Wand', 'Command line');
foreach ($methods as $m) {
$start_time = microtime(true);
for ($i = 0; $i < 4; $i++) {
test($m);
}
$elapsed_time = microtime(true) - $start_time;
echo 'Method: ' . $m . '; elapsed ' . strval($elapsed_time) . PHP_EOL;
}
Результаты выполнения на локальной машине:
Method: Imagick; elapsed 0.45...
Method: Wand; elapsed 0.82...
Method: Command line; elapsed 0.87...
Результаты выполнения на VPS:
Method: Imagick; elapsed 79.64...
Method: Wand; elapsed 151.64...
Method: Command line; elapsed 46.49...
Что-то тут не так...
+155
function moveAll(objectFrom, objectTo)
{
var list_len = objectFrom.length;
if (list_len > 0)
{
// i is 0 all the time in the loop
for (i=0; objectFrom.length>0;)
{
var new_option = new Option (objectFrom[i].text, objectFrom[i].value);
objectTo[objectTo.length] = new_option;
objectFrom[i] = null;
}
}
}
Литералы — для лузеров (я имею в виду objectForm[0])!