- 1
- 2
- 3
function _spb_similar_similar_video_html(&$item, $key) {
$item = htmlspecialchars($item, ENT_NOQUOTES);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+28
function _spb_similar_similar_video_html(&$item, $key) {
$item = htmlspecialchars($item, ENT_NOQUOTES);
}
+130
int i,j;
char alph[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//Подстановка по таблице 1
int S_there[26][8]={{1,0,0,1,1,0,0,1},{1,0,0,0,1,0,0,0},{1,0,1,0,1,0,1,0},{0,0,1,1,0,0,1,1},{1,1,1,0,0,0,0,1},
{1,0,0,0,0,1,1,1},{1,1,1,1,1,1,1,1},{1,1,0,1,0,0,1,0},{0,1,1,1,1,0,0,0},{1,1,0,0,0,0,1,1},{1,0,1,0,0,1,0,1},{0,1,0,0,1,0,1,1},
{0,0,0,1,1,1,1,0},{0,1,0,1,0,1,0,1},{1,1,0,0,1,1,0,0},{0,0,0,1,0,0,0,1},{1,1,0,1,1,1,0,1},{1,0,1,1,0,1,0,0},{0,0,1,0,1,1,0,1},
{0,0,0,0,0,0,0,0},{0,1,1,0,0,1,1,0},{0,1,0,0,0,1,0,0},{1,1,1,1,0,0,0,0},{0,0,1,1,1,1,0,0},{0,1,1,0,1,0,0,1},{0,0,1,0,0,0,1,0}};
char str[]="THIISATESTFILEFORCHECKINGCYPHERMODULE";
int len=strlen(str);
int num[len];//массив с порядковыми номерами
int vector[len][8];//массив с ОТ, переведённым в двоичные вектора длины 8
for (i=0; i< len; i++)//Присваиваем каждой букве порядковый номер (а=0,b=1 и т.д.)
{
num[i]=((strchr(alph, str[i])-alph)% 26 + 0x01);
num[i]--;
}
for (i=0; i<len; i++)//Меняем букву на двоичный вектор длины 8 согласно порядковому номеру
{
int number=num[i];//счётчик текста
for (j=0; j<8; j++)
{
vector[i][j]=S_there[number][j];
}
}
for (i=0; i<len; i++)//Вывод на экран ОТ
{
for (j=0; j<8; j++)
{
printf("%u",vector[i][j]);
}
printf(" %c\n",str[i]);
}
Нашёл в своей очень старой лабе...Нужно было буквы на входе преобразовать в двоичные вектора (например, а=10011001, b=10001000 и т.д.) ну и дальше ковыряться с этими векторами...почему я категорически не захотел тогда использовать case - хз :)))
+118
Params.Name = GetControl(pnlName) ? edName.Text : "";
Params.DateMeasurement = TOperation.GetDateValue(edDateTime);
Params.HalfYear = pnlHalfYear.Tag != null &&
pnlHalfYear.Tag is bool &&
(bool)pnlHalfYear.Tag &&
edHalfYear.SelectedItem != null &&
edHalfYear.SelectedItem.Value != null &&
edHalfYear.SelectedItem.Value is byte ? (byte)
edHalfYear.SelectedItem.Value : (byte)0;
Params.IdDepSource = GetControl(pnlDepSource) ? TDataList.GetComboRecId(edDepSource) : 0;
Params.IdDepSource2 = pnlDepSource2.Tag != null &&
pnlDepSource2.Tag is bool &&
(bool)pnlDepSource2.Tag ?
TDataList.GetComboRecId(edDepSource2) : 0;
Params.Salt = pnlDepSource2.Tag != null &&
pnlDepSource2.Tag is bool &&
(bool)pnlDepSource2.Tag ?
getSalt() : 0;
Params.Description = edComment.Text;
ацкий код сохранения параметров. Досталось в наследство. Автор кода естественно имеет в/о факультета компьютерных педиков.
+162
class Program implements ProgramProvider {
public static function getInstance() {
return new Program();
}
}
Гениальная реализация singleton!
+158
$sCmd='$result=$this->'.$aEvent['method'].'();';
$this->Hook_Run("action_event_".strtolower($this->sCurrentAction)."_before",array('event'=>$this->sCurrentEvent,'params'=>$this->GetParams()));
eval($sCmd);
$this->Hook_Run("action_event_".strtolower($this->sCurrentAction)."_after",array('event'=>$this->sCurrentEvent,'params'=>$this->GetParams()));
return $result;
LiveStreet CMS... nuff said...
+153
do
{
$firstDate = ConvertTimeStamp($firstDateSt, "SHORT");
$lastDate = ConvertTimeStamp($lastDateSt, "SHORT");
$arPeriod = Array(
"TITLE" => CSchool::GetDiaryPeriod($firstDate, $lastDate),
"HREF" => $APPLICATION->GetCurPageParam('START_WEEK='.$firstDate.'&END_WEEK='.$lastDate, array("START_WEEK", "END_WEEK"))
);
Битрикс...
do без while? лаконично
+163
//fucking designers
if ( $page->importantshort ) $page->short = true;
if ( $page->importantNOTshort ) $page->short = false; // так то!
+157
while(true)
{
if ($i==0)
{
$new_form_name = $form_res[0]['frm_name'] . ' ( Copy )';
} else
{
$new_form_name = $form_res[0]['frm_name'] . ' ( Copy '.$i.' )';
}
if(!in_array($new_form_name, $formaNames))
{
break;
}
$i++;
}
Есть имя формы $form_res[0]['frm_name'] , напр "FORMNAME".
нужно получить новое имя вида "FORMNAME ( Copy 1)"
+999
template<class TVisitedComponentList>
TUniqueIDOfVisitedComponentList getUniqueIDOfVisitedComponentTypeList(void)
{
static Type2Type<TVisitedComponentList> UniqueObjectForVisitedComponentTypeList;
return (size_t)(&UniqueObjectForVisitedComponentTypeList);
}
template<class TVisitedComponentList>
TCastWindowComponentTo* const castWindowComponentInternal(PegThing* const Window)
{
ASSERT(Window!=NULL);
if(Window==NULL)
return NULL;
STATIC_CHECK(!(boost::mpl::empty<TVisitedComponentList>::value), TVisitedComponentList_must_be_not_empty_and_be__boost_mpl_list_c__type);
const TUniqueIDOfVisitedComponentList UniqueIDOfVisitedComponentList=this->getUniqueIDOfVisitedComponentTypeList<TVisitedComponentList>();
const TCasterRepositorys::const_iterator NotFound=_casterRepositorys.end();
TCasterRepositorys::const_iterator findedCasterRepositoryForThisVisitedComponentList=_casterRepositorys.find(UniqueIDOfVisitedComponentList);
if(findedCasterRepositoryForThisVisitedComponentList==NotFound)
{
this->registerVisitedComponentList<TVisitedComponentList>();
findedCasterRepositoryForThisVisitedComponentList=_casterRepositorys.find(UniqueIDOfVisitedComponentList);
}
ASSERT(findedCasterRepositoryForThisVisitedComponentList!=NotFound);
const TCasterRepository::const_iterator NotFoundCaster=findedCasterRepositoryForThisVisitedComponentList->second->end();
const unsigned int ComponentType=const_cast<PegThing* const>(Window)->Type();
const TCasterRepository::const_iterator findedCaster=findedCasterRepositoryForThisVisitedComponentList->second->find(ComponentType);
if(findedCaster==NotFoundCaster)
return NULL;
ASSERT(findedCaster!=NotFoundCaster);
return (*(findedCaster->second))(Window);
}
template<class TCurrentItem, class TEnd>
void registerVisitedComponentListItem(TCasterRepository& casterRepository, TCurrentItem CurrentItem, TEnd End)
{
using namespace boost;
enum {WINDOW_COMPONENT_TYPE=mpl::deref<TCurrentItem>::type::value};
STATIC_CHECK((mpl::has_key<TWindowComponentsTypeIdToTypeMap, mpl::int_<WINDOW_COMPONENT_TYPE> >::value!=0), WINDOW_COMPONENT_TYPE_must_be_at_TWindowComponentsTypeIdToTypeMap);
typedef mpl::at<TWindowComponentsTypeIdToTypeMap, mpl::int_<WINDOW_COMPONENT_TYPE> >::type TRealTypeOfWindowComponent;
this->checkDuplicateComponentTypeID(WINDOW_COMPONENT_TYPE, casterRepository);
struct _
{
static TCastWindowComponentTo* const casterForEachWindowComponent(PegThing* const Window)
{
ASSERT(Window!=NULL);
if(Window==NULL)
return NULL;
TRealTypeOfWindowComponent* const RealTypeComponent = static_cast<TRealTypeOfWindowComponent* const>(Window);
ASSERT(RealTypeComponent!=NULL);
TCastWindowComponentTo* const FinalCastedWindowComponent = static_cast<TCastWindowComponentTo* const >(RealTypeComponent);
ASSERT(FinalCastedWindowComponent!=NULL);
return FinalCastedWindowComponent;
}
};
TCasterForEachWindowComponent CasterForEachWindowComponentFunction=&(_::casterForEachWindowComponent);
this->checkDuplicateType(CasterForEachWindowComponentFunction, casterRepository);
casterRepository[WINDOW_COMPONENT_TYPE]=CasterForEachWindowComponentFunction;
registerVisitedComponentListItem(casterRepository, mpl::next<TCurrentItem>::type(), TEnd());
}
template<class TEnd>
void registerVisitedComponentListItem(TCasterRepository& casterRepository, TEnd CurrentItem, TEnd End)
{}
Код из того же большого проекта.
Ассерты после static_cast и "шаблонная магия" особенно доставляют.
Мне конечно boost::mpl нравиться, но я считаю, что его негоже использовать в реальных проектах.
+151
$now = date(date('Y-m-d H:i:s'));