- 1
$this->view->isAdmin = ($auth->getIdentity()->role_id == 1) ? true : false;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+147.7
$this->view->isAdmin = ($auth->getIdentity()->role_id == 1) ? true : false;
Называется: "заработался".
Написал и только потом дошло.
+157.4
....
$str = str_replace(',', ' ', $this->searchString);
$str = str_replace(';', ' ', $str);
$str = str_replace('.', ' ', $str);
$str = str_replace(':', ' ', $str);
$str = str_replace('+', ' ', $str);
$str = str_replace('-', ' ', $str);
$str = str_replace('"', ' ', $str);
$str = str_replace("'", ' ', $str);
$str = trim(preg_replace('!\s{2,}!', ' ', $str));
.....
вот что я наклал как-то
+154.8
function get_($what)
{
global $parser;
$lang = $parser->lang;
$lang = $this->$lang;
return $lang[$what];
}
+166.8
unset($keys[count($keys)-1][count($keys[count($keys)-1])-1]);
+75.3
public static ru.project.subpackage.PersonDTO convertOshPersonDtoToPersonDto(OshPersonDTO person){
ru.project.subpackage.PersonDTO dto = new ru.project.subpackage.PersonDTO();
dto.setPersonid(person.getPersonid().longValue());
dto.setNamelast(person.getNamelast());
dto.setNamefirst (person.getNamefirst ());
dto.setNamesec (person.getNamesec ());
dto.setInitials (person.getInitials ());
dto.setSex (convertSkVocValue(person.getSex()));
dto.setReason (person.getReason ());
dto.setWorkphone (person.getWorkphone ());
dto.setWorkphonedigit (person.getWorkphonedigit ());
dto.setLocalphone (person.getLocalphone ());
dto.setLocalphonedigit (person.getLocalphonedigit ());
dto.setHomephone (person.getHomephone ());
dto.setHomephonedigit (person.getHomephonedigit ());
dto.setMobilephone (person.getMobilephone ());
dto.setMobilephonedigit (person.getMobilephonedigit ());
dto.setFax (person.getFax ());
dto.setFaxdigit (person.getFaxdigit ());
dto.setPager (person.getPager ());
dto.setEmail (person.getEmail ());
dto.setWeb (person.getWeb ());
dto.setNamelastdative (person.getNamelastdative ());
dto.setNamefirstdative (person.getNamefirstdative ());
dto.setNamesecdative (person.getNamesecdative ());
dto.setNamelastaccusative (person.getNamelastaccusative ());
dto.setNamefirstaccusative (person.getNamefirstaccusative ());
dto.setNamesecaccusative (person.getNamesecaccusative ());
dto.setNamelastgenitive (person.getNamelastgenitive ());
dto.setNamefirstgenitive (person.getNamefirstgenitive ());
dto.setNamesecgenitive (person.getNamesecgenitive ());
dto.setNamelastinstrumental (person.getNamelastinstrumental ());
dto.setNamefirstinstrumental(person.getNamefirstinstrumental());
dto.setNamesecinstrumental (person.getNamesecinstrumental ());
dto.setNamelastprepositional(person.getNamelastprepositional());
dto.setNamefirstprepositional(person.getNamefirstprepositional());
dto.setNamesecprepositional (person.getNamesecprepositional ());
return dto;
}
И так далее еще несколько сотен строк. А главное переупаковка из одних объектов в другие и обратно бессмысленна, т.к. можно использовать исходные (они доступны в приложении)
+127
/// <summary>
/// Retrieve currency rates from an external site to be sure they are up to date.
/// In this case just checking the one currency (Australian Dollar) so no need to dynamically parse the site.
/// </summary>
/// <returns>currency rates or msg indicating an error</returns>
private String getCurrencyRates()
{
string strURL = @"http://www.x-rates.com/d/JPY/table.html";
HttpWebRequest txtRequest = (HttpWebRequest)WebRequest.Create(strURL);
txtRequest.Method = "GET";
txtRequest.ContentType = "application/x-www-form-urlencoded";
string response;
using (StreamReader streamReader = new StreamReader(txtRequest.GetResponse().GetResponseStream()))
{
response = streamReader.ReadToEnd();
if (response.IndexOf("Australian Dollar") > 0)
{
//parse the returned page for the two values of the currency rate based on the existing design
int ind_jpy = (response.IndexOf("/d/AUD/JPY/graph120.html") + 39);
int ind_aud = (response.IndexOf("/d/JPY/AUD/graph120.html") + 39);
String jpy_aud = response.Substring(ind_jpy, (response.IndexOf("</a>",ind_jpy) - ind_jpy) );
String aud_jpy = response.Substring(ind_aud, (response.IndexOf("</a>", ind_aud) - ind_aud));
Session["curr_rate"] = "set";
Session["JPY"] = jpy_aud;
Session["AUD"] = aud_jpy;
return aud_jpy + " / " + jpy_aud;
}
//else present msg to user that unable to obtain currency rates
}
return "";
}
Еще один кандидат
+154.3
There is a little problem with iconv in such using:
$mytext = iconv('windows-1251', 'utf-8', $mytext);
echo $mytext;
This code isn't work correctly. Solution is:
$mytext_utf = iconv('windows-1251', 'utf-8', $mytext);
echo $mytext_utf;
//or just
echo iconv('windows-1251', 'utf-8', $mytext);
ссылка: http://www.php.net/manual/en/function.iconv.php#83511
смотрел ман, наткнулся на вот такой комментарий
Если я еще не ослеп, то чувак одну один и тот же код три раза переписал
и он якобы у него заработал :D
+50.1
...
double total, free;
GetCensoredServer()->GetCensoredMemory(total, free);
if (free<0.) // <-- чудесная проверка
{
MessageBox(AfxGetMainWnd()->m_hWnd, censored("Please check censored for enough memory!")), _T(""), MB_OK|MB_ICONWARNING);
return false;
}
...
Найдено в рабочем коде. Некоторые идентификаторы изменены.
+158.9
Нашел в одном индусском скрипте мега аплоадер хендлер
if($_FILES["attach1e"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach1e"]["name"]);
copy ($_FILES['attach1e']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$_POST[pid].'-attach1e.'.$file_details['extension']);
}
if($_FILES["attach2"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach2"]["name"]);
copy ($_FILES['attach2']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach2.'.$file_details['extension']);
}
if($_FILES["attach3"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach3"]["name"]);
copy ($_FILES['attach3']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach3.'.$file_details['extension']);
}
if($_FILES["attach4"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach4"]["name"]);
copy ($_FILES['attach4']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach4.'.$file_details['extension']);
}
if($_FILES["attach5"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach5"]["name"]);
copy ($_FILES['attach5']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach5.'.$file_details['extension']);
}
if($_FILES["attach6"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach6"]["name"]);
copy ($_FILES['attach6']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach6.'.$file_details['extension']);
}
if($_FILES["attach7"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach7"]["name"]);
copy ($_FILES['attach7']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach7.'.$file_details['extension']);
}
if($_FILES["attach8b"]["name"]){
//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
$file_details=pathinfo($_FILES["attach8b"]["name"]);
copy ($_FILES['attach8b']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$_POST[pid].'-attach8b.'.$file_details['extension']);
}
−866.9
CREATE TABLE [Battles] (
[name] [varchar] (20) NOT NULL ,
[date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [Classes] (
[class] [varchar] (50) NOT NULL ,
[type] [varchar] (2) NOT NULL ,
[country] [varchar] (20) NOT NULL ,
[numGuns] [tinyint] NULL ,
[bore] [real] NULL ,
[displacement] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Ships] (
[name] [varchar] (50) NOT NULL ,
[class] [varchar] (50) NOT NULL ,
[launched] [smallint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Outcomes] (
[ship] [varchar] (50) NOT NULL ,
[battle] [varchar] (20) NOT NULL ,
[result] [varchar] (10) NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Battles] ADD
CONSTRAINT [PK_Battles] PRIMARY KEY CLUSTERED
(
[name]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Classes] ADD
CONSTRAINT [PK_Classes] PRIMARY KEY CLUSTERED
(
[class]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Ships] ADD
CONSTRAINT [PK_Ships] PRIMARY KEY CLUSTERED
(
[name]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Outcomes] ADD
CONSTRAINT [PK_Outcomes] PRIMARY KEY CLUSTERED
(
[ship],
[battle]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Ships] ADD
CONSTRAINT [FK_Ships_Classes] FOREIGN KEY
(
[class]
) REFERENCES [dbo].[Classes] (
[class]
) NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[Outcomes] ADD
CONSTRAINT [FK_Outcomes_Battles] FOREIGN KEY
(
[battle]
) REFERENCES [dbo].[Battles] (
[name]
)
GO
Это с sql-ex.ru , база "корабли"
Может, упражнения там интересные,
но сама база истинный говнокод. Почему?
Строчка
"В отношение Outcomes могут входить корабли, отсутствующие в отношении Ships."
делает её говнокодом.