- 1
- 2
- 3
- 4
If($z["timeout"]==1 || $z['timeout']==3 || $z['timeout']==4 || $z['timeout']==5 || $z['timeout']==7 || $z['timeout']==10) {
} else {
$z['timeout'] = 3;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+49
If($z["timeout"]==1 || $z['timeout']==3 || $z['timeout']==4 || $z['timeout']==5 || $z['timeout']==7 || $z['timeout']==10) {
} else {
$z['timeout'] = 3;
}
'<>' и 'or' ? неее, не слышали!
+141
window.onload = function () {
var жирнота = [
600,
700,
800,
900
],
свэг = document.getElementById("swag");
свэг.innerHTML = "";
"SWAG".split("").forEach(function (буква) {
свэг.innerHTML += "<span>" + буква + "</span>"
});
function ослучайнить(что) {
return Math.floor(Math.random() * что);
}
function минимальноРаскрашываетСвэг() {
Array.prototype.forEach.call(свэг.children, function (буква) {
буква.style.color = "#" + ослучайнить(0xffffff).toString(16);
буква.style.fontSize = 250 + ослучайнить(175) + "px";
буква.style.fontWeight = жирнота[ослучайнить(жирнота.length)];
});
}
setInterval(минимальноРаскрашываетСвэг, 500);
};
+11
#include <QVector>
#include <QString>
template< class TYPE>
class call
{
public:
call( TYPE& vl ): value(vl){}
TYPE& value;
};
template< class TYPE>
call<TYPE> all( TYPE& vl )
{ return call<TYPE>(vl); }
template< class TYPE_OUT, class TYPE>
void operator << ( TYPE_OUT& out, call<TYPE>& in )
{
TYPE& value = in.value;
for( TYPE::iterator itr = value.begin() ; itr!=value.end(); itr++)
out << *itr;
}
//**********************************************************************
QVector<int> arr;
QVector<QString> arrStr;
class Cstream{} stream;
void operator << ( Cstream& , const int value)
{
printf("%i\n",value);
}
void operator << ( Cstream& , const QString& value)
{
printf("%s\n",value.toAscii().data());
}
int main(int argc, char *argv[])
{
for( int i=0; i<6;i++)
arr.push_back(i);
arrStr << "asd" << "sadas" << "sadsa";
stream << all(arr);
stream << all(arrStr);
return 0;
}
http://www.gamedev.ru/flame/forum/?id=171504
> @При копирование на говнокод сохранять авторство.
+81
if (request.equals("") || request == null) {
Response.status(Response.Status.NO_CONTENT).build();
}
ну сколько можно...
+156
this.start = function() {
// Инициализирует парсинг выгрузки из Агента Плюс.
if (this.open()) {
this.catalogs = this.getTags("catalogs", true)[0].childs;
this.subdocuments = this.getTags("documents", true)[1].childs;
this.guids = this.document.childs[0].childs[0].childs;
this.sellhistory = this.getCatalog("ИсторияПродаж").childs[0].childs;
this.sellpoints = this.getCatalog("ТорговыеТочки").childs[0].childs;
this.contragents = this.getCatalog("Контрагенты").childs[1].childs;
this.deals = this.getCatalog("Договоры").childs[0].childs;
this.nomenclature = this.getCatalog("Номенклатура").childs;
this.measure = this.getCatalog("ЕдиницыИзмерения").childs[0].childs;
this.route = this.getDocument("Маршрут").childs[0].childs[0].childs[0].childs[0]
this.names = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
this.info = {deals: [], catalog: [], nomenclature: [], measure: [], contragents: [], sellpoints: []};
this.hash = {deals: {}, nomenclature: {}, consts: {}, contragents: {}, sellpoints: [], measure: {}};
for (var i = 0; i < this.catalogs.length; i++) {
this.names.catalog.push(this.catalogs[i].attrib.Comment.replace(/Справочник\./g, ""));
this.info.catalog.push(this.catalogs[i].attrib);
}
for (var i = 0; i < this.nomenclature[1].childs.length; i++) {
this.names.nomenclature.push(this.nomenclature[1].childs[i].attrib.Name);
this.info.nomenclature.push(this.nomenclature[1].childs[i].attrib);
this.hash.nomenclature[this.nomenclature[1].childs[i].attrib.GUID] = this.nomenclature[1].childs[i].attrib;
}
for (var i = 0; i < this.deals.length; i++) {
this.names.deals.push(this.deals[i].attrib.Name);
this.info.deals.push(this.deals[i].attrib);
this.hash.deals[this.deals[i].attrib.GUID] = this.deals[i].attrib;
}
for (var i = 0; i < this.measure.length; i++) {
this.names.measure.push(this.measure[i].attrib.Name);
this.info.measure.push(this.measure[i].attrib);
this.hash.measure[this.measure[i].attrib.GUID] = this.measure[i].attrib;
}
for (var i = 0; i < this.contragents.length; i++) {
this.names.contragents.push(this.contragents[i].attrib.Name);
this.info.contragents.push(this.contragents[i].attrib);
this.hash.contragents[this.contragents[i].attrib.GUID] = this.contragents[i].attrib;
}
for (var i = 0; i < this.sellpoints.length; i++) {
this.names.sellpoints.push(this.sellpoints[i].attrib.Name);
this.info.sellpoints.push(this.sellpoints[i].attrib);
this.hash.sellpoints[this.sellpoints[i].attrib.GUID] = this.sellpoints[i].attrib;
}
for (var i = 0; i < this.guids.length; i++) {
this.hash.consts[this.guids[i].attrib.GUID] = this.guids[i].attrib.VALUE;
}
this.dynamic.routes = new Array();
for (var i = 0; i < this.route.childs.length; i++) {
var sp = this.getSPointByGUID(this.route.childs[i].attrib.A02);
var adr = sp.Name;
var ca = this.getCAgentByGUID(this.route.childs[i].attrib.A01);
var ptypeguid = this.hash.deals[ca.A08].A06;
var cagent = ca.Name;
var dealguid = ca.A08;
var exists = false;
for (var j = 0; j < this.dynamic.routes.length; j++) if (this.dynamic.routes[j].address.trim().toLowerCase() == adr.trim().toLowerCase()) exists = exists || true;
if (!exists) this.dynamic.routes.push({ptypeguid: ptypeguid, spointguid: sp.GUID, address: adr, dealguid: dealguid, cagent: cagent, cagentguid: ca.GUID, datestamp: this.convRouteDate(this.route.childs[i].attrib.A03)});
}
} else return;
};
Маленькая часть нашего скрипта для работы с 1С - Node.JS - WebClient.
+91
procedure RecursiveVisibility(e : PCreature; oct, depth : integer; slopeA, slopeB : single);
var
x, y : integer;
begin
case oct of
1 : begin
y := e^.y - depth; { initialize y }
x := round(e^.x - slopeA * depth); { initialize z }
while GetSlopeStd(x, y, e^.x, e^.y) >= slopeB do begin { while in octant }
if GetVisDistance(x, y, e^.x, e^.y) <= mw then begin { if within max visual range }
if WorldSurface[x, y].entity^.obstruct then begin { if obstruction }
if not WorldSurface[x - 1, y].entity^.obstruct then begin { if no prior obstruction }
RecursiveVisibility(e, 1, depth + 1, slopeA, GetSlopeStd(x - 0.5, y + 0.5, e^.x, e^.y));
end; { ^create recursive scan }
end else begin { no obstruction }
if WorldSurface[x - 1, y].entity^.obstruct then begin { if prior obstruction }
slopeA := GetSlopeStd(x - 0.5, y - 0.5, e^.x, e^.y); { adjust slope for later recursion }
end;
end;
WorldSurface[x, y].visibility := 3; { set block visible }
end;
inc(x);
end;
dec(x)
end;
2 : begin
y := e^.y - depth; { initialize y }
x := round(e^.x + slopeA * depth); { initialize z }
while GetSlopeStd(x, y, e^.x, e^.y) <= slopeB do begin { while in octant }
if GetVisDistance(x, y, e^.x, e^.y) <= mw then begin { if within max visual range }
if WorldSurface[x, y].entity^.obstruct then begin { if obstruction }
if not WorldSurface[x + 1, y].entity^.obstruct then begin { if no prior obstruction }
RecursiveVisibility(e, 2, depth + 1, slopeA, GetSlopeStd(x + 0.5, y + 0.5, e^.x, e^.y));
end; { ^create recursive scan }
end else begin { no obstruction }
if WorldSurface[x + 1, y].entity^.obstruct then begin { if prior obstruction }
slopeA := -GetSlopeStd(x + 0.5, y - 0.5, e^.x, e^.y); { adjust slope for later recursion }
end;
end;
WorldSurface[x, y].visibility := 3; { set block visible }
end;
dec(x);
end;
inc(x)
end;
// Далее всё в таком же духе.
Отсюда: http://roguebasin.roguelikedevelopment.org/index.php?title=FOV_using_recursive_shad owcasting_-_improved
Можно было сделать менее говнокодистей?
+15
LambdaVar<1> X;
LambdaVar<2> Y;
// The next line prints 10:
cout << lambda(X,Y)[ plus[ multiplies[3,X], Y ] ] (3,1) << endl;
cout << lambda(X,Y)[ (3 %multiplies% X) %plus% Y ] << endl;
//...
lambda(X)[ X %plus% getCurrentTime[_*_] ]
//...
let[ X == someLambdaExp,
Y == someOtherLambdaExpWhichMayInvolveX ]
.in[ someLambdaExpInvolvingXandY ]
//...
lambda(X)[
letrec[ F == lambda(Y)[ if1[ Y %equals% 0,
1,
Y %multiplies% F[Y %minus% 1] ] ] ]
.in[ F[X] ] ]
//...
Maybe<int> mx = just(2);
Maybe<int> my = just(3);
mx = lambda()[ compM<MaybeM>()[ plus[X,Y] | X<=mx, Y<=my, guard[false] ] ]();
cout << mx << endl; // Nothing
//...
compM<ListM>()[ makePair[X,Y] | X<=list_with(1,2), guard[true],
Y<=list_with(3,4), guard[ (Y %divides% X) %equal% 3 ] ] ]
Грибки отсюда:
http://people.cs.umass.edu/~yannis/fc++/
+79
private static String dbl2str(Object obj) {
String value;
String str = obj.toString();
if (str.indexOf('E') != -1) {
//System.out.print("1 ");
String[] qwe = str.split("E");
String newstr = "";
int step = Integer.parseInt(qwe[1]);
for (int ind = 0; ind < qwe[0].length(); ind++) {
if (step > 0) {
if ((ind == (step + 2)) && (ind != qwe[0].length())) {
newstr = newstr + '.';
}
if (str.charAt(ind) != '.') {
newstr = newstr + str.charAt(ind);
}
if ((ind == qwe[0].length() - 1) && (ind <= step)) {
for (int ind2 = 0; ind2 < (step + 1 - ind); ind2++) {
newstr = newstr + "0";
}
}
} else {
if (ind == 0) {
newstr = newstr + "0.";
for (int ind3 = 0; ind3 > step + 1; ind3--) {
newstr = newstr + "0";
}
}
if (str.charAt(ind) != '.') {
newstr = newstr + str.charAt(ind);
}
}
}
value = newstr;
} else {
value = obj.toString();
}
return value;
}
жгем, товарищи! Double to String!
−121
Для каждого СтрГотИзд Из ГотовыеИзделия Цикл
СсылкаДСЕ = ОпределитьДСЕГотовоеИзделиеПоНаименованию(СтрГотИзд.Значение);
СсылкаЗаписьРС = НайтиПервуюЗаписьРС_ПоДСЕ(СсылкаДСЕ, ЭтотОбъект.НаДату);
Если СсылкаЗаписьРС = Неопределено Тогда
Предупреждение("На эту дату данных не существует!");
Иначе
ФормаИндикатора.КомментарийОбработкиДанных = "Построение отчета: " + СсылкаДСЕ.ВидПредмета + " - " + СсылкаДСЕ.Наименование + "";
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные1, 1, СсылкаДСЕ, СсылкаЗаписьРС.Применяемость, Неопределено, ФормаИндикатора);
Выборка2Ур = НайтиЗаписиРС_ПоКодуДСЕГл(СсылкаЗаписьРС.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка2Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные2, 2, Выборка2Ур.ДСЕВходящий, Выборка2Ур.Применяемость, Выборка2Ур, ФормаИндикатора);
Выборка3Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка2Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка3Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные3, 3, Выборка3Ур.ДСЕВходящий, Выборка3Ур.Применяемость, Выборка3Ур, ФормаИндикатора);
Выборка4Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка3Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка4Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные4, 4, Выборка4Ур.ДСЕВходящий, Выборка4Ур.Применяемость, Выборка4Ур, ФормаИндикатора);
Выборка5Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка4Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка5Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные5, 5, Выборка5Ур.ДСЕВходящий, Выборка5Ур.Применяемость, Выборка5Ур, ФормаИндикатора);
Выборка6Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка5Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка6Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные6, 6, Выборка6Ур.ДСЕВходящий, Выборка6Ур.Применяемость, Выборка6Ур, ФормаИндикатора);
Выборка7Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка6Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка7Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные7, 7, Выборка7Ур.ДСЕВходящий, Выборка7Ур.Применяемость, Выборка7Ур, ФормаИндикатора);
Выборка8Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка7Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка8Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные8, 8, Выборка8Ур.ДСЕВходящий, Выборка8Ур.Применяемость, Выборка8Ур, ФормаИндикатора);
Выборка9Ур = НайтиЗаписиРС_ПоКодуДСЕГл(Выборка8Ур.НомерЗаписиРСДСЕВх, НаДату).Выбрать();
Пока Выборка9Ур.Следующий() цикл
ОбластьДанныеДобавить(ПолеТабДок, ОбластьДанные9, 9, Выборка9Ур.ДСЕВходящий, Выборка9Ур.Применяемость, Выборка9Ур, ФормаИндикатора);
КонецЦикла;
КонецЦикла;
КонецЦикла;
КонецЦикла;
КонецЦикла;
КонецЦикла;
КонецЦикла;
КонецЦикла;
КонецЕсли;
КонецЦикла;
Функция НайтиЗаписиРС_ПоКодуДСЕГл(КодДСЕГл, НаДату, ДопустимаяЗамена = 0) Экспорт
Запрос = Новый Запрос;
Запрос.Текст =
"ВЫБРАТЬ
| СтруктураПриборов1СрезПоследних.ДСЕГлавный,
| СтруктураПриборов1СрезПоследних.ДСЕВходящий КАК ДСЕВходящий,
| СтруктураПриборов1СрезПоследних.Прибор,
| СтруктураПриборов1СрезПоследних.НомерЗаписиРСДСЕВх,
| СтруктураПриборов1СрезПоследних.НомерЗаписиРСДСЕГл,
| СтруктураПриборов1СрезПоследних.ДопустимаяЗамена,
| СтруктураПриборов1СрезПоследних.Применяемость,
| СтруктураПриборов1СрезПоследних.ДСЕВходящий.Ссылка,
| СтруктураПриборов1СрезПоследних.ДСЕВходящий.ВидПредмета КАК ВидПредмета,
| СтруктураПриборов1СрезПоследних.ДСЕВходящий.ВидПредмета.Порядок КАК ДСЕВходящийВидПредметаПорядок,
| СтруктураПриборов1СрезПоследних.ДСЕВходящий.Код КАК Код,
| СтруктураПриборов1СрезПоследних.Заимствованные,
| СтруктураПриборов1СрезПоследних.Период,
| СтруктураПриборов1СрезПоследних.ДатаОкончанияИспользования,
| СтруктураПриборов1СрезПоследних.ВводНового,
| СтруктураПриборов1СрезПоследних.ИзменениеСоставаИзделия
|ИЗ
| РегистрСведений.СтруктураПриборов1.СрезПоследних(
| &НаДату,
| НомерЗаписиРСДСЕГл = &КодДСЕГл
| И (ДатаОкончанияИспользования = &ПустаяДата
| ИЛИ ДатаОкончанияИспользования > &НаДату)
| И ДопустимаяЗамена = &ДопустимаяЗамена) КАК СтруктураПриборов1СрезПоследних
|
|УПОРЯДОЧИТЬ ПО
| ДСЕВходящийВидПредметаПорядок,
| Код";
Запрос.УстановитьПараметр("НаДату", НаДату);
Запрос.УстановитьПараметр("КодДСЕГл", КодДСЕГл);
Запрос.УстановитьПараметр("ПустаяДата", '00010101');
Запрос.УстановитьПараметр("ДопустимаяЗамена", ДопустимаяЗамена);
Возврат(Запрос.Выполнить());
КонецФункции
Прелесть! Выполняется около минуты. При чем этот код дублируется почти во всех отчетах.
После оптимизации объем кода сократился в 3 раза, а время выполнения составило 1-2 сек.
+16
//...
ret.value(_val != "" ? _val : "");
//...