- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
var code = '\
int sum(int a, int b) {\
__asm {\
mov eax, a;\
add eax, b;\
mov a, eax;\
}\
return a;\
}';
var sum = cpp2js(code);
var ans = sum(34, 288);
alert(ans);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+4
var code = '\
int sum(int a, int b) {\
__asm {\
mov eax, a;\
add eax, b;\
mov a, eax;\
}\
return a;\
}';
var sum = cpp2js(code);
var ans = sum(34, 288);
alert(ans);
http://www.speqmath.com/tutorials/cpp2js/index.html
+3
$('.product-value').find('.form_select_body').find('.dropdown').find('a').on('click', function(){
$('#ordering_popup').find('.popup-section_right').find('[checked=checked]').parents('.equipment-product-preview').find('.equipment-product-info').find('.value').text($(this).text());
$('#ordering_popup').find('.popup-section_right').find('[checked=checked]').parents('.equipment-product-preview').find('.equipment-product-info').find('.value').attr('value',$(this).text());
$('#ordering_popup').find('.popup-section_left').find('.equipment-product-preview:eq(0)').find('.equipment-product-info').find('.value').text($(this).text());
$('#ordering_popup').find('.popup-section_left').find('.equipment-product-preview:eq(0)').find('.equipment-product-info').find('.value').attr('value',$(this).text());
});
−2
unsigned strlen(const char *str)
{
const char *ptr;
for (ptr = str; *ptr; ++ptr);
return ptr - str;
}
char *strcpy(char *dst, const char *src)
{
while((*dst++ = *src++) != 0);
return dst;
}
namespace std
{
class string
{
public:
string(const char *str = 0) : size(str ? strlen(str) : 0)
{
this->str = new char[size + 1];
if(str) strcpy(this->str, str);
else this->str[0]=0;
}
string(const string &str) : size(str.size)
{
this->str = new char[size +1];
strcpy(this->str, str.str);
}
~string()
{
delete[] str;
}
const char* c_str() const
{
return str;
}
private:
char *str;
unsigned size;
};
class Cout
{
public:
Cout &operator<< (const char *str)
{
unsigned len = strlen(str);
asm volatile (
"movl $0x04, %%eax\n"
"movl $0x01, %%ebx\n"
"int $0x80\n"
:
: "c"(str), "d"(len));
return *this;
}
Cout &operator<< (const string &str)
{
operator<< (str.c_str());
return *this;
}
} cout;
}
int main()
{
std::string str = "Hello World!";
std::cout << str << "\n";
return 0;
}
Ещё 1 хелловорлд для линуха x86 на С++
+1
$(".lucky-card-divforCheck").hover(
function () {
if (document.getElementById('lucky-card-p-mail').getElementsByTagName('input')[0].value=="" &&
document.getElementById('lucky-card-p-phone').getElementsByTagName('input')[0].value==""
) {
$(document.getElementById("lucky-card-butt1")).hide();
$(document.getElementById("lucky-card-butt2")).show();
/*document.getElementById('lucky-card-err_fio').innerHTML='Не работает элс';*/
} else {
/*document.getElementById('lucky-card-err_fio').innerHTML='Работает элс';*/
};
}
,
function () {
$(document.getElementById("lucky-card-butt2")).hide();
$(document.getElementById("lucky-card-butt1")).show();
}
);
$('#lucky-card-empty-butt').click(function(){
document.getElementById('lucky-card-err_fio').innerHTML='Напишите хотя бы почту или телефон';
});
изящная валидация
+14
public static bool Convert(string fileName, string Namefile) {
...
}
нет, ну не дебил?
+3
$disabled = $_SESSION['adminUser']->userlevel() < UserLevel::RESELLER_SUPPORT;
$enabled = $_SESSION['adminUser']->userlevel() > UserLevel::RESELLER_SUPPORT;
Form::datePicker('valid_to', 'valid_to', $value, !$enabled);
+2
(function ($) {
Drupal.behaviors.kdating = {
attach: function (context, setting) {
var links = $('#field-slideshow-1-pager').find('a');
links.colorbox({ rel: 'gal' });
$.each(links, function (index, value) {
var val = $(value);
var href = val.find('img').attr('src');
var path = href.split('/'),
newPath = path[0] + '//'
+ path[2] + '/'
+ path[3] + '/'
+ path[4] + '/'
+ path[5] + '/'
+ path[9];
val.attr('href', newPath);
});
}
};
})(jQuery);
Парсим ссылки вместе
+1
class CBaseEntity {
// ...
void (CBaseEntity ::*m_pfnThink)(void);
virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)(); };
// ...
// Ugly code to lookup all functions to make sure they are exported when set.
#ifdef _DEBUG
void FunctionCheck( void *pFunction, char *name )
{
if (pFunction && !NAME_FOR_FUNCTION((uint32)pFunction) )
ALERT( at_error, "No EXPORT: %s:%s (%08lx)\n", STRING(pev->classname), name, (uint32)pFunction );
}
BASEPTR ThinkSet( BASEPTR func, char *name )
{
m_pfnThink = func;
FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnThink)))), name );
return func;
}
// ...
};
// Ugly technique to override base member functions
// Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a
// member function of a base class. static_cast is a sleezy way around that problem.
#ifdef _DEBUG
#define SetThink( a ) ThinkSet( static_cast <void (CBaseEntity::*)(void)> (a), #a )
// ...
#else
#define SetThink( a ) m_pfnThink = static_cast <void (CBaseEntity::*)(void)> (a)
// ...
#endif
https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/dlls/cbase.h
> it's illegal
В крестах всё легально, главное - попросить прощения в комментах...
+2
if ($this->getShowTemplateHints()) {
echo <<<HTML
<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;">
<div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'"
onmouseout="this.style.zIndex='998'" title="{$fileName}">{$fileName}</div>
HTML;
if (self::$_showTemplateHintsBlocks) {
$thisClass = get_class($this);
echo <<<HTML
<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial;
text-align:left !important; z-index:998;" onmouseover="this.style.zIndex='999'" onmouseout="this.style.zIndex='998'"
title="{$thisClass}">{$thisClass}</div>
HTML;
}
}
Правильная реализация hover эффекта. Яркости для картины добавляет то, что это все написано в блоке MVC модели и понятное дело, на живом проекте.
+2
if (count($not_enough_rights) == 1 and !empty($not_enough_rights['user_extra'])) {
// если нужен доступ только к user_extra, то дополнительного доступа не надо, но скрываем сами права user_extra
} else {
if (count(array_merge($user_rights, $EDIT_ADMIN_GROUPS)) != count($EDIT_ADMIN_GROUPS)) {
$GLOBALS['VALID_GROUPS'] = array('root');
} else {
$GLOBALS['VALID_GROUPS'] = array('superadmin');
}
}
Если $user_rights не пустой, то ты просто админ, если пустой, то суперадмин. Не проставил в БД права - суперадмин!