- 1
- 2
- 3
- 4
- 5
- 6
void some_func(ptrdiff_t value)
{
register double cos_v=cos(static_cast<double>(value));
ptrdiff_t pt=static_cast<ptrdiff_t>(cos_v);
{... working with pt ...}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+169
void some_func(ptrdiff_t value)
{
register double cos_v=cos(static_cast<double>(value));
ptrdiff_t pt=static_cast<ptrdiff_t>(cos_v);
{... working with pt ...}
}
Более того есть функция матричного умножения, элементами этих матриц являются ptrdiff_t'ы (там уже нет перевода в double при вычислениях).
Мне одному кажется что автор наркоман?
+163
$firstName = $_POST['firstname'];
$secondName=$_POST['secondname'];
$email = $_POST['email'];
$query="insert into sportsmans values('$secondName','$firstName','$email',null)";
$conn = mysql_connect('localhost','root','VCh3005');
mysql_select_db('Competition');
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
mysql_query($query);
mysql_error();
mysql_close();
Классика...
−179
#count pages
my $counter; my $pagescount = 0; my $pagesstr;
for (my $i = 0; $i <= $count; $i++)
{
if ($counter == POSTS_PER_PAGE)
{
my $a,$b; if ($pagescount == $pagenum) { $a = "["; $b = "]"; } else { $a = ""; $b = ""; }
$pagesstr = $pagesstr."$a<a href=\"wakaba.pl?task=mpanel&admin=$admin&page=$pagescount\">".($pagescount +1)."</a>$b" if ($pagescount == 0);
$pagesstr = $pagesstr.", $a<a href=\"wakaba.pl?task=mpanel&admin=$admin&page=$pagescount\">".($pagescount +1)."</a>$b" if ($pagescount != 0);
$pagescount++; $counter = 0;
} else { $counter++; }
}
Вот такой веселый код пишут программисты дватиреча и на этом этот самый имиджборд и работает.
+126
<div id="scroller">
<a href="javascript:scroll(0,0)">Наверх</a>
</div>
<style type="text/css">
#scroller {
position:fixed;
left:0px;
top:100%;}
#scroller a {
position:relative;
top:-47px;
padding:5000px 10px 30px 10px;}
#scroller a:hover {background:#d8e3f0;}
</style>
Скролл страницы наверх, прикреплённый к левой границе экрана. Надпись "Наверх" -- внизу экрана. Опускаю блок под экран -- "top:100%", а потом поднимаю ссылочку наверх -- "top:-47px".
+92
protected IOException copyRange(InputStream istream, ServletOutputStream ostream) {
// Copy the input stream to the output stream
IOException exception = null;
byte buffer[] = new byte[input];
int len = buffer.length;
while (true) {
try {
len = istream.read(buffer);
if (len == -1) {
break;
}
ostream.write(buffer, 0, len);
} catch (IOException e) {
exception = e;
len = -1;
break;
}
}
return exception;
}
Си-стайл в исходниках Tomcat. Зачем кидать исключения, если их можно возвращать вместо кода ошибки?
+240
db $8F, $AE, $A7, $A4, $E0, $A0, $A2, $AB, $EF, $EE, $20, $E3, $EE, $E2, $AD, $A5
db $AD, $EC, $AA, $A8, $A9, $20, $A3, $AE, $A2, $AD, $AE, $AA, $AE, $A4, $A8, $AA
db $20, $E1, $20, $A4, $AD, $F1, $AC, $20, $E1, $A8, $E1, $E2, $A5, $AC, $AD, $AE
db $A3, $AE, $20, $A0, $A4, $AC, $A8, $AD, $A8, $E1, $E2, $E0, $A0, $E2, $AE, $E0
db $A0, $21
+147
public class Matrix {
private float matrix[][];
private int dim;
public Matrix(int dim) {
this.dim = dim;
this.matrix = new float[dim][dim];
}
public void productOfTwo(Matrix src, Matrix dest) {
if (src.dim == this.dim) {
dest.dim = this.dim;
Matrix[] temp = new Matrix[this.dim];
for (int i = 0; i < this.dim; i++) {
temp[i] = new Matrix(this.dim);
}
for (int i = 0; i < this.dim; i++) {
for (int j = 0; j < this.dim; j++) {
for (int k = 0; k < this.dim; k++) {
temp[k].matrix[i][j] = this.matrix[i][k] * src.matrix[k][j];
}
}
}
for (int i = 0; i < this.dim; i++) {
dest.sum(temp[i]);
}
} else {
System.out.println(" An error occured: Dimensions of matrices do not match");
}
}
public float findDet() {
if (this.dim == 1) {
return this.matrix[0][0];
} else if (this.dim == 2) {
return this.matrix[0][0] * this.matrix[1][1] - this.matrix[0][1] * this.matrix[1][0];
} else {
float result = 0;
Matrix minor = new Matrix(this.dim - 1);
for (int i = 0; i < this.dim; i++) {
for (int j = 1; j < this.dim; j++) {
System.arraycopy(this.matrix[j], 0, minor.matrix[j - 1], 0, i);
System.arraycopy(this.matrix[j], i + 1, minor.matrix[j - 1], i, this.dim - (i + 1));
}
result += Math.pow(-1, i) * this.matrix[0][i] * minor.findDet();
}
return result;
}
}
Всем доброго времени суток! Прошу к Вашему вниманию алгоритм нахождения произведения двух матриц(умножаем слева направо) и нахождения детерминанта разложением по столбцу(рекурсия). Прошу оценить, по всей строгости.
Заранее спасибо!
+149
function footer_menu()
{
global $tbl_lng;
$result_str = '';
$first = true;
$sql = mysql_query('SELECT section_id, section_name, section_level, section_url FROM '.$tbl_lng.' WHERE section_level = 1 ORDER BY section_order')
or die("Invalid query: " . mysql_error());
while($row = mysql_fetch_array($sql))
{
if ($row['section_url'] != '')
{
if ($first)
{
$first = false;
$result_str = $result_str.'<a class="header_menu2_txt" href="' . $row["section_url"] . '">' . $row["section_name"] . '</a>';
}
else
{
$result_str = $result_str.'<img src="images/footer_s.png" width="26" height="20" alt="" /><a class="header_menu2_txt" href="' . $row["section_url"] . '">' . $row["section_name"] . '</a>';
}
}
else
{
if ($first)
{
$first = false;
$result_str = $result_str.'<a class="header_menu2_txt" href="index.php?section_id=' . $row["section_id"] . '">' . $row["section_name"] . '</a>';
}
else
{
$result_str = $result_str.'<img src="images/footer_s.png" width="26" height="20" alt="" /><a class="header_menu2_txt" href="index.php?section_id=' . $row["section_id"] . '">' . $row["section_name"] . '</a>';
}
}
}
mysql_free_result($sql);
return $result_str;
}
Реализация нижнего меню.
+157
function parse_req($value)
{
global $log_conf;
if(!is_array($value))
{
if(preg_match("#UNION|OUTFILE|SELECT|ALTER|INSERT|DROP|TRUNCATE#i", base64_decode($value)))
{
if($log_conf['queryError'] == 1) writeInLog('Попытка произвести SQL-Inj текст: '.$value, 'sql');
//fatal_error(_ERROR, _UNKNOWN_ERROR);
die();
}
}
else
{
foreach($value as $val)
{
parse_req($val);
}
}
}
Баян конечно, но всегда удивляюсь на что они рассчитывают?
Как-бы борится с SQL-Injection...
+168
function randlogo(){
arr=new Array('<img src="http://site.com/logo-pomegranate.png" border="0" width="677" height="345">','<img src="http://site.com/logo-leaves.png" border="0" width="677" height="345">','<img src="http://site.com/logo-lime.png" border="0" width="677" height="345">','<img src="http://site.com/logo-coffee.png" border="0" width="677" height="345">','<img src="http://site.com/logo-lime.png" border="0" width="677" height="345">','<img src="http://site.com/logo-peach.png" border="0" width="677" height="345">','<img src="http://site.com/logo-lemon.png" border="0" width="677" height="345">','<img src="http://site.com/logo-leaf.png" border="0" width="677" height="345">','<img src="http://site.com/logo-apples.png" border="0" width="677" height="345">','<img src="http://site.com/logo-grapes.png" border="0" width="677" height="345">','<img src="http://site.com/logo-autumn.png" border="0" width="677" height="345">','<img src="http://site.com/logo-strawberry.png" border="0" width="677" height="345">')
rand=Math.floor(Math.random()*arr.length)
document.getElementById('randlogo').innerHTML=arr[rand]
}
randlogo()
Код для генерации случайного логотипа.