- 1
z = (lines[i].Substring(n.Length + 2, lines[i].Length - (n.Length + 2))).Substring(0, (lines[i].Substring(n.Length + 2, lines[i].Length - (n.Length + 2))).IndexOf("/"));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+966
z = (lines[i].Substring(n.Length + 2, lines[i].Length - (n.Length + 2))).Substring(0, (lines[i].Substring(n.Length + 2, lines[i].Length - (n.Length + 2))).IndexOf("/"));
Забавный способ вырезания домена из ссылки вида: http://www.govnokod.ru/....
+165
function f_includes(&$text){
//REPLACE FILE INCLUDES LINKS
$regex = '/{(ФАЙЛ=)\s*(.*?)}/i';
$matches = array();
preg_match_all( $regex, $text, $matches, PREG_SET_ORDER );
foreach ($matches as $elm) {
$elm[0] = str_replace('{', '', $elm[0]);
$elm[0] = str_replace('}', '', $elm[0]);
parse_str( $elm[0], $args );
$file=@$args['ФАЙЛ'];
if ($file){
$output = getLink($file);
} else { $output = ''; }
$text = str_replace('{ФАЙЛ='.$file.'}', $output, $text );
}
return true;
}
Что за п##дец. InstantCMS.
+113
//чОткая функция которая возвращает количество отображаемых узлов
//в дереве без скролла
int GetcountVisibleNodesInList()
{
int res = 0;
if (FormGUI.c_MainWorkSpaseTree.Nodes.Count == 0)
{
this.FormGUI.c_MainWorkSpaseTree.Nodes.Add(new TreeNode());
res = this.FormGUI.c_MainWorkSpaseTree.Height / FormGUI.c_MainWorkSpaseTree.getNodeRectangle(this.FormGUI.c_MainWorkSpaseTree.Nodes[0]).Height;
this.FormGUI.c_MainWorkSpaseTree.Nodes[0].Remove();
}
else
{
res = this.FormGUI.c_MainWorkSpaseTree.Height / FormGUI.c_MainWorkSpaseTree.getNodeRectangle(this.FormGUI.c_MainWorkSpaseTree.Nodes[0]).Height;
}
//и незабываем воткнуть вычисленное значение в комбобокс
this.FormGUI.c_cmb_countRowsInPage.Text = (res - 4).ToString();
return res;
}
//пример использования функции
void FormGUI_Load(object sender, EventArgs e)
{
//возвращается интовое значение и ложится в комбобокс
GetcountVisibleNodesInList();
int CountRows = 0;
if (int.TryParse(FormGUI.c_cmb_countRowsInPage.Text, out CountRows))
{
_LastShowedRowNumber = 0;
GoToNextPage(); //там же комбобокс опять парсится
}
}
обратите внимание на обработчик загрузки формы.
Из нужного кода там только вызов GoToNextPage() в котором опять же парсим комбобокс
+163
Example #3 preg_replace_callback() using recursive structure to handle encapsulated BB code
<?php
$input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain";
function parseTagsRecursive($input)
{
$regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#';
if (is_array($input)) {
$input = '<div style="margin-left: 10px">'.$input[1].'</div>';
}
return preg_replace_callback($regex, 'parseTagsRecursive', $input);
}
$output = parseTagsRecursive($input);
echo $output;
?>
Не знаю, баян или нет. Поиском не смог найти preg_replace_callback на этом сайте.
В таком недлинном коде есть очень аппетитное дерьмецо (кроме языка). Если в качестве $input взять строку подлиннее, то интерпретатор, как Чак Норрис, сосчитает до бесконечности. Исправляется добавлением одного символа к коду.
+151
var GetUrl = /\[(.*)\]/g.exec("$SECTION_NAME$")[1].replace(/\-/i, '~').replace(/\-/i, '~');
фу ;(
+155
if($inc == true){
$counter_val = $cat[$this->FileCounterKey] + 1;
}else{
$counter_val = $cat[$this->FileCounterKey] - 1;
}
Класс деревьев в одной русской CMS. Метод пересчитывает кол-во файлов в категории после добавления/удаления.
+75
<% ServicePackage servicePackage = null; %>
<% char fi [] = {'g', 'v', 'p'}; %>
<% int ni [] = {3, 7, 11}; %>
<% for(int i = 0; i < fi.length; i++)
for(int j = 1; j <= ni[i]; j++)
{
String id = "", name = null, brief = null, price = null;
id += (char)fi[i];
if (j >= 10)
id += (char)('0' + j / 10);
id += (char)('0' + j % 10);
servicePackage = AllServicePackages.map.get(id);
if (servicePackage != null)
{
name = servicePackage.getName();
brief = servicePackage.getBrief();
price = servicePackage.getPrise();
}
%>
<% } %>
Автору хотелось перебрать все эл-ты map'а.
+151
$currN = 0;
$countN = count($news);
$currW = 0;
$countW = count($wall);
$time = time();
$date = date('Y-m-d H:i:s');
// Жестянка в сферическом ваккуме куба
foreach($lenta as $k => &$v)
{
while (($v['DZ'] <= $news[$currN]['DZ']))
{
while (($news[$currN]['DZ'] <= $wall[$currW]['DZ']) && ($currW < $countW))
{
$this->create_time($wall[$currW]['DZ'], $time, $date);
$this->display_wall($wall[$currW]);
++$currW;
}
$this->create_time($news[$currN]['DZ'], $time, $date);
$this->display_news($news[$currN]);
++$currN;
}
$this->create_time($v['DZ'], $time, $date);
$this->display_lenta($v, $usr);
}
while ($currN < $countN)
{
while (($news[$currN]['DZ'] <= $wall[$currW]['DZ']) && ($currW < $countW))
{
$this->create_time($wall[$currW]['DZ'], $time, $date);
$this->display_wall($wall[$currW]);
++$currW;
}
$this->create_time($news[$currN]['DZ'], $time, $date);
$this->display_news($news[$currN]);
++$currN;
}
while ($currW < $countW)
{
$this->create_time($wall[$currW]['DZ'], $time, $date);
$this->display_wall($wall[$currW]);
++$currW;
}
Просто и со вкусом.
−108
function t()
{
setTimeout('document.getElementById("qwezxc").innerHTML+="H"',1000)
setTimeout('document.getElementById("qwezxc").innerHTML+="e"',2000)
setTimeout('document.getElementById("qwezxc").innerHTML+="l"',3000)
setTimeout('document.getElementById("qwezxc").innerHTML+="l"',4000)
setTimeout('document.getElementById("qwezxc").innerHTML+="o"',5000)
setTimeout('document.getElementById("qwezxc").innerHTML+=","',6000)
setTimeout('document.getElementById("qwezxc").innerHTML+="W"',7000)
setTimeout('document.getElementById("qwezxc").innerHTML+="o"',8000)
setTimeout('document.getElementById("qwezxc").innerHTML+="r"',9000)
setTimeout('document.getElementById("qwezxc").innerHTML+="l"',10000)
setTimeout('document.getElementById("qwezxc").innerHTML+="d"',11000)
}
+147
dirname(__FILE__)