- 1
str_replace('-','/',date("Y-m-d",($from+(60*60*24*$i))))
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+163
str_replace('-','/',date("Y-m-d",($from+(60*60*24*$i))))
Как-то очень спешил и сам себе наговнокодил, ну куда деваться, со всеми бывает )
+162
$uploadedFileNameParts = explode('.',$fileName);
$uploadedFileExtension = array_pop($uploadedFileNameParts); //pathinfo($fileName, PATHINFO_EXTENSION);
//Это наверно круче и быстрей, чем array('jpeg', 'jpg', 'gif', 'png')
$validFileExts = explode(',', 'jpeg,jpg,png,gif');
$extOk = false;
foreach($validFileExts as $key => $value)
{
if( preg_match("/$value/i", $uploadedFileExtension ) )
{
$extOk = true;
}
}
// if(!in_array($fileExtension, array('png', 'jpg', 'gif', 'jpeg'), false)) не катит...
if ($extOk == false)
{
echo JText::_( 'INVALID EXTENSION' );
return;
}
//...
if( !is_int($imageinfo[0]) || !is_int($imageinfo[1]) || !in_array($imageinfo['mime'], $validFileTypes) )
{
//Кто нибудь встречал картинки с размером 0 на x(где x > 0)..?
//....
}
Из туториала http://docs.joomla.org/Creating_a_file_uploader_in_your_compone nt ...
+119
public static Bitmap DrawBarsChart(ChartType t, Size s)
{
double[] values = DataValues;
string[] names = DataNames;
Bitmap bmp = new Bitmap(s.Width, s.Height);
if (t != ChartType.bars || names.Length != values.Length || names.Length < 2)
return bmp;
else
{
Graphics g = Graphics.FromImage(bmp as Image);
g.Clear(Color.White);
g.DrawLines(new Pen(Brushes.Black), new Point[] { new Point(20, 20), new Point(20, s.Height - 20), new Point(s.Width - 200, s.Height - 20) });
int Columnwidth = (s.Width - 240) / values.Length;
if (Columnwidth > 150) Columnwidth = 150;
double maxvalue = values.Max();
int counter = 1;
int rangefirst;
int rangesecond;
while (true)
{
if (maxvalue / Math.Pow(10, counter) < 10)
{
rangefirst = (int)Math.Floor(maxvalue / Math.Pow(10, counter));
rangesecond = (int)(maxvalue - rangefirst * Math.Pow(10, counter));
break;
}
else
{
counter++;
}
}
int rangepix = (s.Height - 60) / (rangefirst + 1);
for (int i = 0; i < rangefirst + 1; i++)
{
g.DrawString((i * Math.Pow(10, counter)).ToString(), new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular),
Brushes.Black, new PointF(0, s.Height - 30 - rangepix * i));
g.DrawLine(new Pen(Brushes.Black), new Point(17, s.Height - 20 - rangepix * i), new Point(20, s.Height - 20 - rangepix * i));
}
Colors colors = new Colors(); //класс-контейнер цветов (99 штук)
int startcolor = new Random(DateTime.Now.Millisecond).Next(99);
int j = startcolor;
int startx = 21;
int ColumnNumber = 1;
foreach (var value in values)
{
int curfirstrange = (int)Math.Floor(value / Math.Pow(10, counter));
int cursecondrange = (int)(value - curfirstrange * Math.Pow(10, counter));
int rangesmallpix = (int)(cursecondrange * rangepix / Math.Pow(10, counter));
g.FillRectangle(new SolidBrush(colors.GetNextColor(j)), startx,
s.Height - 20 - curfirstrange * rangepix - rangesmallpix, Columnwidth, curfirstrange * rangepix + rangesmallpix);
g.DrawString(value.ToString(), new Font(FontFamily.GenericSerif, 10, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(startx + Columnwidth / 2 - 10,
s.Height - 20 - curfirstrange * rangepix - rangesmallpix - 20));
g.DrawString(ColumnNumber.ToString(), new Font(FontFamily.GenericSerif, 10, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(startx + Columnwidth / 2 - 10,
s.Height - 10));
ColumnNumber++;
j++; if (j > 99) j = 0;
startx += Columnwidth;
}
j = startcolor;
int TopMargin = 20;
foreach (string str in names)
{
string tmp = str;
if (str.Length > 15)
tmp = str.Substring(0, 15);
g.FillRectangle(new SolidBrush(colors.GetNextColor(j)), s.Width - 200, TopMargin, 10, 10); //pucyeM LIBeTHbIe kBagpaTuku
g.DrawString(tmp, new Font(FontFamily.GenericSerif, 12, FontStyle.Italic), Brushes.Black, new PointF(s.Width - 180, TopMargin - 6)); //pucyeM Hagnucu
TopMargin += 20;
j++; if (j > 99) j = 0;
}
return bmp;
}
}
+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;