- 1
- 2
- 3
var a = 4.83 + 2.54 + 4.85 + 4.83;
alert(a);
// выводит 17.049999999999997
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+146
var a = 4.83 + 2.54 + 4.85 + 4.83;
alert(a);
// выводит 17.049999999999997
Что за глюк???
−862
select
PTS.*,
(select client_type_id from clients where client_id = PTS.client_id) as client_type_id,
(select name ||''|| address from ats_list
where id = PTS.ats_id) as ats_name,
(select name ||''|| ip_address from dslam_list
where id = PTS.dslam_id) as dslam_name,
(select label from point_statuses_view
where code = PTS.statuscross) as statuscross,
(select typename from asrtypes
where typename_value = '1' and typename_id = PTS.country_id) as country_name
from points as PTS
where
PTS.point_id = 118749
Ни про LEFT JOIN ни про ORM похоже автор не слышал.
+122
<?php require_once "db_config.php";
class db extends db_config {
private $connection;
function __construct(){
$this->open_connection();
// echo "Соединение установлено ";
}
private function open_connection(){
$this->connection=mysql_connect($this->DB_HOST,$this->DB_USER,$this->DB_PASS);
if (!$this-connection){
die("Соедитение с базой данных не установлено: ".mysql_error());
} else {
$db_select=mysql_select_db($this->DB_NAME);
if (!$db_select){
die("База данных не определена: ".mysql_error());
}
}
mysql_query("set names utf8")or die("set name utf8 failed");
mysql_query("set lc_time_names=ru_RU");
}
public function sql($query){
$result=mysql_query($query,$this->connection);
if (!result){
die("Запрос не выполнен: ".mysql_error());
}
return $result;
}
}
$db = new db();?>
Типа сингелтон
+165
//ip address checking function
//for real use should have a return value but example code
function testipaddress ($nametotest) {
$ipaddress = $nametotest;
$ipaddress = gethostbyname($nametotest);
if ($ipaddress == $nametotest) {
echo "No ip address for host, so host "
. "not currently available in DNS and "
. "probably offline for some time<BR>";
}
else {
echo "good hostname, ipaddress = $ipaddress<BR>";
}
}
Пользовательские комментарии на php.net - это тот ещё кладезь.
http://www.php.net/manual/en/function.gethostbyname.php
+167
<?
function displayData() {
global $chanTitle, $chanLink, $chanDesc, $rss, $items, $itemCount, $imgTitle, $imgLink, $imgUrl;
global $items, $itemCount;
?>
<?
for($i = 0;$i < 1;$i++) {
if(@$items[$i]['link']<>''){
?>
<? echo '<h4>'.codirovkaReader(@$items[$i]['title']).'</h4>'; ?>
<? echo '<h5>'.codirovkaReader(@$items[$i]['pubdate']).'</h5>'; ?>
<? echo codirovkaReader(@$items[$i]['desc']); ?>
<? echo '<br><hr size="1">'; ?>
<?
}
}
?>
<?
}
parseRSS($url);
?>
+146
import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.
*;class T extends JFrame implements Runnable{int C=10,R=20,S=R,i,j,r,l,b;int[][]
M=new int[C][R];T(){setBounds(100,100,C*S,R*S);setDefaultCloseOperation(3);t();
new Thread(this).start();}protected void processKeyEvent(KeyEvent e) {int v=e.
getKeyCode();if(v==37)l=1;if(v==39)r=1;repaint();}void n(){b=0;l=0;for(i=0;i<C;i
++)for(j=0;j<R;j++){if (b>0)break;if(M[i][j]==9){if(i>1){M[i][j]=0;M[i-1][j]=9;}
else b=1;}}}void o(){b=0;r=0;for(i=C-1;i>=0;i--)for(j=0;j<R;j++){if(b>0)break;if
(M[i][j]==9){if(i<C-1){M[i][j]=0;M[i+1][j]=9;}else b=1;}}}public void paint
(Graphics g){super.paint(g);for(i=0;i<C;i++)for(j=0;j<R;j++){int m=M[i][j];if(m
!=0)g.drawRect(i*S,j*S,S,S);}}public static void main(String[]a){new T().
setVisible(true);}public void run(){for(;;){try{Thread.sleep(200);}catch(
Exception e){}if(r>0)o();if(l>0)n();b=0;for(i=C-1;i>=0;i--)for(j=R-1;j>=0;j--){
if (b>0)break;if(M[i][j]==9)if(j<R-1){if(M[i][j+1]==0){if(!isCan()){t();b=1;
break;}M[i][j]=0;M[i][j+1]=9;}else{t();b=1;break;}}else{t();b=1;break;}}repaint(
);}}boolean isCan(){int j,i;for(i=0;i<C;i++)for(j=0;j<R;j++){if(j<R-1&&M[i][j]>8
&&M[i][j+1]==1)return false;}return true;}void t(){int i,j;for(i=C-1;i>=0;i--)
for (j=R-1;j>=0;j--)M[i][j] = M[i][j]!=0?1:0;for(j=0;j<R;j++)for(i=0;i<C;i++){}
Random r=new Random();int s=r.nextInt(3);M[4][0]=9;switch(s){case 0:M[5][0]=9;M[
5][1]=9;break;case 1:M[4][1]=9;M[5][0]=9;M[5][1]=9;break;case 2:M[4][1]=9;M[4][2
]=9;M[4][3]=9;break;}}}
JSwing тетрис : 20 строчек
+146
package t;import java.awt.*;import java.awt.event.*;import javax.swing.*;class M
extends JFrame implements Runnable{int T=100,s,W=500,H=W,x=T,l=10,y,i,S,L;M(){
setBounds(T,T,W,H);new Thread(this).start();}public void paint(Graphics g){super
.paint(g);g.drawOval(x,y,l,l);g.drawRect(i,H-l,T,l);g.drawString("Sco "+s,l,T);}
public void processKeyEvent(KeyEvent e){int k=e.getKeyCode();if(k==37)i-=l;if(k
==39)i+=l;super.processKeyEvent(e);}public static void main(String[]args){new M(
).setVisible(true);}public void run(){while(true){try{Thread.sleep(5);}catch
(Exception e){}x+=S==0?1:-1;y+=L==0?1:-1;if(y>H-l){if(x>i&&x<i+T){s++;}else{S=0;
L=0;x=T;y=0;}}if(x>W-l)S=1;if(x<l)S=0;if(y>H-l)L=1;if(y<l)L=0;repaint();}}}
рабочий JSwing теннис :9 строчек
+138
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctime>
#include <signal.h>
#include <sys/time.h>
#include <fcntl.h>
#include <termios.h>
#include <time.h>
#include <iostream>
using namespace std;
struct termios savetty;
struct termios tty;
char num[]="0123456789QWERTYUIOPASDFGHJKLZXCVBNM";
char let[]="!\",#$%&'()*qwertyuiopasdfghjklzxcvbnm";
int t=1;
int tm=0;
int opnum=0;
char buffer[30];
char var[1000];
char out[1000];
struct timeval tv;
struct timeval tv2;
int main()
{
if ( !isatty(0) ) {
fprintf (stderr, "stdin not terminal\n");
exit (1);
};
tcgetattr (0, &tty);
savetty = tty;
tty.c_lflag &= ~(ICANON|ISIG);
tty.c_cc[VMIN] = 1;
tcsetattr (0, TCSAFLUSH, &tty);
srand(time(0));
int i=0;
bool c=true;
time_t curtime;
int passLen=200+rand()%400;
for(int i=0;i<=passLen;i++){
int s=rand()%2;
if(s==1){
out[i]=let[rand()%37];
} else {
out[i]=num[rand()%35];
};
if((i%5)==0 && i!=0)out[i]=' ';
};
out[passLen]='\0';
int tt=gettimeofday(&tv, NULL);
if(tt<0)exit(0);
printf("%s\n",out);
while(out[i]!='\0')
{
var[i]=getchar();
if(var[i]!=out[i]){
opnum++;
printf("Er%c",out[i]);
};
i++;
};
tt=gettimeofday(&tv2, NULL);
if(tt<0)exit(0);
int tm=tv2.tv_sec-tv.tv_sec;
int v=(passLen*60)/tm;
int min=tm/60;
tm%=60;
printf("Time %d min %d sec\n",min,tm);
cout<<"Num of errors "<<opnum<<" Speed "<<v<<endl;
tcsetattr (0, TCSAFLUSH, &savetty);
};
Клавиатурный тренажер
−182
- application = webapp.WSGIApplication(foo)
+ if 0==1:
+ application = webapp.WSGIApplication(foo)
+ application = webapp.WSGIApplication(bar)
пакистанский юноша знает толк в комментариях.
−91
if ((m_window.popupBox_mc.popupBox_tf.text == "Пожалуйста обратитесь в службу поддержки и опишите действия после которых возникла ошибка. Затем обновите страницу.")||(m_window.popupBox_mc.popupBox_tf.text == "Ошибка ресурсов сервера. Пожалуйста обратитесь в службу поддержки и опишите действия после которых возникла ошибка. Затем обновите страницу.")||(m_window.popupBox_mc.popupBox_tf.text == "Ты запустил игру в двух браузерах или окнах одновременно. Закрой одно из окон и обнови страницу!")||(m_window.popupBox_mc.popupBox_tf.text == GlobalEngine.quickLocalize("FarmGame", "ServerError"))||(m_window.popupBox_mc.popupBox_tf.text == GlobalEngine.quickLocalize("FarmGame", "RefreshGame")))
{
m_window.popupBox_mc.accept_bt.visible = false;
}