- 1
typedef boost::shared_ptr<LPDIRECT3D9> Direct3dShared;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+10
typedef boost::shared_ptr<LPDIRECT3D9> Direct3dShared;
Те кто знают, что такое в гейдеве LPDIRECT3D9 и IDirect3D9 - поймут.
Думаю сегодня даже не нужно писать с какого это сайта.
+141
//у стены - нахождение клеток "у стены"
procedure useny(var vsten:bulArr);
var i,i2:integer;
function sh(x,y,n:integer):boolean; // n-номер сдвига n=[2..5]
begin
if vsten[x+sdx[n],y+sdy[n]] then sh:=true
else
if sten[x+sdx[n],y+sdy[n]] then sh:=false
else
if sten[i2+sdx[n-1],i+sdy[n-1]]or sten[i2+sdx[n+1],i+sdy[n+1]]
then sh:=sh(x+sdx[n],y+sdy[n],n)
else sh:=false;
if result then vsten[x,y]:=true;
end;
begin
for i:=0 to ny do
for i2:=0 to nx do
if not(sten[i2,i]) then
if (sten[i2+1,i] or sten[i2-1,i])and(sten[i2,i+1] or sten[i2,i-1]) then
begin
vsten[i2,i]:=true;
sh(i2,i,2);sh(i2,i,3);sh(i2,i,4);sh(i2,i,5);
end;
end;
Попытка написать решатель Сокобана (Какая-то неведомая функция)
Примечания или то, что я узнал у владельца
1 useny - судя по всему УСтЕНЫ
2 vsten - массив клеток Возле СТЕН
3 sten - сами стены
4 sh - скорее всего Шаг, но автор не уверен.
5 sdx и sdy - СДвиг по Х и СДвиг по Y
+154
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<?if (!empty($arResult)):?>
<nav class="mainNav">
<table>
<tbody><tr>
<?
$i = 0;
$previousLevel = 0;
//echo '<pre>'; print_r($arResult); echo '</pre>';
$CatItemMenu = str_replace("/", "", $arResult[0]['LINK']);
foreach($arResult as $arItem):?>
<?$i++;?>
<?if ($previousLevel && $arItem["DEPTH_LEVEL"] < $previousLevel):?>
<?if($previousLevel != 3):?>
<?=str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));?>
<?endif;?>
<?if($previousLevel == 3):?>
</li></ul>
<div class="someProduct" style="min-height: 336px;">
<a class="productLink" href="<?=$arResult["CATALOG_MENU"][$CatItemMenu]["DETAIL_PAGE_URL"]?>">
<span class="image"><img alt="" src="<?=$arResult["CATALOG_MENU"][$CatItemMenu]["PICTURE_SRC"]?>"></span>
<span><?=$arResult["CATALOG_MENU"][$CatItemMenu]["NAME"]?></span>
<?if($arResult["CATALOG_MENU"][$CatItemMenu]["SALE_PRICE"] < $arResult["CATALOG_MENU"][$CatItemMenu]["CATALOG_PRICE_1"]):?>
<span class="oldPrice"><?=$arResult["CATALOG_MENU"][$CatItemMenu]["CATALOG_PRICE_1"]?> руб.</span>
<span class="newPrice"><?=$arResult["CATALOG_MENU"][$CatItemMenu]["SALE_PRICE"]?> руб.</span>
<?else:?>
<span class="newPrice"><?=$arResult["CATALOG_MENU"][$CatItemMenu]["CATALOG_PRICE_1"]?> руб.</span>
<?endif;?>
</a> </div></div> <?endif;?> <?endif?><?if ($arItem["IS_PARENT"]):?> <?if ($arItem["DEPTH_LEVEL"] == 1):?>
<td><div><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a>
<div class="test_mark" style=""><ul>
<?else:?>
<?if($arItem["DEPTH_LEVEL"] == 2):?>
<li><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?><ins>»</ins></a>
<div class="test_mark" style="min-height: 336px;"><ul style="min-height: 304px;">
<?else:?>
<li><a href="<?=$arItem["LINK"]?>" class="parent<?if ($arItem["SELECTED"]):?> item-selected<?endif?>"><?=$arItem["TEXT"]?></a>
<ul>
<?endif;?>
<?endif?>
<?else:?>
<?if ($arItem["PERMISSION"] > "D"):?>
<?if ($arItem["DEPTH_LEVEL"] == 1):?>
<li><a href="<?=$arItem["LINK"]?>" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>"><?=$arItem["TEXT"]?></a></li>
<?else:?>
<?if($arItem["DEPTH_LEVEL"] == 3):?>
<?//Танцы с бубном для вывода меню по два пункта. ?>
<?if($i%2):?>
<li>
<span><a href="<?=$arItem["LINK"]?>"><?=$arItem["TEXT"]?></a></span>
<?if($arResult[$i]["DEPTH_LEVEL"] == 3):?><span><a href="<?=$arResult[$i]["LINK"]?>"><?=$arResult[$i]["TEXT"]?></a></span><?endif;?>
<?if($arResult[$i-3]["DEPTH_LEVEL"] == 2 && $arItem["TEXT"] != $arResult[$i-1]["TEXT"]):?><span><a href="<?=$arResult[$i-1]["LINK"]?>"><?=$arResult[$i-1]["TEXT"]?></a></span><?endif;?>
<?endif;?>
<?if(!($i%2)):?></li><?endif;?>
<?//Танцы Окончены. ?>
<?else:?>
<li><a href="<?=$arItem["LINK"]?>" <?if ($arItem["SELECTED"]):?> class="item-selected"<?endif?>><?=$arItem["TEXT"]?></a></li>
<?endif;?>
<?endif?>
<?else:?>
<?if ($arItem["DEPTH_LEVEL"] == 1):?>
<li><a href="" class="<?if ($arItem["SELECTED"]):?>root-item-selected<?else:?>root-item<?endif?>" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
<?else:?>
<li><a href="" class="denied" title="<?=GetMessage("MENU_ITEM_ACCESS_DENIED")?>"><?=$arItem["TEXT"]?></a></li>
<?endif?>
<?endif?>
<?endif?>
<?$previousLevel = $arItem["DEPTH_LEVEL"];?>
<?
//Добавляем товар
if($arItem["DEPTH_LEVEL"] == 1){
$ClearLink = str_replace("/", "", $arItem['LINK']);
$CatItemMenu = $ClearLink;
//echo $ClearLink.' - '.$previousLevel;
}
?>
<?endforeach?>
<?if ($previousLevel > 1)://close last item tags?>
<?=str_repeat("</ul>", ($previousLevel-1) );?>
<?endif?>
</tr>
</tbody></table>
</nav>
<?endif?>
Создадим меню и выведем его списком по два пункта.
+161
//Создаём новое изображение из старого // gif png jpg
if (preg_match('/[.](GIF)|(gif)$/', $filename)) {
$src = imagecreatefromgif($target); //если оригинал был в формате gif,
} else if (preg_match('/[.](PNG)|(png)$/', $filename)) {
$src = imagecreatefrompng($target); //если оригинал был в формате png,
} else if (preg_match('/[.](JPG)|(jpg)|(jpeg)|(JPEG)$/', $filename)) {
$src = ImageCreateFromJPEG($target); //если оригинал был в формате jpg,
} else {
throw new Exception('формат не определён, шли-бы вы лесом');
}
+151
// Convert parameter fields to objects.
$registry = new JRegistry;
$registry->loadString($data->attribs);
$data->params = clone $this->getState('params');
$data->params->merge($registry);
$registry = new JRegistry;
$registry->loadString($data->metadata);
$data->metadata = $registry;
В недрах Joomla
/components/com_content/models/article.php
Либо я что-то не понимаю, либо...
+165
/* Здесь мы имеем сраный унаследованный пиздец: количество товара передается в параметрах POST-запроса,
имеющих имена вида productX_count, где X - ИД товара. Как предыдущие разработчики разобирали это счастье?
Правильно, перебирали все (блядь, ВСЕ, блядь, 20000 штук!) товары и проверяли, есть ли соответствующее
значение в запросе.
*/
$items5 = GetIBlockElementList(5);
while($arItem = $items5->GetNext())
if(isset($_POST['product'.$arItem['ID']."_id"]) && is_numeric($_POST['product'.$arItem['ID']."_id"]))
{
$_PRODUCTS[$arItem['ID']]['count'] = $_POST['product'.$arItem['ID']."_count"];
}
В этом коде меня утешает только боль и ненависть комментария.
+16
QVector<Line> Converter::convert(QImage &image, Modes mode/*, int left, int top, int right, int bottom*/){
QVector<Line> result;
/* if(left < 0) left = 0;
if(top < 0) top = 0;
//if(right > image.width()) right = image.width();
//if(bottom > image.height()) bottom = image.height();
//points.clear();
//pix.fill(Qt::black);
if(left > right){
left ^= right;
right ^= left;
left ^= right;
}
if(top > bottom){
top ^= bottom;
bottom ^= top;
top ^= bottom;
}*/
int left = 0,top = 0,right = image.width(),bottom = image.height();
for( int i = left; i < right; ++i){
for( int j = top; j < bottom; ++j){
Line p;
p.x1 = p.x2 = i;
p.y1 = p.y2 = j;
p.z1 = qGray(image.pixel(i,j));
p.c = p.z1;
QVector<int> v;
if(i!=left) v.push_back(qGray(image.pixel(i-1,j)));
if(i < right-1) v.push_back(qGray(image.pixel(i+1,j)));
if(j!=top) v.push_back(qGray(image.pixel(i,j-1)));
if(j < bottom-1) v.push_back(qGray(image.pixel(i,j+1)));
if(i!=left && j!= top) v.push_back(qGray(image.pixel(i-1,j-1)));
if(i < right-1 && j!=top) v.push_back(qGray(image.pixel(i+1,j-1)));
if(j < bottom-1 && i!=left) v.push_back(qGray(image.pixel(i-1,j+1)));
if(i < right-1 && j < bottom-1) v.push_back(qGray(image.pixel(i+1,j+1)));
int min = *(std::min_element(v.begin(),v.end()));
if(min < qGray(image.pixel(i,j))){
/* for( unsigned k = 0; k < p.c-min; ++k){
Point p0;
p0.x = i;
p0.y = j;
p0.z = qGray(image.pixel(i,j))-(k+1);
p0.c = qGray(image.pixel(i,j));
points.push_back(p0);
}*/
p.z2 = p.z1 - min;
}else{
p.z2 = p.z1;
}
result.push_back(p);
}
}
/*origin.x = 0;
origin.y = 0;
origin.z = 0.0;*/
switch (mode) {
case ISO:
rotate(result, 3.1415/180*35.2,3.1415/4,-3.1415/4);
//rotate(result, 0,,0);
//rotate(result, 0,0,-3.1415/4);
break;
case BOTTOM:
rotate(result, 3.1415/180*90,0,0);
break;
case LEFT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, 3.1415/180*90,0);
break;
case RIGHT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, -3.1415/180*90,0);
break;
default:
break;
}
return result;
}
Картинка превращается, превращается...
+17
#include <iostream>
int main(){
int std = 10;
std::cout << std << std::endl;
}
+13
#include <iostream>
using namespace std;
// -- robot`s internal closed implementation --
int data1[] = { 0, 1, 2 }; char data2[] = { 42 };
// -- robot`s API
const int *GetMechaData1() { return data1; }
size_t GetMechaData1Size() { return 3; }
const char *GetMechaData2(){ return data2; }
size_t GetMechaData2Size() { return 1; }
// -- pentagon`s internal closed implementation --
//--------------------если T равно U, то результат будет D, а иначе - G------------//
template<class T, class U, class D, class G> struct SelectIF { typedef G type; };
template<class T, class D, class G> struct SelectIF<T, T, D, G> { typedef D type; };
// -- pentagon`s API
enum { eMAXBUFER = 200 * sizeof(int) };
template<class T, size_t N>void AcceptData(const T(&src)[N])
{
typedef typename SelectIF<T, char, int, T>::type Cast;
enum { is_char = std::is_same<T,char>::value };
cout << "received data:\n";
const size_t num = (N<eMAXBUFER) ? N : eMAXBUFER;
if (is_char)
for (size_t n = 0; n < num; ++n)
cout << "char code = " << (Cast)src[n] << " : char = '" << src[n] << "'\n";
else
for (size_t n = 0; n<num; ++n)
cout << "item = " << src[n] << endl;
}
// client code
template<class T, size_t N> struct Adapter
{
typedef Adapter<T, N + 1> Next;
void Pass(const T* data, const size_t num)
{
if (N < num)
{
Next().Pass(data, num);
return;
}
T(&arr)[N] = reinterpret_cast< T(&)[N] > (mBuf);
for (size_t n = 0; n< N; ++n) arr[n] = data[n];
AcceptData(arr);
}
size_t mLen;
T mBuf[eMAXBUFER];
};
template<class T> struct Adapter<T, eMAXBUFER>
{
void Pass(const T* data, const size_t)
{
for (size_t n = 0; n< eMAXBUFER; ++n) mBuf[n] = data[n];
AcceptData(mBuf);
}
size_t mLen;
T mBuf[eMAXBUFER];
};
Adapter<int, 1> adapter1;
Adapter<char, 1> adapter2;
int main()
{
{
const auto data = GetMechaData1();
const auto num = GetMechaData1Size();
adapter1.Pass(data, num);
}
{
const auto data = GetMechaData2();
const auto num = GetMechaData2Size();
adapter2.Pass(data, num);
}
}
Крестушки раскрестушились, а подраться не решились.
Под катом ещё несколько вариантов.
+124
static class FuncExtention
{
public static Func<T1, Func<T2, T3>> Carry<T1, T2, T3>(this Func<T1, T2, T3> func)
{
return t1 => t2 => func(t1, t2);
}
public static Func<T1, Func<T2, Func<T3, T4>>> Carry<T1, T2, T3, T4>(this Func<T1, T2, T3, T4> func)
{
return t1 => t2 => t3 => func(t1, t2, t3);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, T5>>>> Carry<T1, T2, T3, T4, T5>(this Func<T1, T2, T3, T4, T5> func)
{
return t1 => t2 => t3 => t4 => func(t1, t2, t3, t4);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, T6>>>>> Carry<T1, T2, T3, T4, T5, T6>(this Func<T1, T2, T3, T4, T5, T6> func)
{
return t1 => t2 => t3 => t4 => t5 => func(t1, t2, t3, t4, t5);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, T7>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7>(this Func<T1, T2, T3, T4, T5, T6, T7> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => func(t1, t2, t3, t4, t5, t6);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, T8>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8>(this Func<T1, T2, T3, T4, T5, T6, T7, T8> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => func(t1, t2, t3, t4, t5, t6, t7);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, T9>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => func(t1, t2, t3, t4, t5, t6, t7, t8);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, T10>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, T11>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, Func<T11, T12>>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => t11 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, Func<T11, Func<T12, T13>>>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => t11 => t12 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, Func<T11, Func<T12, Func<T13, T14>>>>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => t11 => t12 => t13 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, Func<T11, Func<T12, Func<T13, Func<T14, T15>>>>>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => t11 => t12 => t13 => t14 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, Func<T11, Func<T12, Func<T13, Func<T14, Func<T15, T16>>>>>>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => t11 => t12 => t13 => t14 => t15 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15);
}
public static Func<T1, Func<T2, Func<T3, Func<T4, Func<T5, Func<T6, Func<T7, Func<T8, Func<T9, Func<T10, Func<T11, Func<T12, Func<T13, Func<T14, Func<T15, Func<T16, T17>>>>>>>>>>>>>>>> Carry<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(this Func<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17> func)
{
return t1 => t2 => t3 => t4 => t5 => t6 => t7 => t8 => t9 => t10 => t11 => t12 => t13 => t14 => t15 => t16 => func(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16);
}
}
А что поделать то....