- 1
- 2
- 3
- 4
- 5
void tick(void)
{
for (auto&& x : registry.objects)
(x? std::function<void(void)>([&](void) {((IObject*)(x))->tick(); }) : [&]() {})();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
void tick(void)
{
for (auto&& x : registry.objects)
(x? std::function<void(void)>([&](void) {((IObject*)(x))->tick(); }) : [&]() {})();
}
Мозг сказал что "((IObject*)(x))->tick();" написать слишком сложно и повелел написать вот это.
+3
int main()
{
+ ! - ! -- -- ! + ! - - - ++ ~ - ! -- -- -- ~ ~ ~ ++ ++ ++ - ~ ++ - * - - -
* ++ * * ++ * -- -- -- -- - * -- + * ++ ++ ++ ++ ++ * ++ * -- -- * -- - *
BRAINFUCK;
return 0;
}
https://ideone.com/EtK1J4
Ответ на https://govnokod.ru/26910. Теперь с реальной конпеляцией в нативный код.
+4
// https://govnokod.ru/26890#comment571155
// bormand 2 часа назад #
// Можно брейнфак запилить на операторах. Как раз вроде унарных хватает.
// & * - ~ ! -- + ++ --
#include <array>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <limits>
struct Brainfuck {
public:
using IPType = uint16_t;
constexpr static size_t MAX_MEMORY = std::numeric_limits<IPType>::max();
std::array<uint8_t, MAX_MEMORY> memory{};
std::vector<char> app{};
IPType ip = 0;
IPType cell = 0;
IPType find_matching_tag(IPType cur_ip, char open, char close, int ip_direction)
{
size_t stack_size = 0;
do {
if (app[cur_ip] == close) {
--stack_size;
}
if (app[cur_ip] == open) {
++stack_size;
}
cur_ip += ip_direction;
} while (stack_size > 0);
return cur_ip - ip_direction;
}
IPType find_matching_close_tag(IPType cur_ip)
{
return find_matching_tag(cur_ip, '[', ']', 1);
}
IPType find_matching_open_tag(IPType cur_ip)
{
return find_matching_tag(cur_ip, ']', '[', -1);
}
void loop_open()
{
if (memory[cell] == 0) {
ip = find_matching_close_tag(ip);
} else {
++ip;
}
}
void loop_close()
{
if (memory[cell] != 0) {
ip = find_matching_open_tag(ip);
} else {
++ip;
}
}
void exec(char op)
{
switch (op) {
case '>': ++cell; break;
case '<': --cell; break;
case '+': ++memory[cell]; break;
case '-': --memory[cell]; break;
case '.': std::putchar(memory[cell]); break;
case ',': memory[cell] = static_cast<uint8_t>(std::getchar()); break;
case '[': loop_open(); return; // no ip advancing
case ']': loop_close(); return; // no ip advancing
}
ip++;
}
void run()
{
while (ip < app.size()) {
exec(app[ip]);
}
}
public:
Brainfuck & operator++() { app.push_back('>'); return *this; }
Brainfuck & operator--() { app.push_back('<'); return *this; }
Brainfuck & operator+() { app.push_back('+'); return *this; }
Brainfuck & operator-() { app.push_back('-'); return *this; }
Brainfuck & operator*() { app.push_back('.'); return *this; }
Brainfuck & operator&() { app.push_back(','); return *this; }
Brainfuck & operator!() { app.push_back('['); return *this; }
Brainfuck & operator~() { app.push_back(']'); return *this; }
Brainfuck & operator>>(const Brainfuck &) { run(); return *this; }
};
https://wandbox.org/permlink/XJUKGyb4YbnBVwOI
Бонус («99 bottles of beer»): https://pastebin.com/s4sBK9nX (взято с https://github.com/fabianishere/brainfuck/blob/master/examples/bottles-1.bf).
0
q)\l sp.q
+`p`city!(`p$`p1`p2`p3`p4`p5`p6`p1`p2;`london`london`london`london`london`lon..
(`s#+(,`color)!,`s#`blue`green`red)!+(,`qty)!,900 1000 1200
+`s`p`qty!(`s$`s1`s1`s1`s2`s3`s4;`p$`p1`p4`p6`p2`p2`p4;300 200 100 400 200 300)
https://code.kx.com/q/learn/tour/
+1
void Argument::parseAsInt()
{
auto res = std::from_chars(data.data(), data.data() + data.size(), dataInt);
if (res.ec == std::errc()) {
setTypeFlag(ArgType::Int);
}
}
void Argument::parseAsFloat()
{
// Rww: gcc still does not support float from_chars(), lol
const char *begin = data.data();
const char *end = begin + data.size();
char *endPtr = nullptr;
dataFloat = std::strtof(begin, &endPtr);
if (endPtr == end || dataFloat != 0.0f) {
setTypeFlag(ArgType::Float);
} else {
for (const char *it = endPtr; it < end; it++) {
if (!std::isspace(*it)) {
return;
}
}
setTypeFlag(ArgType::Float);
}
}
Говнокодил тут недавно, долго думал, что считать числом (пет, ТЗ нет). В конце-концов решил считать всё, что можно распарсить.
−1
// https://habr.com/ru/company/ruvds/blog/515676/
Разбор худшего в мире куска кода.
+1
/// Checks if the token is number or not
bool is_number(char* test_val)
{
const char* ROW = "0123456789\0";
for (int i = 0; i < strlen(test_val); i++) {
for (int j = 0; j < strlen(ROW); j++) {
if (test_val[i] == ROW[j]) {
goto next;
}
}
return false;
next:
}
return true;
}
Попытка проверить строку на число в Си.
+1
//--------------------------------------------------------------------------------------------------------------------\\
float max_rotation = record->m_pEntity->GetMaxBodyRotation();
auto animstate = ent->m_PlayerAnimState();
float resolve_value = 50.f; //не трогайте это, так и должно быть
if (!record->m_pState)
return;
const auto info = g_anims.GetAnimationInfo(record->m_pEntity);
if (!info)
return;
float eye_yaw = record->m_pState->m_flEyeYaw;
if (max_rotation < resolve_value)
resolve_value = max_rotation;
data->m_extending = record->m_pLayers[3].m_cycle == 0.f && record->m_pLayers[3].m_weight == 0.f;
float Delta = AngleDiff(ent->m_angEyeAngles().y, animstate->m_flGoalFeetYaw);
//--------------------------------------------------------------------------------------------------------------------\\
RESOLVERPART
//--------------------------------------------------------------------------------------------------------------------\\
if (data->m_extending)
resolve_value = max_rotation;
if (ent->m_AnimOverlay()[13].m_weight + 14.250f > 0.54)
{
if (ent->m_AnimOverlay()[3].m_cycle > 0.12)
{
if (ent->m_AnimOverlay()[13].m_cycle > 0.43)
{
animstate->m_flGoalFeetYaw = ent->m_angEyeAngles().y;
}
}
}
if (data->m_extending)
{
if (Delta <= 0)
{
animstate->m_flGoalFeetYaw = Delta * resolve_value;
}
else if (Delta > 0)
{
animstate->m_flGoalFeetYaw = Delta * -resolve_value;
}
}
else if (ent->m_AnimOverlay()[7].m_order == record->m_pLayers[7].m_order)
{
if (ent->m_AnimOverlay()[7].m_cycle > 0.5f)
{
animstate->m_flGoalFeetYaw = math::NormalizeYaw(record->m_pEntity->m_flLowerBodyYawTarget()) + get_max_desync_delta;
return;
}
else
animstate->m_flGoalFeetYaw = record->m_pEntity->m_angEyeAngles().y;
}
if (record->m_bDidShot)
info->m_flBrute = Resolver::ResolveShot(data, record);
//--------------------------------------------------------------------------------------------------------------------\\
BRUTEFORCE PART
//--------------------------------------------------------------------------------------------------------------------\\
else {
float lbyt = record->m_pEntity->m_flLowerBodyYawTarget();
data->m_delta = std::abs(math::NormalizedAngle(eye_yaw - lbyt));
float resolve_yaw = ((data->m_delta < 0.f) ? resolve_value : resolve_value);
switch (data->m_missed_shots % 3) {
case 0:
info->m_flBrute = data->m_last_resolve = resolve_yaw;
break;
case 1:
info->m_flBrute = -data->m_last_resolve;
break;
case 2:
info->m_flBrute = 0;
break;
}
}
record->m_pState->m_flGoalFeetYaw = eye_yaw + info->m_flBrute;
//--------------------------------------------------------------------------------------------------------------------\\
best resolver
+2
lea esi, cpu_name
mov eax, 0
mov mreg, eax
;[04/12] G
mov eax, 0ffh
and eax, ebx
mov mreg, eax
mov al, byte ptr [mreg]
mov [esi], al
inc esi
;[03/12] e
mov eax, 0ff00h
and eax, ebx
mov mreg, eax
mov al, byte ptr [mreg + 1]
mov [esi], al
inc esi
;[02/12] n
mov eax, 0ff0000h
and eax, ebx
mov mreg, eax
mov al, byte ptr [mreg + 2]
mov [esi], al
inc esi
;[01/12] u
mov eax, 0ff000000h
and eax, ebx
mov mreg, eax
mov al, byte ptr [mreg + 3]
mov [esi], al
inc esi
;[08/12] i
mov eax, 0ffh
and eax, edx
mov mreg, eax
mov al, byte ptr [mreg]
mov [esi], al
inc esi
;[07/12] n
mov eax, 0ff00h
and eax, edx
mov mreg, eax
mov al, byte ptr [mreg + 1]
mov [esi], al
inc esi
;[06/12] e
mov eax, 0ff0000h
and eax, edx
mov mreg, eax
mov al, byte ptr [mreg + 2]
mov [esi], al
inc esi
;[05/12] I
mov eax, 0ff000000h
and eax, edx
mov mreg, eax
mov al, byte ptr [mreg + 3]
mov [esi], al
inc esi
;[12/12] n
mov eax, 0ffh
and eax, ecx
mov mreg, eax
mov al, byte ptr [mreg]
mov [esi], al
inc esi
;[11/12] t
mov eax, 0ff00h
and eax, ecx
mov mreg, eax
mov al, byte ptr [mreg + 1]
mov [esi], al
inc esi
;[10/12] e
mov eax, 0ff0000h
and eax, ecx
mov mreg, eax
mov al, byte ptr [mreg + 2]
mov [esi], al
inc esi
;[09/12] l
mov eax, 0ff000000h
and eax, ecx
mov mreg, eax
mov al, byte ptr [mreg + 3]
mov [esi], al
inc esi
−1
public function index()
{
$items = CartManager::getAllItems();
$couponCode = Coupon::getFromSession()->implode('code', ', ');
$address = auth()->user()->address;
$user = auth()->user();
$userDetails = auth()->user() ? auth()->user()->fields : null;
$fields = [
'promo_code' => $couponCode,
'email' => $user->email,
'first_name' => $userDetails->firstname,
'last_name' => $userDetails->lastname,
'phone' => $userDetails->phone,
];
if ($address) {
$field = [
'value' => $address->city->title
];
if ($address->city->type === \App\Address::TYPE_CITY) {
$field ['data']['city_fias_id'] = $address->city->id;
$field ['data']['city'] = $address->city->title;
} elseif ($address->city->type === \App\Address::TYPE_SETTLEMENT) {
$field ['data']['settlement_fias_id'] = $address->city->id;
$field ['data']['settlement'] = $address->city->title;
}
$fields ['delivery_city'] = $field;
}
if ($address->street) {
$fields ['delivery_street'] = [
'value' => $address->street->title,
'data' => [
'street_fias_id' => $address->street->id,
]
];
}
if ($address->street_number) {
$fields ['delivery_house_number'] = [
'value' => $address->street_number,
];
}
if ($address->flat) {
$fields ['delivery_flat_number'] = $address->flat;
}
$fields = (object)$fields;
$actions = [
'remove' => route('shop.cart.remove'),
'remove_gift_card' => route('shop.cart.gift-cards.remove'),
'change' => route('shop.cart.update'),
'promo' => route('shop.coupon.apply'),
'checkout' => route('orders.store'),
'get_pickups' => route('delivery_points.index'),
'check_email' => route('check_email'),
];
return view('shop.cart.index', compact(
'items',
'address',
'couponCode',
'fields',
'actions'
));
}
this is MVC, baby !