- 1
- 2
echo $search;
$result = mysql_query ("SELECT id,title,description,date,author,view,mini_img FROM data WHERE MATCH(text) AGAINST('".$search."')");
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+142
echo $search;
$result = mysql_query ("SELECT id,title,description,date,author,view,mini_img FROM data WHERE MATCH(text) AGAINST('".$search."')");
+48
while( !InputFileStream.atEnd() )
{
QString Qstrtmp;
InputFileStream >> Qstrtmp;
ReadButton.bTag = QString(QObject::tr( (Qstrtmp.toStdString()).c_str() ));
InputFileStream >> Qstrtmp;
ReadButton.iTag = QString(QObject::tr( (Qstrtmp.toStdString()).c_str() ));
InputFileStream >> Qstrtmp;
ReadButton.Popup = QString(QObject::tr( (Qstrtmp.toStdString()).c_str() ));
ReadButton.PartitionId = *iVar;
this->Buttons.push_back( ReadButton );
}
Код взят из совместного проекта 5-ти студентов.
Это был начальный период нашего изучения Qt.
+70.9
import javax.microedition.lcdui.*;
import java.lang.*;
import java.io.*;
public class LNRES
{
public InputStream is=null;
public String lines[]=null;
LNRES(String name,int size)
{
int x=0;
is=getClass().getResourceAsStream(name);
byte mb[]=new byte[size];
try { x=is.read(mb); } catch (Exception ex) { }
char mc[]=new char[x];
for (int i=0; i<x; i++) mc[i]=(char)mb[i];
int n=0,a=0,l=0;
String mas2[]=null;
for (int i=0; i<mc.length; i++) {
if ((mb[i]==13)||(i==mc.length-1)) {
mas2=new String[n+1];
for (int j=0; j<n; j++) mas2[j]=new String(lines[j]);
mas2[n]=new String(mc,a,l+((i==mc.length-1)?1:0)); n++; lines=new String[n];
for (int k=0; k<n; k++) lines[k]=new String(mas2[k]);
a=i+2; l=0; i++;
} else l++;
}
lines=new String[n];
for (int i=0; i<n; i++) lines[i]=new String(mas2[i]);
}
}
Писалось под j2me. Класс считывает весь файл и превращает его в массив строк.
−95.4
@ids.each_index do |di|
if @ids[di] then
@ids[di].each_index do |li|
@employ[di][li] = Hash.new
@employ[di][li][:subject] = Subject.find(:first, :conditions => "id = #{
Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:subject_id]
}")[:title] if @ids[di][li]
@employ[di][li][:class] = SchoolClass.find(:first, :conditions => "id = #{
Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:school_class_id]
}")[:number].to_s +
SchoolClass.find(:first, :conditions => "id = #{
Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:school_class_id]
}")[:letter] if @ids[di][li]
@employ[di][li][:teacher] = Teacher.find(:first, :conditions => "id = #{
Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:teacher_id]
}")[:name] + ' ' +
@employ[di][li][:teacher] = Teacher.find(:first, :conditions => "id = #{
Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:teacher_id]
}")[:surname] + ' ' +
@employ[di][li][:teacher] = Teacher.find(:first, :conditions => "id = #{
Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:teacher_id]
}")[:patronymic] if @ids[di][li]
end
end
end
Небольшая утренняя ревизия кода раскрыла заговор по свержению власти и захвату мозга остальных кодеров проекта.
Сидим, рефакторим.
+62.7
class UglyColumnsRedefine < ActiveRecord::Migration
def self.up
change_column :variable_sets, :active, :boolean
VariableSet.all.each{|v| v.update_attribute :active, !!v.active}
end
def self.down
end
end
Миграция с весёлым названием 20090601130619_ugly_columns_redefine.rb, для рельсового приложения, аля "так делать низя".
−105.1
def init_images():
rect = [[0,0],[0,0],[0,0],[0,0],[0,0]]
image = [[0,0],[0,0],[0,0],[0,0],[0,0]]
rect[0][0], image[0][0]=load_image('box.png')
rect[0][1], image[0][1]=load_image('box.png')
rect[1][0], image[1][0]=load_image('fpoint.png')
rect[1][1], image[1][1]=load_image('freefpoint.png')
rect[2][0], image[2][0]=load_image('spoint.png')
rect[2][1], image[2][1]=load_image('freespoint.png')
rect[3][0], image[3][0]=load_image('fbox.png')
rect[3][0], image[3][0]=load_image('fbox.png')
rect[4][0], image[4][0]=load_image('sbox.png')
rect[4][1], image[4][1]=load_image('sbox.png')
return image, rect
Процедура загрузки изображений. Т.к. программа писалась через силу (мозги не работали), получались вот такие жуткие куски кода...
+158.8
function h_circle_1_view() {
document.getElementById("circle_1").style.display = "block";
document.getElementById("circle_2").style.display = "none";
document.getElementById("circle_3").style.display = "none";
document.getElementById("circle_4").style.display = "none";
document.getElementById("circle_5").style.display = "none";
}
function h_circle_1_none() {
document.getElementById("circle_1").style.display = "none";
}
function h_circle_2_view() {
document.getElementById("circle_1").style.display = "none";
document.getElementById("circle_2").style.display = "block";
document.getElementById("circle_3").style.display = "none";
document.getElementById("circle_4").style.display = "none";
document.getElementById("circle_5").style.display = "none";
}
function h_circle_2_none() {
document.getElementById("circle_2").style.display = "none";
}
function h_circle_3_view() {
document.getElementById("circle_1").style.display = "none";
document.getElementById("circle_2").style.display = "none"; // прячем 1, 2
document.getElementById("circle_3").style.display = "block"; // показываем 3
document.getElementById("circle_4").style.display = "none";
document.getElementById("circle_5").style.display = "none";
}
function h_circle_3_none() {
document.getElementById("circle_3").style.display = "none";
}
function h_circle_4_view() {
document.getElementById("circle_1").style.display = "none";
document.getElementById("circle_2").style.display = "none";
document.getElementById("circle_3").style.display = "none"; // прячем 1, 2
document.getElementById("circle_4").style.display = "block"; // показываем 3
document.getElementById("circle_5").style.display = "none";
}
function h_circle_4_none() {
document.getElementById("circle_4").style.display = "none";
}
function h_circle_5_view() {
document.getElementById("circle_1").style.display = "none";
document.getElementById("circle_2").style.display = "none";
document.getElementById("circle_3").style.display = "none"; // прячем 1, 2
document.getElementById("circle_4").style.display = "none"; // показываем 3
document.getElementById("circle_5").style.display = "block";
}
function h_circle_5_none() {
document.getElementById("circle_5").style.display = "none";
}
Натолкнулся вот при тестировании одного проекта
+153
while(true) // Последующие недели.
{
for($i = 0; $i < 7; $i++)
{
if($this->date_count > $this->all_days)
break;
else
{
$this->calendar_table[$this->week_counter][$i] = $this->date_count;
$this->date_count++;
}
}
if($this->date_count > $this->all_days)
break;
$this->week_counter++;
}
Заполнение массива с датами для календаря после первой недели...
+156
class DbSimple_Generic_Database extends DbSimple_Generic_LastError
{
...
/**
* Virtual protected methods
*/
function ____________PROTECTED() {} // for phpEclipse outline
...
}
ой какая красотень у нас будет в аутлайне теперь...
+130
public static LanguageConfiguration GetLanguageByUrl()
{
string requestHost = HttpContext.Current.Request.Url.Host.ToLower();
foreach (LanguageConfiguration language in languages.Values)
foreach (DomainConfiguration domain in language.Domains)
if (domain.Name.Equals(requestHost))
return language;
return languages[LanguageCodes[0]];
}
public static List<string> LanguageCodes
{
get
{
//caching languages
if (languages == null)
{
languages = new Dictionary<string, LanguageConfiguration>();
if (languagesConfiguration.Languages.Count > 0)
foreach (LanguageConfiguration language in languagesConfiguration.Languages)
languages.Add(language.Code, language);
else
languages.Add(String.Empty, new LanguageConfiguration());
}
return new List<string>(languages.Keys);
}
}
"Сначала отрежь, потом отмерь".