- 1
....iv>'.(isset($row['add_descr']) ? $row['add_descr']:'').'</td....
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
....iv>'.(isset($row['add_descr']) ? $row['add_descr']:'').'</td....
угу, в реальном сайте, который на нашей (говно)поддержке
+2
public interface ICachedObject<TCachedValue>
{
TCachedValue Value { get; set; }
}
public interface ICacheProvider<TCachedObject, TCachedValue>
where TCachedObject : ICachedObject<TCachedValue>
{
TCachedObject Get(string key);
void Set(string key, TCachedObject value);
void Remove(string key);
IEnumerable<TCachedObject> GetAll();
}
public class CachedEntityObject : ICachedObject<IEntity>
{
public EntityState State { get; set; }
public IEntity Value { get; set; }
}
public abstract class CacheProvider<TCache, TCachedObject, TCachedValue> :
ICacheProvider<TCachedObject, TCachedValue>
where TCache : IDictionary<string, TCachedObject>
where TCachedObject : ICachedObject<TCachedValue>
{
protected TCache Cache;
protected abstract void InitializationCache();
public abstract TCachedObject Get(string key);
public abstract void Set(string key, TCachedObject value);
public abstract void Remove(string key);
public abstract IEnumerable<TCachedObject> GetAll();
}
public class CacheEntity : CacheProvider<Dictionary<string, CachedEntityObject>, CachedEntityObject, IEntity>
{
public CacheEntity()
{
InitCache();
}
protected sealed override void InitCache()
{
Cache = new Dictionary<string, CachedEntityObject>();
}
public override CachedEntityObject Get(string key)
{
if (Cache[key] == null)
throw new NullReferenceException($"{nameof(key)} not found from cache list");
return Cache[key];
}
public override void Set(string key, CachedEntityObject value)
{
Remove(key);
Cache[key] = value;
}
public override void Remove(string key)
{
if (Cache.ContainsKey(key))
Cache.Remove(key);
}
public override IEnumerable<CachedEntityObject> GetAll()
{
return Cache.Values;
}
}
Кэш сущностей
+8
template <size_t capacity, bool is_signed>
class fixed_int
{
// Описание ошибки компиляции в случае использования не поддерживаемой размерности
template <int x> struct unsupported_capacity { int i[1/(x-x)]; };
template <> struct unsupported_capacity<1> {};
template <> struct unsupported_capacity<2> {};
template <> struct unsupported_capacity<4> {};
template <> struct unsupported_capacity<8> {};
// Свойства базовых типов, необходимые для перебора
template<typename type> struct type_traits;
template<> struct type_traits <unsigned char> { typedef unsigned char current_type; typedef unsigned short next_type; };
template<> struct type_traits <unsigned short> { typedef unsigned short current_type; typedef unsigned int next_type; };
template<> struct type_traits <unsigned int> { typedef unsigned int current_type; typedef unsigned long next_type; };
template<> struct type_traits <unsigned long> { typedef unsigned long current_type; typedef unsigned long long next_type; };
template<> struct type_traits <unsigned long long int> { typedef unsigned long long int current_type; typedef unsupported_capacity<capacity> next_type; };
template<> struct type_traits <signed char> { typedef signed char current_type; typedef short next_type; };
template<> struct type_traits <short> { typedef short current_type; typedef int next_type; };
template<> struct type_traits <int> { typedef int current_type; typedef long next_type; };
template<> struct type_traits <long> { typedef long current_type; typedef long long next_type; };
template<> struct type_traits <long long int> { typedef long long int current_type; typedef unsupported_capacity<capacity> next_type;};
// Алгоритм выбора типа
template<typename type, bool>
struct type_choice
{
typedef typename type_traits<type>::current_type std_type;
};
template<typename type>
struct type_choice<type, false>
{
typedef typename type_traits<type>::next_type next_type;
typedef typename type_choice<next_type, sizeof(next_type) == capacity>::std_type std_type;
};
// Базовый тип для начала подбора
template <bool is_signed> struct base_type_selector { typedef signed char base_type; };
template <> struct base_type_selector<false> { typedef unsigned char base_type; };
public:
typedef typename type_choice< typename base_type_selector<is_signed>::base_type, sizeof(base_type_selector<is_signed>::base_type) == capacity >::std_type type;
};
"Зачем мне нужен stdint.h?
У меня нет времени, чтобы ебаться с ним!
Лучше я высру ещё десяток-другой шаблонов!"
https://habrahabr.ru/post/280542/
PS,
Пятая строка - вообще угар.
+1
private int GetSroOper(MiscTransactionParams param)
{
if (param.ExpenseItem != null)
{
switch (param.ContractType)
{
case Entities.AT.ContractType.Undefined:
case Entities.AT.ContractType.TimeAndMaterials:
case Entities.AT.ContractType.Retainer:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation900;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
case Entities.AT.ContractType.RecurringService:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation550 : Helper.SLServiceOrderOperation950;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
case Entities.AT.ContractType.FixedPrice:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation500 : Helper.SLServiceOrderOperation950;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
case Entities.AT.ContractType.Incident:
switch ((int)param.ExpenseItem.ExpenseCategory)
{
case 2:
case 3:
case 29684252:
case 29684285:
case 29684805:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation950;
default:
throw new InvalidOperationException("Unsupported Expense Category value");
}
default:
throw new InvalidOperationException("Unsupported ContractType value");
}
}
else
{
switch (param.ContractType)
{
case Entities.AT.ContractType.Undefined:
case Entities.AT.ContractType.TimeAndMaterials:
case Entities.AT.ContractType.Retainer:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation600 : Helper.SLServiceOrderOperation900;
case Entities.AT.ContractType.RecurringService:
return param.BillingItem.IsNonBillable() ? Helper.SLServiceOrderOperation550 : Helper.SLServiceOrderOperation950;
case Entities.AT.ContractType.FixedPrice:
case Entities.AT.ContractType.Incident:
int sroOper = (int)param.OrderOperation.EntityRow()[Constants.ServiceOrderOperation.Field.SroOper];
switch (sroOper)
{
case 500:
case 600:
case 800:
case 850:
case 950:
return sroOper;
default:
throw new InvalidOperationException("Unsupported Operation value");
}
default:
throw new InvalidOperationException("Unsupported ContractType value");
}
}
}
Это наш сеньор написал
+3
public static bool AddStringIfNoExist(this List<string> strlist, string str)
{
if (str == "") return true;
foreach (string s in strlist) if (s == str) return true;
strlist.Add(str);
return false;
}
Hashset? А что это такое?
0
$f = fopen("./.htaccess", "r");
while (!feof($f)) {
$tmp = fgets($f);
$tmp = str_replace(REDIRECT_USER."/", $_POST["redir_user"]."/", $tmp);
$tmp = str_replace(REDIRECT_SHOP."/", $_POST["redir_shop"]."/", $tmp);
$tmp = str_replace(REDIRECT_ADMIN."/", $_POST["redir_admin"]."/", $tmp);
$tmp = str_replace(REDIRECT_NEWS."/", $_POST["redir_news"]."/", $tmp);
$tmp = str_replace(REDIRECT_CART."/", $_POST["redir_cart"]."/", $tmp);
$tmp = str_replace(REDIRECT_PAYMENT."/", $_POST["redir_payment"]."/", $tmp);
$tmp = str_replace(REDIRECT_INFO."/", $_POST["redir_info"]."/", $tmp);
$line[] = $tmp;
}
fclose($f);
Настройка редиректов из админки
+81
mov podi,vilov
+2
public function extractPublicPlace($item)
{
list($a['name'], list($a['lat'], $a['lon'])) = $item;
return $a;
}
просто оставлю
+6
http://requests.readthedocs.org/en/master/
Warning: Recreational use of other HTTP libraries may result in dangerous side-effects, including: security vulnerabilities, verbose code, reinventing the wheel, constantly reading documentation, depression, headaches, or even death.
Не говнокод, даже не говнокоммент. Наоборот, хороший, годный комментарий.
+5
.dostali {
font-weight: bold;
}
Достали!!!11