- 1
http://www.quizful.net/interview/java/k4gCs7Qmf8YF
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+133
http://www.quizful.net/interview/java/k4gCs7Qmf8YF
Мне кажется, или кто то накурился?
если я не прав - обьяните(
+164
function ПечатьТоварногоЧека($com, $x) {
echodos(" [{$x['in']['НомерЗаказа']}] ");
$Сделка=$this->app->Документы->ЗаказПокупателя->НайтиПоНомеру($x['in']["НомерЗаказа"], $this->settime(time()));
d(__LINE__);
$Док2=$this->app->Документы->ПлатежноеТребованиеВыставленное->СоздатьДокумент();
$doctime=time();
$Док2->Дата=$this->settime($doctime);
d(__LINE__);
$Док2->Заполнить($Сделка);//Заполняем по счету
$ДД=$this->app->ЗаполнениеДокументов;
d(__LINE__);
$ДД->ЗаполнитьШапкуДокументаПоОснованию($Док2, $Сделка);
$this->app->УправлениеДенежнымиСредствами->ЗаполнитьПриходПоОснованию($Док2,
$Сделка, $this->app->ПараметрыСеанса->ТекущийПользователь);
d(__LINE__);
$this->app->УправлениеДенежнымиСредствами->ЗаполнитьРеквизитыРасчетногоДокумента($Док2,
$this->app->ПараметрыСеанса->ТекущийПользователь,
$this->app->Константы->ВалютаРегламентированногоУчета->Получить(),
$Док2->РасшифровкаПлатежа);
d(__LINE__);
$this->app->УправлениеДенежнымиСредствами->УстановитьСтатьюДДСПоУмолчанию(
$Док2->РасшифровкаПлатежа->Получить(0),
$Док2->ВидОперации);
d(__LINE__);
$Док2->ВидПлатежа = "Электронно";
$Док2->ИННПолучателя = $Док2->Организация->ИНН;
$Док2->КПППолучателя = $Док2->Организация->КПП;
$Док2->ИННПлательщика = $Док2->Контрагент->ИНН;
d(__LINE__);
$ДД=$Док2->РасшифровкаПлатежа->Получить(0);
$ДД->Сделка = $Сделка;
d(__LINE__);
$Док2->Комментарий=$Док2->Комментарий."*Создана с сайта по требованию клиента";
d(__LINE__);
echodos(" [\$x['in']['Сумма']={$x['in']['Сумма']}] ");
d(__LINE__);
echodos(" [\$Сделка->СуммаДокумента={$Сделка->СуммаДокумента}] ");
d(__LINE__);
echodos(" [\$Док2->СуммаДокумента={$Док2->СуммаДокумента}] ");
d(__LINE__);
Связь с 1С. файл на 5к строк подобного говна
−119
use strict;
use warnings;
my ($i, $j) = (42, 13);
my $max = [ $i => $j ]->[ $i <= $j ];
print "max: $max\n";
Вот-так вот: http://ideone.com/2Rd3Mr
// Вроди где-то в PBP этот пример даже есть
+164
//見積画面からの再セット
function forminput2(part_no,qty,index) {
if ( index == "1" ) {
document.forms[0].PRTNO_1.value = part_no;
document.forms[0].QTY_1.value = qty;
} else if ( index == "2" ) {
document.forms[0].PRTNO_2.value = part_no;
document.forms[0].QTY_2.value = qty;
} else if ( index == "3" ) {
document.forms[0].PRTNO_3.value = part_no;
document.forms[0].QTY_3.value = qty;
} else if ( index == "4" ) {
document.forms[0].PRTNO_4.value = part_no;
document.forms[0].QTY_4.value = qty;
} else if ( index == "5" ) {
document.forms[0].PRTNO_5.value = part_no;
document.forms[0].QTY_5.value = qty;
} else if ( index == "6" ) {
document.forms[0].PRTNO_6.value = part_no;
document.forms[0].QTY_6.value = qty;
} else if ( index == "7" ) {
document.forms[0].PRTNO_7.value = part_no;
document.forms[0].QTY_7.value = qty;
} else if ( index == "8" ) {
document.forms[0].PRTNO_8.value = part_no;
document.forms[0].QTY_8.value = qty;
} else if ( index == "9" ) {
document.forms[0].PRTNO_9.value = part_no;
document.forms[0].QTY_9.value = qty;
} else if ( index == "10" ) {
document.forms[0].PRTNO_10.value = part_no;
document.forms[0].QTY_10.value = qty;
} else if ( index == "11" ) {
document.forms[0].PRTNO_11.value = part_no;
document.forms[0].QTY_11.value = qty;
} else if ( index == "12" ) {
document.forms[0].PRTNO_12.value = part_no;
document.forms[0].QTY_12.value = qty;
} else if ( index == "13" ) {
document.forms[0].PRTNO_13.value = part_no;
document.forms[0].QTY_13.value = qty;
} else if ( index == "14" ) {
document.forms[0].PRTNO_14.value = part_no;
document.forms[0].QTY_14.value = qty;
} else if ( index == "15" ) {
document.forms[0].PRTNO_15.value = part_no;
document.forms[0].QTY_15.value = qty;
} else if ( index == "16" ) {
document.forms[0].PRTNO_16.value = part_no;
document.forms[0].QTY_16.value = qty;
} else if ( index == "17" ) {
document.forms[0].PRTNO_17.value = part_no;
document.forms[0].QTY_17.value = qty;
} else if ( index == "18" ) {
document.forms[0].PRTNO_18.value = part_no;
document.forms[0].QTY_18.value = qty;
} else if ( index == "19" ) {
document.forms[0].PRTNO_19.value = part_no;
document.forms[0].QTY_19.value = qty;
} else if ( index == "20" ) {
document.forms[0].PRTNO_20.value = part_no;
document.forms[0].QTY_20.value = qty;
} else if ( index == "21" ) {
document.forms[0].PRTNO_21.value = part_no;
document.forms[0].QTY_21.value = qty;
} else if ( index == "22" ) {
document.forms[0].PRTNO_22.value = part_no;
document.forms[0].QTY_22.value = qty;
} else if ( index == "23" ) {
document.forms[0].PRTNO_23.value = part_no;
document.forms[0].QTY_23.value = qty;
} else if ( index == "24" ) {
document.forms[0].PRTNO_24.value = part_no;
document.forms[0].QTY_24.value = qty;
} else if ( index == "25" ) {
document.forms[0].PRTNO_25.value = part_no;
document.forms[0].QTY_25.value = qty;
} else if ( index == "26" ) {
document.forms[0].PRTNO_26.value = part_no;
document.forms[0].QTY_26.value = qty;
} else if ( index == "27" ) {
document.forms[0].PRTNO_27.value = part_no;
document.forms[0].QTY_27.value = qty;
} else if ( index == "28" ) {
document.forms[0].PRTNO_28.value = part_no;
document.forms[0].QTY_28.value = qty;
} else if ( index == "29" ) {
document.forms[0].PRTNO_29.value = part_no;
document.forms[0].QTY_29.value = qty;
} else if ( index == "30" ) {
document.forms[0].PRTNO_30.value = part_no;
document.forms[0].QTY_30.value = qty;
} else if ( index == "31" ) {
document.forms[0].PRTNO_31.value = part_no;
document.forms[0].QTY_31.value = qty;
} else if ( index == "32" ) {
document.forms[0].PRTNO_32.value = part_no;
document.forms[0].QTY_32.value = qty;
} else if ( index == "33" ) {
document.forms[0].PRTNO_33.value = part_no;
Каталог на сайте http://www.kawasaki-motors.com
Из одного фрейма передаются массив номеров запчастей в другой фрейм, в котором заполняется форма и отправляется.
Таких функций там несколько.
Вроде серьёзная фирма.
+12
struct c_test
{
int value;
c_test(void)
{
(void)new (this) c_test (10);
}
c_test(int v)
{
value = v;
}
};
+132
#define max 0x08 //Max number of samples to average/filter
#define byte unsigned char
#define word unsigned int
#define dword unsigned long
#define FILTER 0
#define AVG 1
typedef struct {
word reading[max];
word result[max];
} ResultStct;
static ResultStct x;
static char samp = 0;//filter;
const byte filter_mode = FILTER;
extern int avg_result;
void MYfilter(word input_sample)
{
byte j;
dword X;
x.reading[samp] = input_sample;
if(samp>0){
X=0;
for (j=0;j<=samp;j++){
X += x.reading[j];
}
avg_result = (X >> 3) - 0x0200;
}
// Shift array of results if we hit max
if (samp >= max-1) {
for (j=0;j<max-1;j++){
x.result[j] = x.result[j+1];
x.reading[j] = x.reading[j+1];
}
samp = max-1;
}
else
{
samp++;
} //end if (i => max)
Такой вот МОЩНЕЙШИЙ фильтр встретился в одном проекте.
−101
@implementation NSString (toint)
- (long long)toInt {
if (self == nil) return 0;
if (self.length == 0) return 0;
return [self longLongValue];
}
@end
В этом коде все прекрасно. Я просто оставлю это здесь. Джава головного мозга.
+7
namespace engine { namespace ui { class Console; } }
class Dummy
{
engine::ui::Console * _ptr;
};
Решение проблемы с перекрёстными #include, когда классы должны хранить указатели друг на друга. Простое объявление class engine::ui::Console; не работает.
Не в первый раз сталкиваюсь с этой проблемой из-за примитивной системы импорта.
+138
uint32_t multiply (uint16_t a, uint16_t b)
{
return ((a & ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0 ) +
((a & ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1 ) +
((a & ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2 ) +
((a & ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3 ) +
((a & ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4 ) +
((a & ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5 ) +
((a & ( (int16_t)( ( b & (1 << 6) ) << 9 ) ) / ( 1 << 15) ) << 6 ) +
((a & ( (int16_t)( ( b & (1 << 7) ) << 8 ) ) / ( 1 << 15) ) << 7 ) +
((a & ( (int16_t)( ( b & (1 << 8) ) << 7 ) ) / ( 1 << 15) ) << 8 ) +
((a & ( (int16_t)( ( b & (1 << 9) ) << 6 ) ) / ( 1 << 15) ) << 9 ) +
((a & ( (int16_t)( ( b & (1 <<10) ) << 5 ) ) / ( 1 << 15) ) << 10) +
((a & ( (int16_t)( ( b & (1 <<11) ) << 4 ) ) / ( 1 << 15) ) << 11) +
((a & ( (int16_t)( ( b & (1 <<12) ) << 3 ) ) / ( 1 << 15) ) << 12) +
((a & ( (int16_t)( ( b & (1 <<13) ) << 2 ) ) / ( 1 << 15) ) << 13) +
((a & ( (int16_t)( ( b & (1 <<14) ) << 1 ) ) / ( 1 << 15) ) << 14) +
((a & ( (int16_t)( ( b & (1 <<15) ) << 0 ) ) / ( 1 << 15) ) << 15);
}
Умножение двух чисел через битовые маски и сдвиги без условных переходов. Компилятор переведет деление инта на сдвинутую единчку в арифметический сдвиг
Использование ">>" применительно к signed типам - implementation defined http://stackoverflow.com/questions/4009885/arithmetic-bit-shift-on-a-signed-integer/4009922
+86
procedure TForm1.Colorize;
procedure SetStr(var s: string; const Style: TFontStyles; const Color, BackColor: Byte);
var
Format: TCharFormat2;
begin
If s<>'' Then
begin
FillChar(Format, SizeOf(Format), 0);
Format.cbSize := SizeOf(Format);
Format.dwMask:= CFM_BACKCOLOR or CFM_COLOR;
Format.crBackColor:= GetIRCColor(BackColor, True);
Format.crTextColor:= GetIRCColor(Color);
if RichEdit1.HandleAllocated then
SendMessage(RichEdit1.Handle, EM_SETCHARFORMAT, SCF_SELECTION,
LPARAM(@Format));
RichEdit1.SelAttributes.Style:= Style;
RichEdit1.SelText:= s;
RichEdit1.SelAttributes.Assign(RichEdit1.DefAttributes);
s:= ''
end;
end;
var
Color, BackColor: Byte;
Style: TFontStyles;
CurrStr: string;
I: Integer;
begin
Style:= [];
Color:= DefForeColor;
BackColor:= DefBackColor;
CurrStr:= '';
I:= 0;
While (I<Length(Str))do
begin
Inc(I);
case Str[I] of
#31:
begin
SetStr(CurrStr, Style, Color, BackColor);
If fsUnderLine in Style Then
Exclude(Style, fsUnderLine)
else
Include(Style, fsUnderLine);
end;
#2:
begin
SetStr(CurrStr, Style, Color, BackColor);
If fsBold in Style Then
Exclude(Style, fsBold)
else
Include(Style, fsBold);
end;
#15, #13:
begin
SetStr(CurrStr, Style, Color, BackColor);
Color:= DefForeColor;
BackColor:= DefBackColor;
end;
#3:
begin
SetStr(CurrStr, Style, Color, BackColor);
Inc(I);
Color:= DefForeColor;
If (Str[I] in ['0', '1'..'9'])Then
begin
Color:= StrToInt(Str[I]);
Inc(I);
If (Str[I] in ['0', '1'..'9'])Then
begin
Color:= StrToInt(IntToStr(Color)+Str[I]);
Inc(I)
end;
end;
If Str[I] = ',' Then //BackColor
begin
BackColor:= DefBackColor;
Inc(I);
If (Str[I] in ['0', '1'..'9'])Then
begin
BackColor:= StrToInt(Str[I]);
Inc(I);
If (Str[I] in ['0', '1'..'9'])Then
begin
BackColor:= StrToInt(IntToStr(BackColor)+Str[I]);
Inc(I)
end;
end;
end;
Dec(I)
end;
else
CurrStr:= CurrStr+Str[I]
end;
end;
SetStr(CurrStr, Style, Color, BackColor);
end;
Процедура раскрашивающая текст из Log-файла mIRC загруженого в TRichEdit на форме.
function GetIRCColor(const Color: Byte; const Back: Boolean=False): TColor;
begin
case Color of
0: Result:= clWhite;
1: Result:= clBlack;
2: Result:= clNavy;
3: Result:= clGreen;
4: Result:= clRed;
5: Result:= clMaroon;
6: Result:= clPurple;
7: Result:= $000080FF;
8: Result:= clYellow;
9: Result:= clLime;
10: Result:= clTeal;
11: Result:= clAqua;
12: Result:= clBlue;
13: Result:= clFuchsia;
14: Result:= clGray;
15: Result:= clSilver;
else
begin
If Back Then
Result:= clWhite
else
Result:= clBlack
end;
end;
end;