- 1
С днём математика вас, питухи!
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
С днём математика вас, питухи!
+1
// если пользователь авторизован
if($user->get('id')) {
$_SESSION['city-select'] = '';
// если пользователь авторизован - определяем город
$profile = $user->getOne('Profile');
if ($profile) {
$city = $profile->get('city');
}
// проходим все города и ищем подходящий
$cities = $modx->runSnippet('pdoResources', array(
'parents' => 205,
'limit' => 0,
'includeTVs' => 'setCityForHome',
'where' => '{ "template" : "25" }',
'tpl' => '@CODE:{"id":"[[+id]]","city":"[[+tv.setCityForHome]]"}',
'outputSeparator' => ','
));
$redirectTo = 0;
if($cities) {
$cities = $modx->fromJson('['.$cities.']');
foreach( $cities as $c ) {
if($c['city'] == $city) {
$redirectTo = $c['id'];
break;
}
}
}
} else {
// если не авторизован - проверяем сессию
$session = $_SESSION['city-select'];
// если сессия пустая - проверяем, на какой странице находимся
// если страница города и пустая сессия - записываем в сессию
if($modx->resource->get('template') == 25) {
$_SESSION['city-select'] = $modx->resource->get('pagetitle');
$city = $modx->resource->get('pagetitle');
} else {
$city = (!empty($_SESSION['city-select']))? $_SESSION['city-select'] : $city;
}
}
Сумрачный гений, сука. Строки 11-28 особенно примечательны.
+1
program square;
var sep, input: string;
i, j, n, m : integer;
begin
write('sep:');
readln(sep);
write('str:');
readln(input);
for i:=1 to length(input) do write(input[i], ' ');
writeln();
for i:=2 to length(input)-1 do begin
write(input[i]);
for j:=1 to length(input)*2-3 do write (sep);
writeln(input[length(input) - i + 1]);
end;
for i:=0 to length(input)-1 do
write(input[length(input)-i], ' ');
end.
Написала на скучной лекции программку на телефоне, чтобы распечатывать
Х У Й
У У
Й У Х
+1
$query = "
SELECT
`version`, `mods`, `plugins`, `keywords`
WHERE
`version` = {$version}";
foreach (explode(",", $mods) as $mod)
{
$query += "AND `mods` LIKE '{$mod}' OR `mods` LIKE '{$mod},%' OR `mods` LIKE '%,{$mod},%' OR `mods` LIKE '%,{$mod}'";
}
foreach (explode(",", $plugins) as $plugin)
{
$query += "AND `plugins` LIKE '{$plugin}' OR `plugins` LIKE '{$plugin},%' OR `plugins` LIKE '%,{$plugin},%' OR `plugins` LIKE '%,{$plugin}'";
}
Говнокод чтобы прогнать массив с id записей внутри varchar по массиву с id записей из переменной (id,id,id)
+1
Просто оффтоп #17
#1: https://govnokod.ru/20162 https://govnokod.xyz/_20162
#2: https://govnokod.ru/25329 https://govnokod.xyz/_25329
#3: https://govnokod.ru/25415 https://govnokod.xyz/_25415
#4: (vanished) https://govnokod.xyz/_25472
#5: https://govnokod.ru/25693 https://govnokod.xyz/_25693
#6: (vanished) https://govnokod.xyz/_26649
#7: https://govnokod.ru/26672 https://govnokod.xyz/_26672
#8: https://govnokod.ru/26924 https://govnokod.xyz/_26924
#9: https://govnokod.ru/27072 https://govnokod.xyz/_27072
#10: https://govnokod.ru/27086 https://govnokod.xyz/_27086
#11: https://govnokod.ru/27122 https://govnokod.xyz/_27122
#12: https://govnokod.ru/27153 https://govnokod.xyz/_27153
#13: https://govnokod.ru/27159 https://govnokod.xyz/_27159
#14: https://govnokod.ru/27200 https://govnokod.xyz/_27200
#15: https://govnokod.ru/27237 https://govnokod.xyz/_27237
#16: https://govnokod.ru/27282 https://govnokod.xyz/_27282
+1
pubimbue, ate и ios
давайте ржать над крестостримами
+1
?check_trace(
begin
%% Inject some orderings to make sure the replicant
%% receives transactions in all states.
%%
%% 1. Commit some transactions before the replicant start:
?force_ordering(#{?snk_kind := trans_gen_counter_update, value := 5}, #{?snk_kind := state_change, to := disconnected}),
%% 2. Make sure the rest of transactions are produced after the agent starts:
?force_ordering(#{?snk_kind := subscribe_realtime_stream}, #{?snk_kind := trans_gen_counter_update, value := 10}),
%% 3. Make sure transactions are sent during TLOG replay:
?force_ordering(#{?snk_kind := state_change, to := bootstrap}, #{?snk_kind := trans_gen_counter_update, value := 15}),
%% 4. Make sure some transactions are produced while in normal mode
?force_ordering(#{?snk_kind := state_change, to := normal}, #{?snk_kind := trans_gen_counter_update, value := 25}),
...
Какой тест )))
+1
# PowerShell
switch ($true)
{
($firstNumber -gt $secondNumber) {Write-Output ("{0} > {1}" -F $firstNumber, $secondNumber)}
($firstNumber -eq $secondNumber) {Write-Output ("{0} == {1}" -F $firstNumber, $secondNumber)}
($firstNumber -lt $secondNumber) {Write-Output ("{0} < {1}" -F $firstNumber, $secondNumber)}
}
Интересный такой свитч-кейс (https://stackoverflow.com/questions/57063932/powershell-overriding-assignment-and-comparison-operators)
+1
#include <iostream>
template<typename T>
struct CrtpBase {
static float base_func()
{
std::cout << "CrtpBase::base_func(), " << typeid(T).name() << "::int_field == "
<< T::int_field << std::endl;
return 16.0f;
}
static inline float x = base_func();
};
struct A: public CrtpBase<A> {
void func_a()
{
base_func();
}
static inline int int_field = 16;
};
struct B : public CrtpBase<B> {
void func_b()
{
std::cout << "B::func_b(), no CrtpBase<B>::base_func() call" << std::endl;
}
};
int main()
{
A a;
a.func_a();
B b;
b.func_b();
}
[temp.inst]/2:
Unless a class template specialization is a declared specialization,
the class template specialization is implicitly instantiated when
the specialization is referenced in a context that requires a
completely-defined object type or when the completeness of the
class type affects the semantics of the program.
[temp.inst]/3:
The implicit instantiation of a class template specialization causes
(3.1) -- the implicit instantiation of the declarations, but not of the definitions, of
the non-deleted class member functions, member classes, scoped member enumerations,
static data members, member templates, and friends; and
(3.2) -- the implicit instantiation of the definitions of deleted member functions,
unscoped member enumerations, and member anonymous unions.
[temp.inst]/4:
Unless a member of a templated class is a declared specialization, the specialization
of the member is implicitly instantiated when the specialization is referenced in a
context that requires the member definition to exist or if the existence of the definition
of the member affects the semantics of the program; in particular, the initialization
(and any associated side effects) of a static data member does not occur unless the
static data member is itself used in a way that requires the definition of the static
data member to exist.
+1
namespace detail {
template<entity_event_t Event>
struct EventHasEntityStateConstructor {
// Sanity check
static_assert(static_cast<int32_t>(Event) >= 0
&& static_cast<int32_t>(Event) < ENTITY_EVENTS_COUNT);
private:
struct TwoChar {
char a, b;
};
template<typename T>
constexpr static TwoChar _check(
decltype(
T(std::declval<const entityState_t &>())
)*
);
template<typename T>
constexpr static char _check(...);
public:
constexpr inline static bool value = (sizeof(_check<EntityEvent<Event>>(nullptr)) == sizeof(TwoChar));
};
template<typename BusT, entity_event_t Event>
bool defaultEntityEventPublisher(const BusT & bus, const entityState_t & eventEntity)
{
static_assert(EventHasEntityStateConstructor<Event>::value,
"defaultEntityEventFactory<Event>() instantiated for a custom\n"
"event that does not have a (const entityState_t & eventEntity) constructor.\n"
"This should not happen (you'll get a more obscured compiler error anyway)!");
return bus.publishEmplace<EntityEvent<Event>>(eventEntity);
}
template<typename BusT, typename T, T... Is>
constexpr std::array<EntityEventPublisherPtr<BusT>, sizeof...(Is)>
createDefaultEntityEventFactories(std::integer_sequence<T, Is...>)
{
return {
[](auto i) -> EntityEventPublisherPtr<BusT> {
if constexpr (EventHasEntityStateConstructor<static_cast<entity_event_t>(i.value)>::value) {
return &defaultEntityEventPublisher<BusT, static_cast<entity_event_t>(i.value)>;
} else {
return nullptr;
}
}(std::integral_constant<T, Is>{})...
};
}
}
// An (event_number -> EntityState<event_number> 'publishing factory' function) mapping;
// if event N could not be constructed from a single entityState_t reference
// then this table would contain nullptr at the index N
template<typename BusT>
const std::array<EntityEventPublisherPtr<BusT>, ENTITY_EVENTS_COUNT> & getDefaultEntityEventsPublishers() noexcept
{
static auto factories = detail::createDefaultEntityEventFactories<BusT>(std::make_integer_sequence<int32_t, ENTITY_EVENTS_COUNT>());
return factories;
}
template<typename BusT>
EntityEventPublisherPtr<BusT> tryGetDefaultEntityEventPublisher(entity_event_t event) noexcept
{
auto eventNum = static_cast<int32_t>(event);
if (eventNum >= 0 && eventNum < ENTITY_EVENTS_COUNT) {
return getDefaultEntityEventsPublishers<BusT>()[eventNum];
} else {
return nullptr;
}
}