- 1
$news = new news($_GET["news"]);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+146
$news = new news($_GET["news"]);
Обьект класса news. Выводит нужную новость в соответствии с get запросом.
+162
// юзер просит :
// "Дату выводит как записано в базе к примеру 2010-10-26 15:17:01. А мне нужно вывести Только 15:17. Как так сделать не меняя записи в базе?"
$infochat=SQLrow("select datesend, id_user, message from minichat order by datesend desc limit 0,1");
// и варианты
$exp=explode(" ", $date);
$exp=explode(":", $exp);
echo $exp[0].':'.$exp[1];
//.........
$exp=substr("$date", 11, 3);
echo $exp;
// :D
С одного форума
+157
protected function _defineUser()
{
if ($this->_getParam('controller') == 'profile')
{
// check for mb and sf
if ($this->_getParam('action') == 'mb')
{
$user = new Dbrow_User();
$this->userId = $user->getIdByMbId($this->currentId);
}
if ($this->_getParam('action') == 'sf')
{
$user = new Dbrow_User();
$this->userId = $user->getIdBySfId($this->currentId);
}
}
if ($this->userId <= 0)
{
$this->userId = (int)$this->_getParam('userId');
}
if ($this->userId <= 0)
{
$this->userId = (int)$this->currentId;
}
if ($this->userId <= 0 && Static_Auth::isLogged())
{
$this->user = Static_Auth::getUser();
$this->userId = $this->user->id;
}
else
{
$this->user = new Dbrow_User();
$this->user->loadById($this->userId, array());
}
$this->view->user = $this->user;
self::$curUser = $this->user;
//var_dump($this->user->parentEssences);
//exit;
}
just piece of shit
+144
int X,Y,Z;
X=StrToInt(Edit1->Text);
Y=StrToInt(Edit2->Text);
Z=X+Y;
Edit3->Text=IntToStr(Z),
−120
print qq(<div id="Layer26" class="blank" style="left:170mm; top:96mm; width:95mm;">$base1[17]);
Верстаем в миллиметрах, используем магические числа и т.п.
+125
<?
# запускаем сессии
session_start();
# подключаем MySQL
require "db.php";
// Если существуют куки, то выполняем автовход!
if(isset($_COOKIE['adminauto']))
{$nik = $_COOKIE['adminnik'];
$password = $_COOKIE['adminpassword'];
$_SESSION['adminnik'] = $nik;
$_SESSION['adminpassword'] = crc32(crypt(base64_encode(strrev(md5($password)))));
}// Если переменные пустые, то запрещаем вход
....... Тут какое то говнишко
# если пользователь ввел данные, то проверяем их
if(isset($go))
{
# принимаем данные через POST
if (isset($_POST['nik'])) {$nik = $_POST['nik'];}
if (isset($_POST['pass'])) {$pass = $_POST['pass'];}
# проверяем нет ли пустых полей
if(empty($nik) or empty($pass))
{exit("<script language='javascript'>alert('Вы попытались получить доступ к Чату, но замечено, что Вы не ввели какое-то из полей, пожалуйста заполните их!');</script><head><meta http-equiv='refresh' content='0; URL=admin.php'></head>");}
$result = mysql_query("SELECT nik,password FROM admin WHERE nik='$nik' and password='$pass'");
if(mysql_num_rows($result) > 0)
{
$_SESSION['adminnik'] = $nik;
$_SESSION['adminpassword'] = crc32(crypt(base64_encode(strrev(md5($pass)))));}
else {exit("<script language='javascript'>alert('Вы попытались получить доступ к Чату, но те данные которые Вы ввели, не совподают с правильными! Пожалуйста введите правильные!');</script><head><meta http-equiv='refresh' content='0; URL=admin.php'></head>");}}
if( !isset($_SESSION['adminnik']) or !isset($_SESSION['adminpassword']) ) {
echo "<br><br><br><br><br><br><br>
<table bgcolor='#EAF3FF' width='300px' align='center' style='border:1px solid #000000; padding:10px;'>
<tr><td><strong>Вход</strong></td></tr><br>
<form method='post'><tr bgcolor='#F9F8FD'><td>
<div style='font-size:11px; font-family:Verdana; color:#424242;'>Ваш ник:</div></td><td>
<input style='border:1px solid #B3B9C3; font-size:12px;' type='text' name='nik'></td></tr>
<tr bgcolor='#F9F8FD'><td>
<div style='font-size:11px; font-family:Verdana; color:#424242;'>Ваш пароль:</div></td><td>
<input style='border:1px solid #B3B9C3; font-size:12px;' type='password' name='pass'></td></tr><tr><td>
<input type='checkbox' name='auto' cheked> Автовход<br>
<input style='border:1px solid #000000; color:#3A4F6C; font-weight:700; padding:0px; background-color:#F0F5FA; margin-top:5px;' type='submit' name='go' value='Войти'></form>
</td>
</tr>
</table>
<br><table bgcolor='#EAF3FF' width='500px' align='center' style='border:1px solid #000000; padding:10px;'><tr align='center'><td><strong style='font-size:14px;'>Забыли пароль?</strong></td></tr><form method='post' action='newpass.php'><tr align='center'><td bgcolor='#F9F8FD' style='padding-bottom:7px;'><strong style='font-size:11px; font-family:Verdana;'>Введите Ваш email: </strong><input type='text' name='email' style='border:1px solid #B3B9C3; font-size:11px; font-family:Verdana; padding:1px; margin-top:5px;'> <input type='submit' style='border:1px solid #000000; color:#3A4F6C; font-weight:700; padding:0px; background-color:#F0F5FA; margin-top:5px;' name='newpass' value='Получить пароль!'></form></td></tr><tr><td align='center' style='font-size:11px; font-family:Verdana; color:#FF0000;'>* Вам на email будет выслан новый пароль!</td></tr></table>
";
exit();
}
?>
Вот. это называется авто вход.
+144
public void onMessage(final NetConnection connection, final NetMessage message) {
final ClientConnection client = (ClientConnection) connection;
if (message.isCommand(Protocol.CMD_LOGIN)) {
if (this.auth(client,
message.getParameter(Protocol.PARAM_NAME, String.class))) {
final NetMutableMessage msgLogin = new NetMutableMessage(
Protocol.CMD_LOGIN);
msgLogin.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(client, null, msgLogin);
} else {
this.removeConnection(client);
}
}
if (message.isCommand(Protocol.CMD_LOGOUT)) {
final NetMutableMessage msgLogout = new NetMutableMessage(
Protocol.CMD_LOGOUT);
msgLogout.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(client, null, msgLogout);
this.removeConnection(client);
}
if (message.isCommand(Protocol.CMD_STATUS)) {
final NetMutableMessage msgStatus = new NetMutableMessage(
Protocol.CMD_STATUS);
msgStatus.addParameter(Protocol.PARAM_TYPE,
message.getParameter(Protocol.PARAM_TYPE));
msgStatus.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(client, null, message);
this.removeConnection(client);
}
if (message.isCommand(Protocol.CMD_USERS)) {
final NetMutableMessage msgUsers = new NetMutableMessage(
Protocol.CMD_USERS);
msgUsers.addParameter("list", this.getUsers(connection));
this.writeMessage(client, msgUsers, null);
}
if (message.isCommand(Protocol.CMD_SAY)) {
final NetMutableMessage msgSay = new NetMutableMessage(Protocol.CMD_SAY);
msgSay.addParameter(Protocol.PARAM_FROM, client.getNick());
msgSay.addParameter(Protocol.PARAM_MESSAGE,
message.getParameter(Protocol.PARAM_MESSAGE));
if (null == message.getParameter(Protocol.PARAM_TO)) {
this.writeMessage(client, msgSay, msgSay);
} else {
this.writeMessage(
message.getParameter(Protocol.PARAM_TO, String.class), msgSay, null);
}
}
if (message.isCommand(Protocol.CMD_MOVE)) {
final NetMutableMessage msgMove = new NetMutableMessage(Protocol.CMD_MOVE);
msgMove.addParameter(Protocol.PARAM_FROM, client.getNick());
msgMove.addParameter(Protocol.PARAM_CODE,
message.getParameter(Protocol.PARAM_CODE));
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgMove, null);
}
if (message.isCommand(Protocol.CMD_OFFER)) {
final NetMutableMessage msgOffer = new NetMutableMessage(
Protocol.CMD_OFFER);
msgOffer.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgOffer, null);
}
if (message.isCommand(Protocol.CMD_ACCEPT)) {
final NetMutableMessage msgAccept = new NetMutableMessage(
Protocol.CMD_ACCEPT);
msgAccept.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgAccept, null);
}
if (message.isCommand(Protocol.CMD_DECLINE)) {
final NetMutableMessage msgDecline = new NetMutableMessage(
Protocol.CMD_DECLINE);
msgDecline.addParameter(Protocol.PARAM_FROM, client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
msgDecline, null);
}
if (message.isCommand(Protocol.CMD_END)) {
final NetMutableMessage msgEnd = new NetMutableMessage(Protocol.CMD_END);
msgEnd.addParameter("player1",
message.getParameter(Protocol.PARAM_TO, String.class));
msgEnd.addParameter("player2", client.getNick());
this.writeMessage(message.getParameter(Protocol.PARAM_TO, String.class),
null, msgEnd);
}
}
нагкодил свежачок, прямиком из IDE Eclipse :)
разрабатываю сетевую мини-игрушку с чатом. Данный метод -- из серверной части, где сервер принимает приходящие сообщения и реагирует на них.
Обьем метода и однородность кусков намекает, что это пора рефакторить - вот думаю как.
+77
public void actionPerformed(ActionEvent e) {
System.out.println("Przed utworzeniem resultseta");
Statement stm=null;
try{stm = Aplikacja.dajPolaczenieDB().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);}
catch (SQLException ex){System.out.println("Wystąpił błąd przy próbie utworzemia Statement: "+ex.getLocalizedMessage());}
String z_sql = "SELECT id,imie FROM crm_sl_imion";
ResultSet rs=null;
try{rs = stm.executeQuery(z_sql);}
catch(SQLException e1){System.out.println("Wystąpił błąd przy próbie utworzeniu ResultSet'a: "+e1.getLocalizedMessage());}
try{
System.out.println("Rozpoczynam transakcje");
Aplikacja.dajPolaczenieDB().setAutoCommit(false);
}catch(SQLException e1){
System.out.println("Wystąpił błąd przy probie rozpoczęcia transkacji");
}
String z_insert="insert into crm_sl_imion(imie) values('Zdzisek')";
Statement stm2=null;
try{
stm2 = Aplikacja.dajPolaczenieDB().createStatement();
}catch(SQLException e1){
System.out.println("Wystąpił błąd przy próbie utowrzenia drugiego Stadementa: "+e1.getLocalizedMessage());
}
try{
stm2.execute(z_insert);
}catch(SQLException e1){
System.out.println("Wystąpił błąd przy próbie wykonywania sql'a: "+z_insert+", błąd: "+e1.getLocalizedMessage());
}
try{
System.out.println("Odwijam transakcje");
Aplikacja.dajPolaczenieDB().commit();
Aplikacja.dajPolaczenieDB().setAutoCommit(true);
}catch(SQLException e1){
System.out.println("Wystąpił błąd przy odwijaniu transakcji");
}
try{
while(rs.next()){
System.out.println("id: "+rs.getString("id")+" imie: "+rs.getString("imie"));
}
}catch(SQLException e2){
System.out.println("Wystąpił błąd przy próbie odczytania danych: "+e2.getLocalizedMessage());
}
try{
stm.close();
System.out.println("Po zamknięciu Statement'a");
}catch(SQLException e1){
System.out.println("Wystąpił błąd przy próbie zamknięcia Statement'a");
}
}
+144
// Devide vector
Tuple<Complex[], Complex[]> DevideVector(Complex[] vector){
Complex[] firstPart = new Complex[vector.Length / 2],
secondPart = new Complex[vector.Length / 2];
for (int index = 0; index < firstPart.Length; index++) { firstPart[index] = vector[index]; }
for (int index = 0, offset = firstPart.Length; index < secondPart.Length; index++) { secondPart[index] = vector[index + offset]; }
return new Tuple<Complex[], Complex[]>(firstPart, secondPart);}
// FFT
public Complex[] Transform(Complex[] vector){
inverse = false;
Complex[] result = Operation(vector);
result = InverceIndexBits(result);
for (int index = 0; index < vector.Length; index++) { result[index] /= result.Length; }
return result;}
// IFFT
public Complex[] InverseTransform(Complex[] vector){
inverse = true;
Complex[] result = Operation(vector);
result = InverceIndexBits(result);
return result;}
}}
Код из лабы моего одногруппника. Яркий пример того, как НЕ НАДО оформлять код
+151
$g_source= SF(qGet("source")); // $_GET['source'] со всякой фильтрацией
if ($g_source=="") { $g_source=''; }