- 1
https://github.com/pustladi/Windows-2000
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
https://github.com/pustladi/Windows-2000
давайте обсуждать срцы винд
+1
// https://habr.com/ru/post/440388/
// Интервалы: грядущая эволюция C++
// Давайте теперь рассмотрим следующую задачу: имеется вектор, необходимо удалить
// из него все повторяющиеся элементы. В рамках текущего стандарта мы решали бы её так:
std::vector<T> vec=...;
std::sort( vec.begin(), vec.end() );
vec.erase( std::unique( vec.begin(), vec.end() ), vec.end() );
// При этом мы указываем имя вектора аж 6 раз! Однако, используя концепцию интервалов
// (объединив итераторы на начало и конец вектора в один объект), можно написать в разы проще, указав искомый вектор лишь единожды:
tc::unique_inplace( tc::sort(vec) );
//... Че, серьезно? Я так тоже могу:
// Однако, используя сишный препроцессор™, можно написать в разы проще, указав искомый вектор лишь единожды:
#define DELETE_DUPS(x) do{ std::sort( x.begin(), x.end() ); x.erase( x::unique( x.begin(), x.end() ), x.end() );}while(0)
DELETE_DUPS(vec);
Тоже мне революция.
+2
-- Pipe Elbow ****************************************************************************
pipe_elbow = util.table.deepcopy(data.raw["storage-tank"]["storage-tank"])
pipe_elbow.name = "pipe-elbow"
pipe_elbow.icon = "__Flow Control__/graphics/icon/pipe-elbow.png"
pipe_elbow.minable = data.raw["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"].minable
pipe_elbow.corpse = "small-remnants"
pipe_elbow.max_health = data.raw["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"].max_health
pipe_elbow.resistances = data.raw["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"].resistances
pipe_elbow.fast_replaceable_group = data.raw["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"].fast_replaceable_group
pipe_elbow.collision_box = data.raw["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"].collision_box
pipe_elbow.selection_box = data.raw["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"]["pipe"].selection_box
Пип Еблов.
Factorio mod Flow Control_3.0.3
--Завышеное ЧСВ или самолюбование?
+1
// https://habr.com/post/428846/
// Работа со строками на этапе компиляции в современном C++
// Определим статическую строку как массив символов, для удобства будем считать, что строка всегда оканчивается нулевым символом:
template<size_t Size>
using static_string = std::array<const char, Size>;
constexpr static_string<6> hello = {'H', 'e', 'l', 'l', 'o', '\0'};
constexpr auto hello = make_static_string("hello");
// Здесь нам поможет одна из форм вариативного шаблона, которая позволяет развернуть
// шаблонные аргументы как индексы для агрегатной инициализации нашей статической
// строки из строкового литерала:
template<size_t Size, size_t ... Indexes>
constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const char (& str)[Size]) {
return {str[Indexes] ..., '\0'};
}
constexpr auto hello = make_static_string<0, 1, 2, 3, 4>("hello"); // hello == "hello"
// ...
//Будем сравнивать строки посимвольно, пока не выявим различия, либо не достигнем конца хотя бы одной из строк.
// Поскольку constexpr for еще не изобрели, воспользуемся рекурсией и тернарным оператором:
template<size_t Size1, size_t Size2>
constexpr int static_string_compare(
const static_string<Size1>& str1,
const static_string<Size2>& str2,
int index = 0) {
return index >= Size1 && index >= Size2 ? 0 :
index >= Size1 ? -1 :
index >= Size2 ? 1 :
str1[index] > str2[index] ? 1 :
str1[index] < str2[index] ? -1 :
static_string_compare(str1, str2, index + 1);
}
Ммм, какой БАГОР
Крестобляди опять накостылили какой-то параши на шаблонах и радуются
+2
//macrolib.h
#ifndef MACRO_LIB
#define MACRO_LIB
#include <stdio.h>
typedef void proc(void);
#ifdef DEBUG
#define TRACE printf
#else
#define TRACE(...)
#endif
#ifdef TRACE_CALLS
#define ON_ENTER_TRACE(name) char __CUR_FUNC_NAME__[] = #name; TRACE("<entering %s>", __CUR_FUNC_NAME__);
#define ON_EXIT_TRACE(...) TRACE(__VA_ARGS__)
#else
#define ON_ENTER_TRACE(name) ;
#define ON_EXIT_TRACE(...)
#endif
#define def(type, name, ...) type name __VA_ARGS__ { ON_ENTER_TRACE(name)
#define ret(ret_val) {ON_EXIT_TRACE("<leaving %s>", __CUR_FUNC_NAME__); return ret_val;}
#define end(ret_val) ret(ret_val);}
#define with(type, x, on_exit) { type __CUR_WITH_VAR__ = x; int (*__ON_EXIT__)() = (int(*)())on_exit;
#define endwith __ON_EXIT__(__CUR_WITH_VAR__);}
#define dup(d, ...) __VA_ARGS__ d __VA_ARGS__
#define dupwithcomma(...) __VA_ARGS__, __VA_ARGS__
#endif
//chain.h
#ifdef I0
#undef I0
#if defined(I1) || defined(I2) || defined(I3)
ELEMENT DELIMETER
#include "chain.h"
#else
ELEMENT
#undef ELEMENT
#undef DELIMETER
#endif
#else
#ifdef I1
#undef I1
#define I0
ELEMENT DELIMETER
#include "chain.h"
#else
#ifdef I2
#undef I2
#define I1
#define I0
ELEMENT DELIMETER
#include "chain.h"
#else
#ifdef I3
#undef I3
#define I2
#define I1
#define I0
ELEMENT DELIMETER
#include "chain.h"
#endif
#endif
#endif
#endif
//test.c
#define DEBUG
#define TRACE_CALLS
#include "macrolib.h"
def(int, main, ())
printf(dup(" ", "%s"), dupwithcomma("Чот мне понравилось макроёбить..."));
FILE *f = fopen("file", "w");
with(FILE*, f, fclose)
fputs(
#define ELEMENT "o"
#define DELIMETER "l"
#define I3
#define I2
#define I1
#define I0
#include "chain.h"
, f
);
endwith
end(0)
Мне понравилось. то ещё можно намакроёбить? ;D
−2
Ваш почтовый сервер говно.
Я 2 часа ждал подтверждения регистрации на мыло гугла.
Но вот на fakemailgenerator.com оно пришло спустя 2 минуты.
ПЫХАПЭ - говно.
+4
DWORD NEAR _fastcall RgbCompare(RGBQUAD rgb1, RGBQUAD rgb2)
{
DWORD sum=0;
//
// lets do some majic shit so the compiler generates "good" code.
//
#define SUMSQ(a,b) \
if (a > b) \
sum += (WORD)(a-b) * (WORD)(a-b); \
else \
sum += (WORD)(b-a) * (WORD)(b-a);
SUMSQ(rgb1.rgbRed, rgb2.rgbRed);
SUMSQ(rgb1.rgbGreen, rgb2.rgbGreen);
SUMSQ(rgb1.rgbBlue, rgb2.rgbBlue);
return sum;
}
Как сложно, оказывается, посчитать (a-b)² на Си. Нужно каждый раз писать макрос для этой операции...
−1
def $qmark = 1
def ? = 1
// Error:(2, 6) method ? is defined twice
Scala-way
0
Тем временем на переднем крае вореционной науки: https://arxiv.org/pdf/1806.08462.pdf
0
// https://github.com/google/brotli/blob/29dc2cce9090d6c92c908116e11373bc7fdc8ad1/c/enc/static_dict.c#L82
/* Transforms "" + BROTLI_TRANSFORM_IDENTITY + <suffix> */
if (s[0] == ' ') {
AddMatch(id + n, l + 1, l, matches);
if (s[1] == 'a') {
if (s[2] == ' ') {
AddMatch(id + 28 * n, l + 3, l, matches);
} else if (s[2] == 's') {
if (s[3] == ' ') AddMatch(id + 46 * n, l + 4, l, matches);
} else if (s[2] == 't') {
if (s[3] == ' ') AddMatch(id + 60 * n, l + 4, l, matches);
} else if (s[2] == 'n') {
if (s[3] == 'd' && s[4] == ' ') {
AddMatch(id + 10 * n, l + 5, l, matches);
}
}
} else if (s[1] == 'b') {
if (s[2] == 'y' && s[3] == ' ') {
AddMatch(id + 38 * n, l + 4, l, matches);
}
} else if (s[1] == 'i') {
if (s[2] == 'n') {
if (s[3] == ' ') AddMatch(id + 16 * n, l + 4, l, matches);
} else if (s[2] == 's') {
if (s[3] == ' ') AddMatch(id + 47 * n, l + 4, l, matches);
}
} else if (s[1] == 'f') {
if (s[2] == 'o') {
if (s[3] == 'r' && s[4] == ' ') {
AddMatch(id + 25 * n, l + 5, l, matches);
}
} else if (s[2] == 'r') {
if (s[3] == 'o' && s[4] == 'm' && s[5] == ' ') {
AddMatch(id + 37 * n, l + 6, l, matches);
}
}
} else if (s[1] == 'o') {
if (s[2] == 'f') {
if (s[3] == ' ') AddMatch(id + 8 * n, l + 4, l, matches);
} else if (s[2] == 'n') {
if (s[3] == ' ') AddMatch(id + 45 * n, l + 4, l, matches);
}
} else if (s[1] == 'n') {
if (s[2] == 'o' && s[3] == 't' && s[4] == ' ') {
AddMatch(id + 80 * n, l + 5, l, matches);
}
} else if (s[1] == 't') {
if (s[2] == 'h') {
if (s[3] == 'e') {
if (s[4] == ' ') AddMatch(id + 5 * n, l + 5, l, matches);
} else if (s[3] == 'a') {
if (s[4] == 't' && s[5] == ' ') {
AddMatch(id + 29 * n, l + 6, l, matches);
}
}
} else if (s[2] == 'o') {
if (s[3] == ' ') AddMatch(id + 17 * n, l + 4, l, matches);
}
} else if (s[1] == 'w') {
if (s[2] == 'i' && s[3] == 't' && s[4] == 'h' && s[5] == ' ') {
AddMatch(id + 35 * n, l + 6, l, matches);
}
}
} else if (s[0] == '"') {
AddMatch(id + 19 * n, l + 1, l, matches);
if (s[1] == '>') {
AddMatch(id + 21 * n, l + 2, l, matches);
}
} else if (s[0] == '.') {
AddMatch(id + 20 * n, l + 1, l, matches);
if (s[1] == ' ') {
AddMatch(id + 31 * n, l + 2, l, matches);
if (s[2] == 'T' && s[3] == 'h') {
if (s[4] == 'e') {
if (s[5] == ' ') AddMatch(id + 43 * n, l + 6, l, matches);
} else if (s[4] == 'i') {
if (s[5] == 's' && s[6] == ' ') {
AddMatch(id + 75 * n, l + 7, l, matches);
}
}
}
}
} else if (s[0] == ',') {
AddMatch(id + 76 * n, l + 1, l, matches);
if (s[1] == ' ') {
AddMatch(id + 14 * n, l + 2, l, matches);
}
} else if (s[0] == '\n') {
AddMatch(id + 22 * n, l + 1, l, matches);
if (s[1] == '\t') {
AddMatch(id + 50 * n, l + 2, l, matches);
}
} else if (s[0] == ']') {
AddMatch(id + 24 * n, l + 1, l, matches);
} else if (s[0] == '\'') {
AddMatch(id + 36 * n, l + 1, l, matches);
} else if (s[0] == ':') {
AddMatch(id + 51 * n, l + 1, l, matches);
Какая-то непонятная херота из архиватора Brotli с кучей магических констант, которые хрен знает что означают. Очевидно, этот код должен находить в текстовых данных какие-то часто встречающиеся куски текста, и таким образом сжимать эту хрень (т.н. словарный метод сжатия) но зачем все так пиздануто рассовывать по буквам в куче if() ?
Не могли для этого каких-нибудь ГОМОИКОН сделать?