- 1
- 2
- 3
- 4
ДокументСсылка = парВыборка.Документ;
Если СокрЛП(ДокументСсылка) = "" Тогда
Продолжить;
КонецЕсли;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
ДокументСсылка = парВыборка.Документ;
Если СокрЛП(ДокументСсылка) = "" Тогда
Продолжить;
КонецЕсли;
А как вы проверяете на ПустуюСсылку?
+1
#include <iostream>
#include <cstdio>
namespace std {
namespace ios_base2 {
extern struct sync_with_stdio_t {
void h(bool sync = true) {
ios_base::sync_with_stdio(sync);
}
} sync_with_stdio;
}
}
int main() {
std::ios_base2::sync_with_stdio.h(false);
std::cout << "1";
printf("2");
std::cout << "3";
puts("");
return 0;
}
132
https://ideone.com/NkGYUL
+1
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
if (m == 1) return 0;
unsigned int _m = (unsigned int)(m);
unsigned long long r = 1;
unsigned long long y = safe_mod(x, m);
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
if (n <= 1) return false;
if (n == 2 || n == 7 || n == 61) return true;
if (n % 2 == 0) return false;
long long d = n - 1;
while (d % 2 == 0) d /= 2;
constexpr long long bases[3] = {2, 7, 61};
for (long long a : bases) {
long long t = d;
long long y = pow_mod_constexpr(a, t, n);
while (t != n - 1 && y != 1 && y != n - 1) {
y = y * y % n;
t <<= 1;
}
if (y != n - 1 && t % 2 == 0) {
return false;
}
}
return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
https://codeforces.com/contest/1508/submission/113222414
> if (n == 2 || n == 7 || n == 61) return true;
Помню я как делал: подобрал 3 базовых числа, прогнал на всех интах, там где алгоритм ошибался - проифал вручную )))
+1
// https://github.com/gcc-mirror/gcc/blob/b0c83d59f44bf677c8d74acae228acf32719acb3/libstdc%2B%2B-v3/include/bits/regex_compiler.tcc#L446
template<typename _TraitsT>
template<bool __icase, bool __collate>
bool
_Compiler<_TraitsT>::
_M_expression_term(pair<bool, _CharT>& __last_char,
_BracketMatcher<_TraitsT, __icase, __collate>& __matcher)
{
if (_M_match_token(_ScannerT::_S_token_bracket_end))
return false;
const auto __push_char = [&](_CharT __ch)
{
if (__last_char.first)
__matcher._M_add_char(__last_char.second);
else
__last_char.first = true;
__last_char.second = __ch;
};
const auto __flush = [&]
{
if (__last_char.first)
{
__matcher._M_add_char(__last_char.second);
__last_char.first = false;
}
};
if (_M_match_token(_ScannerT::_S_token_collsymbol))
{
auto __symbol = __matcher._M_add_collate_element(_M_value);
if (__symbol.size() == 1)
__push_char(__symbol[0]);
else
__flush();
}
else if (_M_match_token(_ScannerT::_S_token_equiv_class_name))
{
__flush();
__matcher._M_add_equivalence_class(_M_value);
}
else if (_M_match_token(_ScannerT::_S_token_char_class_name))
{
__flush();
__matcher._M_add_character_class(_M_value, false);
}
else if (_M_try_char())
__push_char(_M_value[0]);
// POSIX doesn't allow '-' as a start-range char (say [a-z--0]),
// except when the '-' is the first or last character in the bracket
// expression ([--0]). ECMAScript treats all '-' after a range as a
// normal character. Also see above, where _M_expression_term gets called.
//
// As a result, POSIX rejects [-----], but ECMAScript doesn't.
// Boost (1.57.0) always uses POSIX style even in its ECMAScript syntax.
// Clang (3.5) always uses ECMAScript style even in its POSIX syntax.
//
// It turns out that no one reads BNFs ;)
else if (_M_match_token(_ScannerT::_S_token_bracket_dash))
{
if (!__last_char.first)
{
if (!(_M_flags & regex_constants::ECMAScript))
{
if (_M_match_token(_ScannerT::_S_token_bracket_end))
{
__push_char('-');
return false;
}
__throw_regex_error(
regex_constants::error_range,
"Unexpected dash in bracket expression. For POSIX syntax, "
"a dash is not treated literally only when it is at "
"beginning or end.");
}
__push_char('-');
}
else
{
if (_M_try_char())
{
__matcher._M_make_range(__last_char.second, _M_value[0]);
__last_char.first = false;
}
else if (_M_match_token(_ScannerT::_S_token_bracket_dash))
{
__matcher._M_make_range(__last_char.second, '-');
__last_char.first = false;
}
else
{
if (_M_scanner._M_get_token()
!= _ScannerT::_S_token_bracket_end)
__throw_regex_error(
regex_constants::error_range,
"Character is expected after a dash.");
__push_char('-');
}
}
}
Читаю тут реализацию стандартной говнокрестовой библиотеки из GCC
Какой багор )))
+1
// https://github.com/j123123/sexpr_parse/blob/584fc23de71bebe02545214f819e16b720a2c1e2/my_struct_utils.c#L119
blob *
blob_scan_fromstream
(
FILE *stream
)
{
size_t st_len = 0;
size_t st_alloc;
uint8_t *st = NULL;
while(true)
{
const int fg = getc(stream);
if(fg == EOF)
{
PRV_ERR_MACRO();
}
uint8_t c = fg;
if(!isprint(fg))
{
PRV_ERR_MACRO();
}
switch(c)
{
case '\\':
{
int c2 = getc(stream);
switch(c2)
{
case 'x':
{
int c3[2] =
{
getc(stream),
getc(stream)
};
uint8_t tmp[2];
for(size_t i = 0; i < 2; ++i)
{
switch(c3[i])
{
case '0' ... '9':
tmp[i] = c3[i]-'0';
break;
case 'a' ... 'f':
tmp[i] = c3[i]+10-'a';
break;
case 'A' ... 'F':
tmp[i] = c3[i]+10-'A';
break;
default:
PRV_ERR_MACRO();
}
}
M_PUSH(tmp[1] | tmp[0] << 4);
}
break;
case '\\':
M_PUSH('\\');
break;
case 't':
M_PUSH('\t');
break;
case 'n':
M_PUSH('\n');
break;
case '"':
M_PUSH('"');
break;
default:
PRV_ERR_MACRO();
}
}
break;
// case '\t':
// case '\n':
// PRV_ERR_MACRO();
// break;
case '"':
goto end;
default:
M_PUSH(c);
}
}
end:
;
blob *tmp = blob_init(st_len, st);
PRV_FREE(st);
return tmp;
}
Эта вот хрень вычитывает из "FILE *" одно "слово".
+1
#include <stdio.h>
#define new(class) _##class##_##new
#define impl(class, method) _##class##_##method
struct Calculate
{
int(*getOne)(struct Calculate*);
};
int impl(Calculate, getOne)(struct Calculate* this) { return 1; }
void* new(Calculate)(void)
{
struct Calculate* class = malloc(sizeof(struct Calculate));
class->getOne = impl(Calculate, getOne);
return class;
}
struct CalculateProxy
{
struct Calculate;
};
int impl(CalculateProxy, getOne)(struct Calculate* this)
{
printf("Method call!\n");
return impl(Calculate, getOne)(this);
}
void* new(CalculateProxy)(void)
{
struct CalculateProxy* class = malloc(sizeof(struct CalculateProxy));
class->getOne = impl(CalculateProxy, getOne);
return class;
}
int main(void)
{
struct Calculate* calc = new(CalculateProxy)();
printf("%X!\n", calc->getOne(calc));
}
жавашок попросил реализовать паттерн прокси на Си
+1
npm install
очередной npm пакет с трояном
https://www.bleepingcomputer.com/news/security/popular-coa-npm-library-hijacked-to-steal-user-passwords/
+1
#include <string>
#include <type_traits>
#include <iostream>
template<int N> struct tag {};
template<typename T, int N>
struct loophole_t
{
friend auto loophole(tag<N>) { return T{}; };
};
#define BA(c) auto loophole(tag< (c) >);
#define Cb(c) BA(c) BA(c+1) BA(c+2) BA(c+3) BA(c+4)
#define KA(c) Cb(c) Cb(c+5) Cb(c+10) Cb(c+15) Cb(c+20)
#define ZDES(c) KA(c) KA(c+20) KA(c+40) KA(c+60) KA(c+80)
#define BACbKAZDES ZDES(0) ZDES(80) ZDES(160) ZDES(240) ZDES(300)
BACbKAZDES
template<int I>
struct wrp
{
int a;
};
int main(void)
{
sizeof(loophole_t<wrp<67>, 0>);
sizeof(loophole_t<wrp<66>, 1>);
sizeof(loophole_t<wrp<68>, 2>);
sizeof(loophole_t<wrp<99>, 3>);
sizeof(loophole_t<wrp<76>, 4>);
sizeof(loophole_t<wrp<66>, 5>);
sizeof(loophole_t<wrp<33>, 6>);
sizeof(loophole_t<wrp<73>, 7>);
sizeof(loophole_t<wrp<66>, 8>);
sizeof(loophole_t<wrp<68>, 9>);
sizeof(loophole_t<wrp<85>, 10>);
sizeof(loophole_t<wrp<70>, 11>);
sizeof(loophole_t<wrp<79>, 12>);
sizeof(loophole_t<wrp<99>, 13>);
sizeof(loophole_t<wrp<76>, 14>);
sizeof(loophole_t<wrp<66>, 15>);
sizeof(loophole_t<wrp<33>, 16>);
sizeof(loophole_t<wrp<109>, 17>);
sizeof(loophole_t<wrp<112>, 18>);
sizeof(loophole_t<wrp<119>, 19>);
sizeof(loophole_t<wrp<102>, 20>);
std::string nactenbka;
#define L(c, i) if(std::is_same< wrp< (c) >, decltype( loophole(tag< (i) >{}) )>::value) nactenbka.push_back((char)( c-1 ) );
#define O(c, i) L(c, i) L(c+1, i) L(c+2, i) L(c+3, i) L(c+4, i)
#define V(c, i) O(c, i) O(c+5, i) O(c+10,i) O(c+15,i) O(c+20,i)
#define E(c, i) V(c, i) V(c+20,i) V(c+40,i) V(c+60,i) V(c+80,i)
#define LOVE(c, i) E(c, i) V(c+80, i) V(c+100, i)
#define FORE(i) LOVE(0, i)
#define VER(i) FORE(i) FORE(i+1) FORE(i+2) FORE(i+3) FORE(i+4)
#define FOREVER VER(0) VER(5) VER(10) VER(15) FORE(20)
FOREVER
std::cout << nactenbka << std::endl;
return 0;
}
<3
+1
(** Set of all possible interleaving of two traces is a trace
ensemble. As we later prove in [interleaving_to_permutation], this
definition is dual to [Permutation]. *)
Inductive Interleaving : list TE -> list TE -> TraceEnsemble :=
| ilv_cons_l : forall te t1 t2 t,
Interleaving t1 t2 t ->
Interleaving (te :: t1) t2 (te :: t)
| ilv_cons_r : forall te t1 t2 t,
Interleaving t1 t2 t ->
Interleaving t1 (te :: t2) (te :: t)
| ilv_nil : Interleaving [] [] [].
Попытка оптимизации:
(* Left-biased version of [Interleaving] that doesn't make
distinction between schedulings of commuting elements: *)
Inductive UniqueInterleaving : list TE -> list TE -> TraceEnsemble :=
| uilv_cons_l : forall l t1 t2 t,
UniqueInterleaving t1 t2 t ->
UniqueInterleaving (l :: t1) t2 (l :: t)
| uilv_cons_r1 : forall l r t1 t2 t,
~trace_elems_commute l r ->
UniqueInterleaving (l :: t1) t2 (l :: t) ->
UniqueInterleaving (l :: t1) (r :: t2) (r :: l :: t)
| uilv_cons_r2 : forall r1 r2 t1 t2 t,
UniqueInterleaving t1 (r1 :: t2) (r1 :: t) ->
UniqueInterleaving t1 (r2 :: r1 :: t2) (r2 :: r1 :: t)
| uilv_nil : forall t, UniqueInterleaving [] t t.
Сложный говнокод. Почему вторая "оптимизированная" версия работает хуже первой?
+1
if (op.size() == 1)
{
if (op[0].id == LexemID::REGISTER)
{
if (isSIBbase(registerName2registerId.at( std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[0].lexemas))
});
}
else if (op[0].id == LexemID::LABEL_USE)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.disp = LabelUse(std::get<std::string>(op[0].lexemas))
});
else if (op[0].id == LexemID::NUMBER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.disp = Constant(std::get<int>(op[0].lexemas))
});
}
else if (op.size() == 3)
{
if (const auto operation = std::get<std::string>(op[1].lexemas)[0]; operation == '+')
{
if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::REGISTER)
{
if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas)),
.index = Register(std::get<std::string>(op[2].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[2].lexemas)),
.index = Register(std::get<std::string>(op[0].lexemas))
});
}
else if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::NUMBER)
{
if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas)),
.disp = Constant(std::get<int>(op[2].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[0].lexemas)),
.disp = Constant(std::get<int>(op[2].lexemas))
});
}
else if (op[0].id == LexemID::REGISTER && op[2].id == LexemID::LABEL_USE)
{
if (isSIBbase(registerName2registerId.at(std::get<std::string>(op[0].lexemas))))
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[0].lexemas)),
.disp = LabelUse(std::get<std::string>(op[2].lexemas))
});
else
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[0].lexemas)),
.disp = LabelUse(std::get<std::string>(op[2].lexemas))
});
}
}
else if (operation == '*')
{
if (op[0].id == LexemID::NUMBER && op[2].id == LexemID::REGISTER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas))
});
}
}
else if(op.size() == 5)
{
if (op[4].id == LexemID::REGISTER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.base = Register(std::get<std::string>(op[4].lexemas)),
.index = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas))
});
else if (op[4].id == LexemID::NUMBER)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas)),
.disp = Constant(std::get<int>(op[4].lexemas))
});
else if (op[4].id == LexemID::LABEL_USE)
mnemonic.mnemonics.emplace_back(IndirectAddress{
.index = Register(std::get<std::string>(op[2].lexemas)),
.scale = static_cast<uint8_t>(std::get<int>(op[0].lexemas)),
.disp = LabelUse(std::get<std::string>(op[4].lexemas))
});
...
чё к щам близко?
https://github.com/kcalbSphere/PVC-16/blob/master/pvc-asm/syntaxer.cpp