- 1
<br />
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+28
<br />
+65
$needDied = $this->battle_data['type'] == 104 ? true : false;
−153
SELECT count(*) as cnt FROM cms_books AS b
JOIN (SELECT DISTINCT r.book_id FROM cms_book2cat AS r
JOIN (SELECT 40 AS category_id
UNION SELECT 105 AS category_id UNION SELECT 212 AS category_id UNION SELECT 404 AS category_id UNION SELECT 1 AS category_id UNION SELECT 2 AS category_id UNION SELECT 3 AS category_id UNION SELECT 5 AS category_id UNION SELECT 62 AS category_id UNION SELECT 60 AS category_id UNION SELECT 59 AS category_id UNION SELECT 58 AS category_id UNION SELECT 55 AS category_id UNION SELECT 54 AS category_id UNION SELECT 51 AS category_id UNION SELECT 50 AS category_id UNION SELECT 49 AS category_id UNION SELECT 71 AS category_id UNION SELECT 72 AS category_id UNION SELECT 78 AS category_id UNION SELECT 85 AS category_id UNION SELECT 86 AS category_id UNION SELECT 90 AS category_id UNION SELECT 91 AS category_id UNION SELECT 92 AS category_id UNION SELECT 94 AS category_id UNION SELECT 96 AS category_id UNION SELECT 101 AS category_id UNION SELECT 156 AS category_id UNION SELECT 157 AS category_id UNION SELECT 222 AS category_id UNION SELECT 226 AS category_id UNION SELECT 398 AS category_id UNION SELECT 406 AS category_id UNION SELECT 407 AS category_id UNION SELECT 416 AS category_id UNION SELECT 417 AS category_id UNION SELECT 890 AS category_id UNION SELECT 106 AS category_id UNION SELECT 108 AS category_id UNION SELECT 111 AS category_id UNION SELECT 115 AS category_id UNION SELECT 152 AS category_id UNION SELECT 121 AS category_id UNION SELECT 125 AS category_id UNION SELECT 159 AS category_id UNION SELECT 195 AS category_id UNION SELECT 257 AS category_id UNION SELECT 262 AS category_id UNION SELECT 302 AS category_id UNION SELECT 306 AS category_id UNION SELECT 397 AS category_id UNION SELECT 401 AS category_id UNION SELECT 402 AS category_id UNION SELECT 403 AS category_id UNION SELECT 413 AS category_id UNION SELECT 414 AS category_id UNION SELECT 213 AS category_id UNION SELECT 214 AS category_id UNION SELECT 215 AS category_id UNION SELECT 216 AS category_id UNION SELECT 217 AS category_id UNION SELECT 4 AS category_id UNION SELECT 477 AS category_id UNION SELECT 45 AS category_id UNION SELECT 10 AS category_id UNION SELECT 9 AS category_id UNION SELECT 11 AS category_id UNION SELECT 65 AS category_id UNION SELECT 64 AS category_id UNION SELECT 63 AS category_id UNION SELECT 61 AS category_id UNION SELECT 57 AS category_id UNION SELECT 56 AS category_id UNION SELECT 53 AS category_id UNION SELECT 52 AS category_id UNION SELECT 48 AS category_id UNION SELECT 47 AS category_id UNION SELECT 46 AS category_id UNION SELECT 43 AS category_id UNION SELECT 44 AS category_id UNION SELECT 66 AS category_id UNION SELECT 67 AS category_id UNION SELECT 68 AS category_id UNION SELECT 69 AS category_id UNION SELECT 70 AS category_id UNION SELECT 73 AS category_id UNION SELECT 74 AS category_id UNION SELECT 75 AS category_id UNION SELECT 76 AS category_id UNION SELECT 77 AS category_id UNION SELECT 79 AS category_id UNION SELECT 80 AS category_id UNION SELECT 81 AS category_id UNION SELECT 82 AS category_id UNION SELECT 83 AS category_id UNION SELECT 84 AS category_id UNION SELECT 87 AS category_id UNION SELECT 88 AS category_id UNION SELECT 89 AS category_id UNION SELECT 93 AS category_id UNION SELECT 95 AS category_id UNION SELECT 97 AS category_id UNION SELECT 98 AS category_id UNION SELECT 102 AS category_id UNION SELECT 103 AS category_id UNION SELECT 109 AS category_id UNION SELECT 112 AS category_id UNION SELECT 113 AS category_id UNION SELECT 114 AS category_id UNION SELECT 116 AS category_id UNION SELECT 117 AS category_id UNION SELECT 119 AS category_id UNION SELECT 122 AS category_id UNION SELECT 123 AS category_id UNION SELECT 124 AS category_id UNION SELECT 126 AS category_id UNION SELECT 133 AS category_id UNION SELECT 134 AS category_id UNION SELECT 137 AS category_id UNION SELECT 142 AS category_id UNION SELECT 146 AS category_id UNION SELECT 149 AS category_id UNION SELECT 153 AS category_id UNION SELECT 155 AS category_id UNION SELECT 158 AS category_id UNION SELECT 160 AS category_id UNION SELECT 162 AS category_id UNION SELECT 163 AS category_id UNION SELECT 169 AS category_id UNION SELECT 176 AS category_id UNION SELECT 185 AS category_id UNION SELECT 193 AS category_id UNION SELECT 194 AS category_id UNION SELECT 196 AS category_id UNION SELECT 197 AS category_id UNION SELECT 198 AS category_id UNION SELECT 199 AS category_id UNION SELECT 200 AS category_id UNION SELECT 202 AS category_id UNION SELECT 205 AS category_id UNION SELECT 207 AS category_id UNION SELECT 208 AS category_id UNION SELECT 209 AS category_id UNION SELECT 210 AS category_id UNION SELECT 211 AS category_id UNION SELECT 228 AS category_id UNION SELECT 221 AS category_id UNION SELECT 224 AS category_id UNION SELECT 225 AS category_id UNION SELECT 238 AS category_id UNION SELECT 249 AS category_id UNION SELECT 250 AS category_id UNION SELECT 254 AS category_id UNION SELECT 255 AS category_id UNION SELECT 256 AS category_id UNION SELECT 258 AS category_id UNION SELECT 259 AS category_id UNION SELECT 263 AS category_id UNION SELECT 264 AS category_id UNION SELECT 265 AS category_id UNION SELECT 266 AS category_id UNION SELECT 267 AS category_id UNION SELECT 268 AS category_id UNION SELECT 269 AS category_id UNION SELECT 270 AS category_id UNION SELECT 271 AS category_id UNION SELECT 272 AS category_id UNION SELECT 274 AS category_id UNION SELECT 275 AS category_id UNION SELECT 276 AS category_id UNION SELECT 277 AS category_id UNION SELECT 278 AS category_id
AS c ON (c.category_id=r.category_id)) AS br ON (b.book_id=br.book_id)
WHERE 1
половину пришлось отрезать - форма не пускала. Общая длина запроса - более 12k
задача - выбрать кол-во книг из текущей категории и всех вложенных
+153
<ul class="menu">
<li class="leaf first">
<a href="http://example.com/app1?operator=<!--{cke_protected}
<?php echo($user->profile_crm_name); ?>
-->" target="_blank">Заявка №1</a>
</li>
<li class="leaf">
<a href="http://example.com/app2?operator=<!--{cke_protected}
<?php echo($user->profile_crm_name); ?>
-->" target="_blank">Заявка №2</a>
</li>
<!-- ... еще десяток ... -->
</ul>
Drupal, приложение для колл-центра, пользовательский блок со списком ссылок. {cke_protected} - защита от WYSIWYG-редактора.
Спасибо, что хоть без SQL
+156
private static BigInteger result = 0;
static BigInteger F1 = 1;
static BigInteger F2 = 1;
static BigInteger provv;
static BigInteger provv2;
static void Main(string[] args)
{
for (BigInteger number = 3; result == 0; number++)
{
provv2 = F2;
F2 = F2 + F1;
F1 = provv2; ;
if (HasProperty(F2.ToString()))
result = number;
}
}
private static bool HasProperty(string number)
{
if (number.Length < 9)
return false;
if (IsPandigital(number.Substring(0, 9)))
if (IsPandigital(number.Substring(number.Length - 9, 9)))
return true;
return false;
}
private static bool IsPandigital(string result)
{
int repetitions;
for (int count = 0; count < 9; count++)
{
repetitions = 0;
for (int count2 = 0; count2 < 9; count2++)
{
if (result.ElementAt(count).ToString() == "0")
return false;
if (result.ElementAt(count).ToString() == result.ElementAt(count2).ToString())
{
repetitions++;
if (repetitions == 2)
return false;
}
}
}
return true;
}
http://projecteuler.net/problem=104
http://projecteuler.net/thread=104;page=6
>brute force approach,solved aproximately in 24 hours
>solved aproximately in 24 hours
>24 hours
>24
>hours
Терпеливый, сука!
+137
[ExposeProperty]
public bool Exhausted {
get {
if (this.State > FatigueConsts.globalNormalRange)
return true;
else
return false;
}
set {
if (this.State > FatigueConsts.globalNormalRange)
Exhausted = true;
else
Exhausted = false;
}
}
И потом полчаса сидел, понимал, почему Юнити зависает, когда я пытаюсь открыть инспектор с этим объектом ) Потом поставил в сеттер return;, ибо для костыля [ExposeProperty] требуются и геттер, и сеттер.
+141
...
ASSERT( sizeof(L"SystemPartition") <= sizeof(nameBuffer) );
/* Китайский код? Или по другому нельзя было запихнуть строку в ентот массив? */
nameBuffer[0] = L'S';
nameBuffer[1] = L'y';
nameBuffer[2] = L's';
nameBuffer[3] = L't';
nameBuffer[4] = L'e';
nameBuffer[5] = L'm';
nameBuffer[6] = L'P';
nameBuffer[7] = L'a';
nameBuffer[8] = L'r';
nameBuffer[9] = L't';
nameBuffer[10] = L'i';
nameBuffer[11] = L't';
nameBuffer[12] = L'i';
nameBuffer[13] = L'o';
nameBuffer[14] = L'n';
nameBuffer[15] = L'\0';
nameString.MaximumLength = sizeof(L"SystemPartition");
nameString.Length = sizeof(L"SystemPartition") - sizeof(WCHAR);
status = NtSetValueKey(setupHandle,
&nameString,
TITLE_INDEX_VALUE,
REG_SZ,
volumeNameString.Buffer,
volumeNameString.Length + sizeof(WCHAR)
);
...
В Мелкософт китайцев пригласили?
Кусок кода ядра Шindoшs ИТ
файл ioinit.c, строка 3312
+56
<?php
define(STATIC_SALT, "herz_salt");
function generateRandChar()
{
$chars = 'abdefhiknrstyzABDEFGHKNQRSTYZ23456789';
$numChars = strlen($chars);
$string = '';
for ($i = 0; $i < rand(1, 7); $i++)
{
$string .= substr($chars, rand(1, $numChars) - 1, 1);
}
return $string;
}
$time = microtime(true) / 10000;
$str = $time - floor($time);
$str = (string)$str;
$str = preg_replace('/0./', '', $str);
$deleteNum = strlen($str);
if($deleteNum <= 5)
{
$str = substr($str, rand(0, 4));
}
elseif($deleteNum > 5 && $deleteNum <= 10)
{
$str = substr($str, rand(5, 9));
}
else $str = substr($str, rand(7, 9));
if(strlen($str) == 0)
{
$str = rand(0, 15000);
}
sleep(5);
$str = sha1(md5($str . STATIC_SALT . microtime(true))) . generateRandChar();
echo $str;
?>
паранойя в действии :)
+132
function rechargePubSession(age,sexe)
{
var url_pub_ban = "publicite_banniere";
var url_pub_sky = "publicite_skyscrapper";
var ext;
if (age >0)
{
if (age < 18)
ext="_A";
else if (age < 33)
ext="_G";
else if (age >= 33)
ext="_E";
if (ext!="")
{
if (sexe == "F")
ext+="_F";
else if (sexe == "M")
ext+="_M";
if (sexe=="M" || sexe=="F")
{
url_pub_ban += ext;
url_pub_sky += ext;
}
}
}
url_pub_ban+=".html";
url_pub_sky+=".html";
frame_pub_banniere.document.location= url_pub_ban;
frame_pub_droite.document.location=url_pub_sky;
}
http://ru.akinator.com
+50
// $conn - mysqli_object
$query = "insert into orders values
('0', '".$customerid."', '".$_SESSION['total_price']."',
'".$date."', '".PARTIAL."', '".$ship_name."',
'".$ship_address."', '".$ship_city."',
'".$ship_state."', '".$ship_zip."',
'".$ship_phone."', '".$ship_mail."')";
$result = $conn->query($query) ;
if (!$result) {
return false;
}
//amount - float
$query = "select orderid from orders where
customerid = '".$customerid."' and
amount > (".$_SESSION['total_price']."-.001) and
amount < (".$_SESSION['total_price']."+.001) and
date = '".$date."' and
order_status = 'PARTIAL' and
ship_name = '".$ship_name."' and
ship_address = '".$ship_address."' and
ship_city = '".$ship_city."' and
ship_state = '".$ship_state."' and
ship_zip = '".$ship_zip."' and
ship_country = '".$ship_country."'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$order = $result->fetch_object();
$orderid = $order->orderid;
} else {
return false;
}
Источник: Люк Веллинг и Лора Томсон: Разработка веб-приложений с помощью PHP и MySQL(4 издание стр 594)
Как выдрать last_insert_id? Очень просто: нужно составить запрос на select вставленного orderid с указанием всех вставленных значений в поля, а для флоата указать на всякий случай интервал, и только тогда можно из выборки извлечь вставленный id
ps: констатна PARTIAL нигде не задаётся=)