- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
$z = 1;
do
{
$key = mt_rand( 100000000, 999999999 );
if ( strlen( $key ) == 9 )
{
$z++;
}
} while ( $z < 1 );
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+170
$z = 1;
do
{
$key = mt_rand( 100000000, 999999999 );
if ( strlen( $key ) == 9 )
{
$z++;
}
} while ( $z < 1 );
как вам это?
+123
</tr>
<?php endforeach;?>
</tbody></table><br>
<?php /*<ul style="margin-left:575px;" id="subnavlist">
<li><a class="update" href="jobs-favorites.asp">update</a></li>
</ul> */?>
</form>
коммент насящего php программиста
+102
if (nchan == 1)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],sub_window_length,main_window_length,out_dir,decon_c);
}
if (nchan == 2)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],sub_window_length,main_window_length,out_dir,decon_c);
}
if (nchan == 3)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],sub_window_length,main_window_length,out_dir,decon_c);
}
if (nchan == 4)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],sub_window_length,main_window_length,out_dir,decon_c);
}
if (nchan == 5)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],sub_window_length,main_window_length,out_dir,decon_c);
}
if (nchan == 6)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],sub_window_length,main_window_length,out_dir,decon_c);
}
if (nchan == 7)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],chan_list[6],sub_window_length,main_window_length,out_dir,decon_c);
}
...
}
if (nchan >= 14)
{
fprintf(commands_ptr,(char *)"StaNoise sta=%s start_time=%14.3f chan_list=%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s window_type=nutall4a sub_window_length=%5.1f main_window_length=%6.1f out_dir=%s plot=yes record=yes decon=%s\n",sta,gmttime,chan_list[0],chan_list[1],chan_list[2],chan_list[3],chan_list[4],chan_list[5],chan_list[6],chan_list[7],chan_list[8],chan_list[9],chan_list[10],chan_list[11],chan_list[12],chan_list[13],sub_window_length,main_window_length,out_dir,decon_c);
}
Тяжело в сях работать со строками и переменным числом параметров...
+168
typedef union Variant
{
public:
Variant() {}
Variant(signed int val) :
v_int(val)
{}
operator signed int &() { return const_cast<signed int&>(this->operator const signed int &()); }
operator const signed int&() const { return v_int; }
Variant(unsigned int val) :
v_uint(val)
{}
operator unsigned int &() { return const_cast<unsigned int&>(this->operator const unsigned int &()); }
operator const unsigned int &() const { return v_uint; }
Variant(char val) :
v_char(val)
{}
operator char &() { return const_cast<char&>(this->operator const char &()); }
operator const char&() const { return v_char; }
Variant(double val) :
v_float(val)
{}
operator double &() { return const_cast<double&>(this->operator const double &()); }
operator const double &() const { return v_float; }
Variant(void *val) :
v_ptr(val)
{}
operator void*& () { return const_cast<void*&>(this->operator void *&()); }
operator const void* const& () const { return v_ptr; }
static size_t getValueSize(const Type::OfType &type)
{
size_t result = 0;
switch ( type )
{
case Type::Pointer:
case Type::CharPtr:
case Type::IntPtr:
case Type::UIntPtr:
case Type::RealPtr:
case Type::String:
result = sizeof(v_ptr);
break;
case Type::Char:
result = sizeof(v_char);
break;
case Type::Int:
result = sizeof(v_int);
break;
case Type::UInt:
result = sizeof(v_uint);
break;
case Type::Real:
result = sizeof(v_float);
break;
case Type::Void:
result = 0;
break;
}
return result;
}
private:
void* v_ptr;
char v_char;
unsigned int v_uint;
signed int v_int;
double v_float;
} Variant;
Небольшая имплементация безтиповости ;-[
+158
<script type="text/javascript">
jQuery('.container').cycle({
fx: 'scrollHorz',
prev: '#prev2',
next: '#next2',
timeout: 0});
</script>
<img id="prev2" src="<?=$this->getSkinUrl('images/leftarr.png')?>" alt="Left Arrow" />
<?php foreach ($_gallery as $_image)
$__gallery[] = $_image;
?>
<ul class="container">
<?php
for($i = 0;$i < count($__gallery);$i++):
$_image = $__gallery[($i) % count($__gallery)];
?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
</li>
<?php endfor; ?>
</ul>
<ul class="container">
<?php
for($i = 0;$i < count($__gallery);$i++):
$_image = $__gallery[($i+1) % count($__gallery)];
?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
</li>
<?php endfor; ?>
</ul>
<ul class="container">
<?php
for($i = 0;$i < count($__gallery);$i++):
$_image = $__gallery[($i+2) % count($__gallery)];
?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
</li>
<?php endfor; ?>
</ul>
<ul class="container">
<?php
for($i = 0;$i < count($__gallery);$i++):
$_image = $__gallery[($i+3) % count($__gallery)];
?>
<li>
<a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" onclick="slide('<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()) ?>',<?php echo ($s = isset($s) ? ++$s : 0) ?>,'<?php echo $this->getGalleryUrl($_image) ?>'); return false;"><img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>
</li>
<?php endfor; ?>
</ul>
слайдер с прокруткой с помощью цайкла
−125
'aaa' =~ /a(?=)aa/;
'aaa' =~ /(?=)aaa/;
'aaa' =~ /aaa(?=)/;
в ActiveState Perl 5.10.0 build 1003 неожиданно обнаружил грубую ошибку в регулярных выражениях. Конструкция (?=), которая означает "с этого места имеется пустой фрагмент текста" вообще не работает! То же относится к аналогичной конструкции "заглядывания назад" (?<=). Например, не находится соответствие в операторах и т.д. Я пришёл в недоумение, ведь это работало правильно в ActiveState Perl 5.8.7 и в более ранних версиях, которые были установлены у меня прежде.
+150
nPosition = !bInvert ? data->pos_back
: data->pos_front;
+157
var is_ie = !(navigator.appName.indexOf("Netscape") != -1);
Из недр http://habrahabr.ru/blogs/internet/117202/
+161
$Qstatus = $osC_Database->query('select max(cms_id) as cms_id from cms');
$Qstatus->execute();
$cms_id = $Qstatus->valueInt('cms_id') + 1;
Код в OSCommerce использующийся для увеличения id на 1.
+134
int _Mbtowcx(wchar_t *pwc, const char *s, size_t nin, mbstate_t *pst, _Statab *pmbstate)
char state = (char)pst->_State;
unsigned char *su = (unsigned char *)s;
wchar_t wc = (wchar_t)pst->_Wchar;
static const mbstate_t initial = {0};
if (pmbstate->_Tab[0] == 0) { /* no table, convert from UTF8 */
if (s == 0)
{ /* set initial state */
*pst = initial;
return (0);
}
for (; ; ++su, --nin) { /* consume an input byte */
if (nin == 0) { /* report incomplete conversion */
pst->_Wchar = wc;
pst->_State = state;
return (-2);
}
else if (0 < state) { /* fold in a successor byte */
if ((*su & 0xc0) != 0x80) { /* report invalid sequence */
errno = EILSEQ;
return (-1);
}
wc = (wchar_t)((wc << 6) | (*su & 0x3f));
--state;
}
else if ((*su & 0x80) == 0)
wc = *su; /* consume a single byte */
else if ((*su & 0xe0) == 0xc0) { /* consume first of two bytes */
wc = (wchar_t)(*su & 0x1f);
state = 1;
}
else if ((*su & 0xf0) == 0xe0) { /* consume first of three bytes */
wc = (wchar_t)(*su & 0x0f);
state = 2;
}
else{ /* report invalid sequence */
errno = EILSEQ;
return (-1);
}
if (state == 0) { /* produce an output wchar */
if (pwc != 0)
*pwc = wc;
pst->_State = 0;
return (wc == 0 ? 0 : (const char *)++su - s);
}
}
}
else
{ /* run finite state machine */
int limit = 0;
if (s == 0) { /* set initial state */
*pst = initial;
return (pmbstate->_Tab[0][0] & _ST_STATE);
}
for (; ; ) { /* perform a state transformation */
unsigned short code;
const unsigned short *stab;
if (nin == 0)
{ /* report incomplete conversion */
pst->_Wchar = wc;
pst->_State = state;
return (-2);
}
else if (_NSTATE <= state
|| (stab = pmbstate->_Tab[state]) == 0
|| (_NSTATE*UCHAR_MAX) <= ++limit
|| (code = stab[*su]) == 0)
{ /* report invalid sequence */
errno = EILSEQ;
return (-1);
}
state = (char)((code & _ST_STATE) >> _ST_STOFF);
if (code & _ST_FOLD)
wc = (wchar_t)(wc & ~UCHAR_MAX | code & _ST_CH);
if (code & _ST_ROTATE)
wc = (wchar_t)(wc << CHAR_BIT | UCHAR_MAX
& wc >> CHAR_BIT * (sizeof (wchar_t) - 1));
if (code & _ST_INPUT && *su != '\0')
++su, --nin, limit = 0;
if (code & _ST_OUTPUT)
{ /* produce an output wchar */
int nused = (const char *)su - s;
if (pwc)
*pwc = wc;
pst->_Wchar = wc;
pst->_State = state;
return (wc == 0 ? 0 : nused == 0 ? -3 : nused);
}
}
}
}
Долго не мог понять почему не работает
setlocale(...);
_setmbcp(...);
mbtowc(...);
на C++ Builder. Пока не заглянул в исходники.