- 1
- 2
- 3
- 4
- 5
- 6
Random random = new Random(Environment.TickCount);
for (int i = 0; i < random.Next(380, 480); i++)
{
Marshal.AllocHGlobal(random.Next(0x4400, 0xd400));
Thread.Sleep(1);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+134
Random random = new Random(Environment.TickCount);
for (int i = 0; i < random.Next(380, 480); i++)
{
Marshal.AllocHGlobal(random.Next(0x4400, 0xd400));
Thread.Sleep(1);
}
Из исходников подрядчика...
Заказчиков надо садить на иглу правильно
+135
if (currentItem.Type.ActiveProperty != null)
{
Type controltype = currentControl.GetType();
PropertyInfo pinfo = controltype.GetProperty(currentItem.Type.ActiveProperty.Name);
bool enabledtrue = (currentItem.Type.ActiveProperty.Name.ToLower() != "readonly");
if ((r1 != 2) || _page.ReadOnly)
enabledtrue = !enabledtrue;
pinfo.SetValue(currentControl, enabledtrue, null);
}
enabledtrue как пример интуитивно-понятного названия переменной
+154
$this->db->insert("orders", $data);
//Get order's id
$this->db->select("orders_id");
$this->db->where('orders_customer_tel', $data['tel']);
$this->db->order_by("orders_id", "desc");
$this->db->limit(1);
$query = $this->db->get("orders");
foreach ($query->result_array() as $res) {
$orders_id = $res['orders_id'];
}
Ништяяяк!
−131
[self
performSelectorOnMainThread: @selector(_blockCaller:)
withObject: ^{
[self _reportAchievement:achievement listener:listener];
}
waitUntilDone: YES
];
<...>
- (void) _blockCaller:(void(^)())blockHandler {
blockHandler();
}
GCD не в моде.
+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?>
Создадим меню и выведем его списком по два пункта.
+154
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
$json['error']['shipping']['postcode'] = $this->language->get('error_postcode');
}
if ($this->request->post['shipping_country_id'] == '') {
$json['error']['shipping']['country'] = $this->language->get('error_country');
}
if ($this->request->post['shipping_zone_id'] == '') {
$json['error']['shipping']['zone'] = $this->language->get('error_zone');
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
$json['error']['shipping']['postcode'] = $this->language->get('error_postcode');
}
строки 279 - 301
файл catalog/controller/checkout/manual.php
opencart 1.5.5.1.1
Зачем два идентичных куска кода (1 - 6 и 16 - 21), в одном файле идущих друг за другом, я так и не понял.
+160
if ( String(typeof Ext).toLowerCase() === "object") {
Ext.BLANK_IMAGE_URL = '/style/ext/resources/images/default/s.gif';
}
Ох. Штабильненько.
+135
Структура для хранения данных:
typedef struct rs_script_t {
int status; // on/off
int next_stage;
int next_time;
} rs_script_t;
Макросы:
#define SEQ(scr1,t) \
const int scr_zero = __COUNTER__; \
rs_script_t *scr = scr1; \
if ( (scr->status) && (t > scr->next_time) ) { \
switch(scr->next_stage) { \
#define END_SEQ } };
#define SEQ_FIRST \
case 0: \
scr->next_stage = scr_zero;
#define SEQ_DT(dt) \
scr->next_stage = __COUNTER__ + 1; \
scr->next_time += dt; \
break; \
case __COUNTER__: \
#define SEQ_DT_TAGGED(dt,tag) \
scr->next_stage = __COUNTER__ + 1; \
scr->next_time += dt; \
break; \
case __COUNTER__: \
case (100000+tag): \
#define SEQ_LAST_DEFAULT \
scr->status = 0; \
break; \
\
default: \
DEBUG10f(":: ERROR, unknown stage position: %d \n", scr->next_stage); \
break;
#define SEQ_GOTO(dt,tag) \
scr->next_stage = 100000+tag; \
scr->next_time += dt; \
break;
#define SEQ_GOTO_INSTANT(tag) \
scr->next_stage = 100000+tag; \
break;
Пользоваться примерно так:
void process() { // вызывать каждый кадр
SEQ(&scrtest, rs_app.app_time)
SEQ_FIRST
printf("Ноль\n");
SEQ_DT(1000)
printf("Один\n");
SEQ_DT(1000)
printf("Два\n");
SEQ_DT_TAGGED(1000, 555)
printf("Три (метка №555) \n");
SEQ_DT(1000)
printf("Четыре\n");
SEQ_DT(1000)
printf("Пять\n");
SEQ_DT(1000)
printf("Шесть, повторяем с метки №555, если нажат Шифт\n");
if (rs_keyboard_is_key_down(RS_KEY_SHIFT_L)) {
SEQ_GOTO(1000, 555);
};
printf("Завершаем. \n");
SEQ_LAST_DEFAULT
END_SEQ;
};
Страдания по yield
+152
public function getNearestRoadsOrderedByDistanceFromOverpassAPI ($point, $radius = 1000, $highway = FALSE, $raw = FALSE, $json = FALSE)
за то со смыслом!
+129
[Serializable]
private class NameValue<N, V>
{
public N Name { get; set; }
public V Value { get; set; }
public NameValue() { }
public NameValue(N name, V value)
{
Name = name;
Value = value;
}
}
private System.Collections.Generic.List<NameValue<string, string>> productList =
new System.Collections.Generic.List<NameValue<string, string>>();
не шутка