- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
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
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+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);
}
}
"Сначала отрежь, потом отмерь".
+50
int i, j;
for (i = j = 0; i < 4; i++)
if (frame & (0x8 >> i))
{
if (i < 2 && p.value < double(frames1[j]) && !(i && j) ||
i > 1 && p.value > double(frames1[j]))
p.value.attr = 1 + i;
j++;
}
Как вам цикл до 4 с тремя проверками на значение счётчика? :)
+161
$id_country = 0;
$id_region = 0;
$id_city = 0;
$zip_code = 0;
if(isset($_REQUEST["id_country"]))
{
$id_country=$_REQUEST["id_country"];
}
if(isset($_REQUEST["id_region"]))
{
$id_region=$_REQUEST["id_region"];
}
if(isset($_REQUEST["id_city"]))
{
$id_city=$_REQUEST["id_city"];
}
if(isset($_REQUEST["zip_code"]))//проверка zip кода
{
$zip_code=$_REQUEST["zip_code"];
}
$id_country=strip_tags(trim(strval($_REQUEST["id_country"])));
$id_region=strip_tags(trim(strval($_REQUEST["id_region"])));
$id_city=strip_tags(trim(strval($_REQUEST["id_city"])));
$zip_code=strip_tags(trim(strval($_REQUEST["zip_code"])));
..........................
//переходим на Шаг 2 решистрации
header("location: ./registration.php?sel=2");
..........................
Индусы среди нас!
+150.9
//$arr - array with arbitrary keys
end($arr);
do {
if( <some condition> ) {
<something of no importance>
unset($arr[key($arr)]);
}
else {
<something of no importance>
}
} while( prev($arr) !== false );
Предполагалось, что на входе будет непустой массив. Потом он будет пролистан с конца (это необходимо) и из него по некоторому условию исключаются элементы. При этом после первого исключения итератор оказывается вне массива и prev() возвращает false (в самом массиве false не размещён заведомо).
+47.9
IsSimpleAssign = ( !isIfWhileForReturn&&
( _currString->ecoString )->IsAtOncePresent( equalsSign )&&
( _currString->ecoString )->IsAtOncePresent( star ) &&
( _currString->ecoString )->IsAtOncePresent( amper ) &&
( ( ( _currString->ecoString )->GetCharPos( amper ) <
( _currString->ecoString )->GetCharPos( star ) ) ||
( ( _currString->ecoString )->GetCharPos( amper ) >
( _currString->ecoString )->GetCharPos( star ) ) ) &&
( ( ( _currString->ecoString )->GetCharPos( equalsSign ) <
( _currString->ecoString )->GetCharPos( star ) ) &&
( ( _currString->ecoString )->GetCharPos( amper ) <
( _currString->ecoString )->GetCharPos( equalsSign ) )
||
( ( _currString->ecoString )->GetCharPos( equalsSign ) >
( _currString->ecoString )->GetCharPos( star ) ) &&
( ( _currString->ecoString )->GetCharPos( amper ) >
( _currString->ecoString )->GetCharPos( equalsSign ) ) )
);
где-то в недрах рукописного парсера