- 1
SELECT Status_ID FROM User,UserStatus,Status WHERE User_ID=UserStatus_UserID AND UserStatus_StatusID=Status_ID GROUP BY Status_ID
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−169
SELECT Status_ID FROM User,UserStatus,Status WHERE User_ID=UserStatus_UserID AND UserStatus_StatusID=Status_ID GROUP BY Status_ID
+133
//checks if the string is a hex stream e.g. "31 32 33 6A F8"
private bool _IsHexStream(string sValue)
{
sValue = sValue.Trim();
if (sValue.Length < 2)
{
return false;
}
for (int i = 0; i < sValue.Length; i++)
{
if(_IsHexChar(Convert.ToChar(sValue.Substring(i,1))) == false)
{
return false;
}
}
//every third char must be a space, only possible in case of two bytes
if (sValue.Length > 3)
{
for (int i = 2; i < sValue.Length; i += 3)
{
string sBuffer = sValue.Substring(i, 1);
if (sBuffer.Equals(" ") == false)
{
return false;
}
}
}
//string is a hex stream
return true;
}
+134
TestScriptResult Test_method( ... )
{
TestScriptResult result = new TestScriptResult();
object obj = null;
///...
obj = foo.Set(...);
if (obj.GetType() == typeof(Exception))
{
result.SetResult(TestScriptResult.eTestResult.FAIL_SET_REQUEST, ((Exception)obj).Message);
_LogTestMethodEnd(result);
return result;
}
else
{
}
}
public Object Set(...)
{
//...
if(CheckForErrors(res) == true)
{
//create error description
string sErrorDescription = string.Format("Error during ...."));
//create exception object and return this
Exception ex = new Exception(sErrorDescription);
//error logging
m_logger.Error(sErrorDescription);
return ex;
}
else
{
}
}
Ну нах так жыть, котаны???
+8
#define FOR_INCLUSION (iostream) (studio.h) (stdlib.h) (boost/phoenix.hpp) (my_drugs_library.h)
#include <include_and_disable_some_warnings>
+96
var m = map[int]string { 1: "one", 2: "two", 3: "three", }
if val, ok := m[3]; ok { fmt.Printf("Yes! %s\n",val) } else { fmt.Println("No!") }
Почему в Go первое присваивание надо писать через =
А то что в if через :=
http://ideone.com/cPf2cw
http://ideone.com/fork/cPf2cw
+150
<?php
$subjects = array (
0 =>
array (
'title' => 'ОС Unix',
'teacher' => 'Вася',
'mark' => '3'),
1 =>
array (
'title' => 'Компьютерные сети',
'teacher' => 'Петя',
'mark' =>'4'),
2 =>
array (
'title' => 'Алгоритмы',
'teacher' => 'Коля',
'mark' => '4'),
);?>
<table>
<? foreach ($subjects as $key=>$subject) :
$number = $key+1;
?>
<tr>
<td><?echo $number;?></td>
<td><?echo $subject['title'];?></td>
<td><?echo $subject['teacher'];?></td>
<td><?echo $subject['mark'];?></td>
</tr>
<? endforeach; ?>
</table>
<? var_dump($subject)?>
+73
int a = 1;
int b = 2;
int c = 2;
String d = " ";
System.out.print(a+d);
System.out.print(b+d);
System.out.print(b+a+d);
System.out.print(4+d);
System.out.print(5+d);
System.out.print(6+d);
System.out.print(7+d);
System.out.print(8+d);
System.out.print(9+d);
System.out.println(10+d);
System.out.print(2+d);
System.out.print(4+d);
System.out.print(6+d);
System.out.print(8+d);
System.out.print(10+d);
System.out.print(12+d);
System.out.print(14+d);
System.out.print(16+d);
System.out.print(18+d);
System.out.println(20+d);
System.out.print(3+d);
System.out.print(6+d);
System.out.print(9+d);
System.out.print(12+d);
System.out.print(15+d);
System.out.print(18+d);
System.out.print(21+d);
System.out.print(24+d);
System.out.print(27+d);
System.out.println(30+d);
System.out.print(4+d);
System.out.print(8+d);
System.out.print(12+d);
System.out.print(16+d);
System.out.print(20+d);
System.out.print(24+d);
System.out.print(28+d);
System.out.print(32+d);
System.out.print(36+d);
System.out.println(40+d);
System.out.print(5+d);
System.out.print(10+d);
System.out.print(15+d);
System.out.print(20+d);
System.out.print(25);
System.out.print(30+d);
System.out.print(35+d);
System.out.print(40+d);
System.out.print(45+d);
System.out.println(50+d);
System.out.print(6+d);
System.out.print(12+d);
System.out.print(18+d);
System.out.print(24+d);
System.out.print(30+d);
System.out.print(36+d);
System.out.print(42+d);
System.out.print(48+d);
System.out.print(54+d);
System.out.println(60+d);
System.out.print(7+d);
System.out.print(14+d);
System.out.print(21+d);
System.out.print(28+d);
System.out.print(35+d);
System.out.print(42+d);
System.out.print(49+d);
System.out.print(56+d);
System.out.print(63+d);
System.out.println(70+d);
System.out.print(8+d);
System.out.print(16+d);
System.out.print(24+d);
System.out.print(32+d);
System.out.print(40+d);
System.out.print(48+d);
System.out.print(56+d);
System.out.print(64+d);
System.out.print(72+d);
System.out.println(80+d);
System.out.print(9+d);
System.out.print(18+d);
System.out.print(27+d);
System.out.print(36+d);
System.out.print(45+d);
System.out.print(54+d);
System.out.print(63+d);
System.out.print(72+d);
System.out.print(81+d);
System.out.println(90+d);
System.out.print(10+d);
System.out.print(20+d);
System.out.print(30+d);
System.out.print(40+d);
System.out.print(50+d);
System.out.print(60+d);
Пытался таблицу умножения сделать в детстве...
+157
if (strlen($arResult["ERROR_MESSAGE"]) <= 0){
// любая ахинея
}
2014 год. Битрикс все так же терпеливо ожидает патент на строки отрицательной длины.
Полагаю, такой икспрешн используется не только в компоненте корзины, учитывая страсть авторов к копипасте.
+154
if ($_SERVER["REQUEST_METHOD"] == "POST" && strlen($_REQUEST["backButton"]) > 0 && ($arParams["DELIVERY_NO_SESSION"] == "N" || check_bitrix_sessid()))
{
if($arResult["POST"]["CurrentStep"] == 6 && $arResult["SKIP_FORTH_STEP"] == "Y")
$arResult["CurrentStepTmp"] = 3;
if($arResult["POST"]["CurrentStepTmp"] <= 5 && $arResult["SKIP_THIRD_STEP"] == "Y")
$arResult["CurrentStepTmp"] = 2;
if($arResult["POST"]["CurrentStepTmp"] <= 3 && $arResult["SKIP_SECOND_STEP"] == "Y")
$arResult["CurrentStepTmp"] = 1;
if(IntVal($arResult["CurrentStepTmp"])>0)
$arResult["CurrentStep"] = $arResult["CurrentStepTmp"];
else
$arResult["CurrentStep"] = $arResult["CurrentStep"] - 2;
$arResult["BACK"] = "Y";
}
if ($arResult["CurrentStep"] <= 0)
$arResult["CurrentStep"] = 1;
$arResult["ERROR_MESSAGE"] = "";
Компонент страницы заказа в магазине Битрикса, 14я версия.
Тут вам и отсутствие констант для осмысленных шагов, и отсутствие конфигурирования этих шагов, как они i18n-ятся, вообще не представляю.
КАК ЭТО ВСЁ РАБОТАЕТ??!!!
ЗЫ мало того, тут же в компонент вкопипащен (или переговнокоден заново, не сравнивал) процесс залогинивания/регистрации нового юзера, елси он не залогинен. Не смог перекопипастить эту копипасту лишь потому, что она содержит 310 строк. Неслабый DRY.
+72
public class PLock {
private Map<Thread, Integer> readLocks = new HashMap<Thread, Integer>();
private Thread writeLock = null;
private int writeLockCount = 0;
public synchronized void getReadLock() {
Thread currentThread = Thread.currentThread();
long startTimeMillis = System.currentTimeMillis();
boolean gotStuck = false;
while (canClaimReadLock(currentThread) == false) {
gotStuck = true;
try {
wait();
} catch (InterruptedException ex) {
Log.warn("Interrupted while attempting to get read lock.", ex);
}
}
report(gotStuck, startTimeMillis, "read");
if (readLocks.containsKey(currentThread)) {
readLocks.put(currentThread, 1 + readLocks.get(currentThread));
} else {
readLocks.put(currentThread, 1);
}
}
...
public synchronized void relinquishReadLock() {
Thread currentThread = Thread.currentThread();
if (readLocks.containsKey(currentThread) == false) {
throw new RuntimeException("Cannot relinquish read lock on thread " + currentThread + " because it does not hold a lock.");
}
int newLockCount = readLocks.get(currentThread) - 1;
if (newLockCount == 0) {
readLocks.remove(currentThread);
notifyAll(); // IMPORTANT: allow other threads to wake up and check if they can get locks now.
} else {
readLocks.put(currentThread, newLockCount);
}
}
public synchronized void getWriteLock() {
//Log.warn("getWriteLock() in thread " + Thread.currentThread());
//dumpLocks();
Thread currentThread = Thread.currentThread();
long startTimeMillis = System.currentTimeMillis();
boolean gotStuck = false;
while (canClaimWriteLock(currentThread) == false) {
gotStuck = true;
try {
wait();
} catch (InterruptedException ex) {
Log.warn("Interrupted while attempting to get write lock.", ex);
}
}
report(gotStuck, startTimeMillis, "write");
writeLock = currentThread;
writeLockCount++;
}
...
public synchronized void relinquishWriteLock() {
//Log.warn("relinquishWriteLock() in thread " + Thread.currentThread());
Thread currentThread = Thread.currentThread();
if (writeLock != currentThread) {
throw new RuntimeException("Cannot relinquish write lock on thread " + currentThread + " because it does not hold the lock.");
}
if (writeLockCount <= 0) {
throw new RuntimeException("Tried to relinquish write lock on thread " + currentThread + " while write lock count is " + writeLockCount);
}
writeLockCount--;
if (writeLockCount == 0) {
writeLock = null;
notifyAll(); // IMPORTANT: allow other threads to wake up and check if they can get locks now.
}
}
...
}
А у вас уже есть свой теплый ламповый ReentrantReadWriteLock?
Нет? Тогда https://github.com/orph/jujitsu/blob/master/src/e/ptextarea/PLock.java идет к вам...