- 1
- 2
- 3
- 4
- 5
- 6
class Program implements ProgramProvider {
public static function getInstance() {
return new Program();
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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'));
+162
if(
(trim($class->antihacker($_POST['fio']))=='')or
(trim($class->antihacker($_POST['phone']))=='')or
(trim($class->antihacker($_POST['email']))=='')or
(trim($class->antihacker($_POST['adress']))=='')
){$error="Указанные поля заполнены неверно!";}
elseif(!$class->validate_email($_POST['email'])){$error="E-mail указан не корректно!";}
elseif($_POST['is_company']=='1'){
if(
(trim($class->antihacker($_POST['company']))=='')or
(trim($class->antihacker($_POST['fio_cmp']))=='')or
(trim($class->antihacker($_POST['email_cmp']))=='')or
(trim($class->antihacker($_POST['kchet']))=='')or
(trim($class->antihacker($_POST['rchet']))=='')
){$error="Указанные поля заполнены неверно!";}
}
анти хакерз...
+73
public String XOR_Encrypt(String source, String key)
{
byte plain_text[] = new byte[source.length()];
plain_text = source.getBytes();
byte key_mas[] = new byte[key.length()];
key_mas = key.getBytes();
int key_len = key.length();
int crypt_pos = 0;
for(int i = 0; i < source.length(); i++)
{
plain_text[i] = (byte)(plain_text[i] ^ 0xaa);
plain_text[i] = (byte)(plain_text[i] ^ key_mas[crypt_pos]);
if(crypt_pos >= key_len - 1)
crypt_pos = 0;
else
crypt_pos++;
}
String EText = ByteToHexString(plain_text);
return EText;
}
public static String EncodeSimmetr(String s)
{
int MultKey = 62142;
int AddKey = 11719;
byte f1[] = new byte[s.length()];
byte f[] = new byte[s.length()];
f = s.getBytes();
for(int i = 0; i < s.length(); i++)
{
f1[i] = (byte)(f[i] ^ MultKey);
MultKey ^= AddKey;
}
s = new String(f1);
return s;
}
Система шифрования в той-же платёжке...
+71
String url = "http://*.*.*.*:*/java/?code=" + sCode + "&request=monitor";
String LogPass = sName + ":" + sPass;
String sAuth = "Basic " + encodeBase64(LogPass);
try
{
con = (HttpConnection)Connector.open(url);
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Confirguration/CLDC-1.0");
con.setRequestProperty("Accept_Language", "en-US");
con.setRequestProperty("Content-Type", "//text plain");
con.setRequestProperty("Connection", "close");
con.setRequestProperty("Authorization", sAuth);
in = con.openInputStream();
if(con.getResponseCode() == 200)
{
StringBuffer sb = new StringBuffer();
int chr;
while((chr = in.read()) != -1)
sb.append((char)(chr < 192 || chr > 255 ? chr : chr + 848));
sBuff = sb.toString();
}
}
Авторизация в одной из платёжных систем