- 1
print "Match" if 'ab' =~ /^a?(?=b)b/;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−112
print "Match" if 'ab' =~ /^a?(?=b)b/;
Я не один раз находил ошибки в Perl особенно в Perl регулярных выражениях. Некоторые из них уже исправили, но одна остаётся и в версии ActiveState Perl 5.10.
+117
WorksheetRow row = new WorksheetRow();
row.Cells.Add("");
// ispublished
row.Cells.Add(point.IsPublished ? "+" : "");
// id superregion
row.Cells.Add(point.Town.Region.SuperRegion.Id.ToString());
// name superregion
if (cleanupTags)
row.Cells.Add(CleanXMLTags(point.Town.Region.SuperRegion.Name));
else row.Cells.Add(point.Town.Region.SuperRegion.Name);
// id rregion
row.Cells.Add(point.Town.Region.Id.ToString());
// name region
if (cleanupTags)
row.Cells.Add(CleanXMLTags(point.Town.Region.DefaultText.Name));
else row.Cells.Add(point.Town.Region.DefaultText.Name);
...
StringBuilder subwayIDs = new StringBuilder("");
StringBuilder subwayNames = new StringBuilder("");
foreach (Subway subway in point.Subways)
{
subwayIDs.Append(subway.Id).Append(", ");
subwayNames.Append(subway.DisplayName).Append(", ");
}
string sIDs = subwayIDs.ToString();
if (sIDs.Length > 0) sIDs = sIDs.Substring(0, sIDs.Length - 2);
string sNames = subwayNames.ToString();
if (sNames.Length > 0) sNames = sNames.Substring(0, sNames.Length - 2);
Это 10% от метода. Там все в том же духе.
+146
<?xml version="1.0" encoding="utf-8"?>
<website>
<settings>
<logo>21431_logo_image.png</logo>
<slogan>PHOTOGRAPHER’S PORTFOLIO</slogan>
<bottom_sub_menu><![CDATA[<a href="event:switchPage,7,3">HOW TO BUY MY PHOTOS</a>]]></bottom_sub_menu>
<copyright><![CDATA[AXIS PHOTOPORTFOLIO (C) 2008 | <a href="event:switchPage,6">PRIVACY POLICY</a> | <a href="event:switchFullScreen">FULLSCREEN</a> ]]></copyright>
</settings>
<menu>
<item targetPage="0"><![CDATA[<font color="#25808D">about me</font>]]></item>
<item targetPage="1"><![CDATA[nature]]></item>
<item targetPage="2"><![CDATA[people]]></item>
<item targetPage="3"><![CDATA[macro]]></item>
<item targetPage="4"><![CDATA[architectural]]></item>
<item targetPage="5"><![CDATA[contact me]]></item>
</menu>
<sounds>
<sound id="templateBackgroundMusic" url="21431_templateBackgroundMusic.mp3" loops="9999" volume="100" panning="0" skipFrom="23" skipTo="26209"/>
<sound id="topMenuButtonSound" url="21431_topMenuButtonSound."/>
<sound id="pageImageSound" url="21431_pageImageSound.wav"/>
<sound id="galleryZoomInSound" url="21431_galleryZoomInSound.wav"/>
<sound id="galleryZoomOutSound" url="21431_galleryZoomOutSound.wav"/>
<sound id="pagesSwitchingSound" url="21431_pagesSwitchingSound.wav"/>
<sound id="pagesAppearenceSound" url="21431_pagesAppearenceSound.wav"/>
<sound id="pageButtonSound" url="21431_pageImageSound.wav"/>
<sound id="galleryImageSound" url="21431_pageImageSound.wav"/>
</sounds>
найдите в xml ошибку
−108
item1.clear();
item2.clear();
item3.clear();
item4.clear();
item5.clear();
item6.clear();
item7.clear();
item8.clear();
item9.clear();
item10.clear();
...
for each (var item:Object in acData){
switch (item.ageProfileIndex.toString()){
case "1":
item1.itemData = item;
break;
case "2":
item2.itemData = item;
break;
case "3":
item3.itemData = item;
break;
case "4":
item4.itemData = item;
break;
case "5":
item5.itemData = item;
break;
case "6":
item6.itemData = item;
break;
case "7":
item7.itemData = item;
break;
case "8":
item8.itemData = item;
break;
case "9":
item9.itemData = item;
break;
case "10":
item10.itemData = item;
break;
}
}
вот такая вот легко расширяемая система :)
−99
Было (плохо):
<% @collection.each_with_index do |item, counter| -%>
<%= "<div class='group'>" if ((counter)/items_in_block).to_i*items_in_block == (counter) %>
<%= render :partial => 'item', :locals => { :item => item} %>
<%= "</div>" if (counter > 0 and (((counter+1)/items_in_block).to_i*items_in_block == (counter+1)) or ((counter+1) == @collection.size)) %>
<% end -%>
Стало (чуть лучше ;):
<% @collection.in_groups_of(items_in_block).each do |items| %>
<div class="group">
<% items.each do |item| %>
<%= render :partial => 'item', :locals => { :item => item} %>
<% end %>
</div>
<% end %>
Группировка элементов в группы div'ов.
+164
public function __destruct()
{
unset($this);
}
+75
String filler = "";
int tot = text.length();
int til = 18 - (tot/100);
for(int i = 0; i < tot; i++)
{
if(text.charAt(i) == '\n')
{
text = text.substring(0, i) + "<br/>" + text.substring(i+1);
tot += 3; i += 3;
til--;
}
}
Продакшн. Форматирование текста - вставка перевода строки.
+161
if(($n=func_num_args())>1)
{
$args=func_get_args();
if($n===2)
$object=new $type($args[1]);
else if($n===3)
$object=new $type($args[1],$args[2]);
else if($n===4)
$object=new $type($args[1],$args[2],$args[3]);
else
{
unset($args[0]);
$class=new ReflectionClass($type);
// Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
// $object=$class->newInstanceArgs($args);
$object=call_user_func_array(array($class,'newInstance'),$args);
}
}
yii :)
+164
$result = array(
'clips' => $clips,
'block_title' => $title,
'clips_count' => sizeof($clips),
);
$this->view->assign('clips', $result['clips']);
$this->view->assign('block_title', $result['block_title']);
$this->view->assign('clips_count', $result['clips_count']);
Оптимизируя читабельность :)
+135
^(?:[^<>]*<[^<>]+>)+?[ \n\t]*Вопрос №\d+\:[ \n\t]*((?:<[^<>]+>[^<>]*)+?)(?:<table>|<table [^<>]*>)[ \n\t]*(?:<tr>|<tr [^<>]*>)[ \n\t]*(?:<td>|<td [^<>]*>)[^<>]*(?:(?:(?:(?:<div>|<div[ \n\t]*[^<>]*>)|</div>|<div[ \n\t]*?/[ \n\t]*?>)|(?:(?:<p>|<p[ \n\t]*[^<>]*>)|</p>|<p[ \n\t]*?/[ \n\t]*?>)|(?:(?:<font>|<font[ \n\t]*[^<>]*>)|</font>|<font[ \n\t]*?/[ \n\t]*?>)|(?:(?:<html>|<html[ \n\t]*[^<>]*>)|</html>|<html[ \n\t]*?/[ \n\t]*?>)|(?:(?:<body>|<body[ \n\t]*[^<>]*>)|</body>|<body[ \n\t]*?/[ \n\t]*?>)|(?:(?:<head>|<head[ \n\t]*[^<>]*>)|</head>|<head[ \n\t]*?/[ \n\t]*?>)|(?:(?:<span>|<span[ \n\t]*[^<>]*>)|</span>|<span[ \n\t]*?/[ \n\t]*?>)|(?:(?:<style>|<style[ \n\t]*[^<>]*>)|</style>|<style[ \n\t]*?/[ \n\t]*?>)|(?:(?:<title>|<title[ \n\t]*[^<>]*>)|</title>|<title[ \n\t]*?/[ \n\t]*?>)|(?:(?:<br>|<br[ \n\t]*[^<>]*>)|</br>|<br[ \n\t]*?/[ \n\t]*?>)|(?:(?:<img>|<img[ \n\t]*[^<>]*>)|</img>|<img[ \n\t]*?/[ \n\t]*?>)|(?:(?:<meta>|<meta[ \n\t]*[^<>]*>)|</meta>|<meta[ \n\t]*?/[ \n\t]*?>))[^<>]*)*Вариан
Продолжение (8 килобайт, сюда не влазит): http://pastie.org/1750060
Регулярка безусловно генерится, но всё равно ГК.