- 1
- 2
- 3
- 4
- 5
- 6
- 7
const gearIcon = new Vivus(
'gears',
{
type: 'delayed',
duration: 200
}
);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
const gearIcon = new Vivus(
'gears',
{
type: 'delayed',
duration: 200
}
);
+2
public static int booleanToInt(Boolean value) {
int res;
if (value == null) {
res = 0;
} else {
if (value) {
res = 1;
} else {
res = 0;
}
}
return res;
}
Добро пожаловать к нам в индийскую школу программирования!
+1
// https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/global/qglobal.h?h=v5.13.1#n1017
#if __cplusplus >= 201703L
// Use C++17 if statement with initializer. User's code ends up in a else so
// scoping of different ifs is not broken
#define Q_FOREACH(variable, container) \
for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
_container_.i != _container_.e; ++_container_.i) \
if (variable = *_container_.i; false) {} else
#else
// Explanation of the control word:
// - it's initialized to 1
// - that means both the inner and outer loops start
// - if there were no breaks, at the end of the inner loop, it's set to 0, which
// causes it to exit (the inner loop is run exactly once)
// - at the end of the outer loop, it's inverted, so it becomes 1 again, allowing
// the outer loop to continue executing
// - if there was a break inside the inner loop, it will exit with control still
// set to 1; in that case, the outer loop will invert it to 0 and will exit too
#define Q_FOREACH(variable, container) \
for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
_container_.control && _container_.i != _container_.e; \
++_container_.i, _container_.control ^= 1) \
for (variable = *_container_.i; _container_.control; _container_.control = 0)
#endif
А можно ли свой foreach сделать через какую-нибудь шаблонопарашу? Или тут, как обычно, нужна гомоиконность?
0
Пиздец-оффтоп #22
#1: https://govnokod.ru/26503 https://govnokod.xyz/_26503
#2: https://govnokod.ru/26541 https://govnokod.xyz/_26541
#3: https://govnokod.ru/26583 https://govnokod.xyz/_26583
#4: https://govnokod.ru/26689 https://govnokod.xyz/_26689
#5: https://govnokod.ru/26784 https://govnokod.xyz/_26784
#5: https://govnokod.ru/26839 https://govnokod.xyz/_26839
#6: https://govnokod.ru/26986 https://govnokod.xyz/_26986
#7: https://govnokod.ru/27007 https://govnokod.xyz/_27007
#8: https://govnokod.ru/27023 https://govnokod.xyz/_27023
#9: https://govnokod.ru/27098 https://govnokod.xyz/_27098
#10: https://govnokod.ru/27125 https://govnokod.xyz/_27125
#11: https://govnokod.ru/27129 https://govnokod.xyz/_27129
#12: https://govnokod.ru/27184 https://govnokod.xyz/_27184
#13: https://govnokod.ru/27286 https://govnokod.xyz/_27286
#14: https://govnokod.ru/27298 https://govnokod.xyz/_27298
#15: https://govnokod.ru/27322 https://govnokod.xyz/_27322
#16: https://govnokod.ru/27328 https://govnokod.xyz/_27328
#17: https://govnokod.ru/27346 https://govnokod.xyz/_27346
#18: https://govnokod.ru/27374 https://govnokod.xyz/_27374
#19: https://govnokod.ru/27468 https://govnokod.xyz/_27468
#20: https://govnokod.ru/27469 https://govnokod.xyz/_27469
#21: https://govnokod.ru/27479 https://govnokod.xyz/_27479
+1
IT Оффтоп #97
#67: https://govnokod.ru/27049 https://govnokod.xyz/_27049
#68: https://govnokod.ru/27061 https://govnokod.xyz/_27061
#69: https://govnokod.ru/27071 https://govnokod.xyz/_27071
#70: https://govnokod.ru/27097 https://govnokod.xyz/_27097
#71: https://govnokod.ru/27115 https://govnokod.xyz/_27115
#72: https://govnokod.ru/27120 https://govnokod.xyz/_27120
#73: https://govnokod.ru/27136 https://govnokod.xyz/_27136
#74: https://govnokod.ru/27160 https://govnokod.xyz/_27160
#75: https://govnokod.ru/27166 https://govnokod.xyz/_27166
#76: https://govnokod.ru/27168 https://govnokod.xyz/_27168
#77: https://govnokod.ru/27186 https://govnokod.xyz/_27186
#78: https://govnokod.ru/27219 https://govnokod.xyz/_27219
#79: https://govnokod.ru/27254 https://govnokod.xyz/_27254
#80: https://govnokod.ru/27270 https://govnokod.xyz/_27270
#81: https://govnokod.ru/27280 https://govnokod.xyz/_27280
#82: https://govnokod.ru/27284 https://govnokod.xyz/_27284
#83: https://govnokod.ru/27296 https://govnokod.xyz/_27296
#84: https://govnokod.ru/27336 https://govnokod.xyz/_27336
#85: https://govnokod.ru/27381 https://govnokod.xyz/_27381
#86: https://govnokod.ru/27405 https://govnokod.xyz/_27405
#87: https://govnokod.ru/27429 https://govnokod.xyz/_27429
#88: https://govnokod.ru/27432 https://govnokod.xyz/_27432
#89: https://govnokod.ru/27435 https://govnokod.xyz/_27435
#90: https://govnokod.ru/27439 https://govnokod.xyz/_27439
#91: https://govnokod.ru/27449 https://govnokod.xyz/_27449
#92: https://govnokod.ru/27460 https://govnokod.xyz/_27460
#93: https://govnokod.ru/27463 https://govnokod.xyz/_27463
#94: https://govnokod.ru/27466 https://govnokod.xyz/_27466
#95: https://govnokod.ru/27473 https://govnokod.xyz/_27473
#96: https://govnokod.ru/27478 https://govnokod.xyz/_27478
+5
#include <unistd.h>
#include <stdio.h>
#include <limits.h>
template<size_t Size> struct static_string {char data[Size];};
template<size_t ... Indexes>struct index_sequence {};
template<size_t Size, size_t ... Indexes>
constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const static_string<Size>& str,index_sequence<Indexes ...>) {return {str.data[Indexes] ..., '\0'};}
constexpr static_string<1> make_static_string() {return {'\0'};}
template<size_t Size, size_t ... Indexes>
struct make_index_sequence : make_index_sequence<Size - 1, Size - 1, Indexes ...> {};
template<size_t Size>
constexpr static_string<Size> make_static_string(const char (& str)[Size]) {return make_static_string(str, make_index_sequence<Size - 1>{});}
template<size_t ... Indexes>
struct make_index_sequence<0, Indexes ...> : index_sequence<Indexes ...> {};
template<size_t Size, size_t ... Indexes>
constexpr static_string<sizeof ... (Indexes) + 1> make_static_string(const char (& str)[Size],index_sequence<Indexes ...>) {return {str[Indexes] ..., '\0'};}
template<size_t Size>
constexpr size_t static_string_find(const static_string<Size>& str, char ch, size_t from, size_t nth) {return Size < 2 || from >= Size - 1 ? UINT_MAX :str.data[from] != ch ? static_string_find(str, ch, from + 1, nth) :nth > 0 ? static_string_find(str, ch, from + 1, nth - 1) : from;}
template<size_t Size>
constexpr size_t static_string_find_0(const static_string<Size>& str, char ch, size_t from, size_t nth) {return Size < 2 || from >= Size - 1 ? 0 : str.data[from] != ch ? static_string_find_0(str, ch, from + 1, nth) :nth > 0 ? static_string_find(str, ch, from + 1, nth - 1) : from;}
template<size_t Size1, size_t ... Indexes1, size_t Size2, size_t ... Indexes2>
constexpr static_string<Size1 + Size2 - 1> static_string_concat_2(const static_string<Size1>& str1, index_sequence<Indexes1 ...>,const static_string<Size2>& str2, index_sequence<Indexes2 ...>) {return {str1.data[Indexes1] ..., str2.data[Indexes2] ..., '\0'};}
template<size_t Size1, size_t Size2>
constexpr static_string<Size1 + Size2 - 1> static_string_concat_2(const static_string<Size1>& str1, const static_string<Size2>& str2) {return static_string_concat_2(str1, make_index_sequence<Size1 - 1>{},str2, make_index_sequence<Size2 - 1>{});}
template<size_t Begin, size_t End, size_t ... Indexes>
struct make_index_subsequence : make_index_subsequence<Begin, End - 1, End - 1, Indexes ...> {};
template<size_t Pos, size_t ... Indexes>
struct make_index_subsequence<Pos, Pos, Indexes ...> : index_sequence<Indexes ...> {};
template<size_t Begin, size_t End, size_t Size>
constexpr static_string<End - Begin + 1> static_string_substring(const static_string<Size>& str) {return make_static_string(str, make_index_subsequence<Begin, End>{});}
template<size_t Begin, size_t Size>
constexpr static_string<Size - Begin> static_string_suffix(const static_string<Size>& str) {return static_string_substring<Begin, Size - 1>(str);}
#define remove_underscore(arg) ([] () __attribute__((always_inline)) {constexpr auto a = static_string_find(make_static_string(arg),'_',0,0) == UINT_MAX? make_static_string(arg):static_string_concat_2(static_string_concat_2(static_string_substring<0,static_string_find_0(make_static_string(arg),'_',0,0)>(make_static_string(arg)),static_string_suffix<static_string_find_0(make_static_string(arg),'_',0,0)+1>(make_static_string(arg))),make_static_string("\0"));return a;}().data)
int main()
{
puts(remove_underscore("_testtest"));
puts(remove_underscore("test_test"));
puts(remove_underscore("testtest_"));
}
Убогий constexpr в c++11
−1
На этом ресурсе неоднократно появляются "говнокоды" с кривым форматированием.
Не всё что криво отформатированно, является говнокодом с точки зрения самого кодирования.
Отчасти такие коды - ето копипаст из лаб студентов,
которых заставили скопипастнуть свой код в какой-нибудь отчет, а возиться с вордовской версткой мало кому охота ага).
О том, что формат doc(x) для сорцов мало подходит, мало каких преподов волнует. Им отчет же нужно показать комиссии.
Столкнулась с этим после неоднократных переделок лаб по предметам, связанным с программированием.
+3
#include <stdio.h>
#include <stdlib.h>
#define DEREF(x) ({*(x);})
#define PTR(x) ({&(x);})
#define PTR_T(x) typeof(typeof(x) *)
#define DEREF_T(x) typeof( ({typeof(x) DEREF_T; *DEREF_T;}) )
void add5(PTR_T(int) a)
{
DEREF(a)+= 5;
}
int main(void)
{
int a = 0;
printf("%d\n", a);
add5(PTR(a));
printf("%d\n", a);
int b = 5;
PTR_T(b) b_p = PTR(b); // int *
printf("%d\n", DEREF(b_p) );
DEREF_T(b_p) c = 666; // int
printf("%d", c);
return EXIT_SUCCESS;
}
https://govnokod.ru/27476#comment637183
ASD_77:
потому что я люблю Си и С++ но ненажижу * и & ... поэтому я решил исправить этот недочет в мире
Исправил, проверь. Компилится только в GCC, всё-таки Clang не 100% совместим c гнутыми расширениями.
+1
function main() {
let a = 10;
function f() {
print(a);
}
f();
print("done.");
}
С виду этот простой кодик - это то что не может С и я так долго трахался что бы смочь его проимлементировать.... но я бля сделал
+1
dirty_boostrap_test() ->
SourceTab = ets:new(source, [public, named_table]),
ReplicaTab = ets:new(replica, [public, named_table]),
%% Insert some initial data:
ets:insert(source, {1, 1}),
ets:insert(source, {2, 2}),
ets:insert(source, {3, 3}),
try
register(testcase, self()),
Replica = spawn_link(fun replica/0),
register(replica, Replica),
%% "importer" process emulates mnesia_tm:
spawn_link(fun importer/0),
%% "bootstrapper" process emulates bootstrapper server:
spawn_link(fun bootstrapper/0),
receive
done ->
SrcData = lists:sort(ets:tab2list(source)),
RcvData = lists:sort(ets:tab2list(replica)),
?assertEqual(SrcData, RcvData)
end
after
ets:delete(SourceTab),
ets:delete(ReplicaTab)
end.
importer() ->
Ops = [ {write, 3, 3}
, {write, 4, 4}
, {write, 4, 5}
, {delete, 2}
],
lists:map(fun(OP) ->
import_op(source, OP),
%% Imitate mnesia event (note: here we send it
%% directly to the replica process bypassing
%% the agent):
replica ! {tlog, OP}
end,
Ops),
replica ! last_trans.
replica() ->
receive
{bootstrap, K, V} ->
ets:insert(replica, {K, V}),
replica();
bootstrap_done ->
replay()
end.
replay() ->
receive
{tlog, Op} ->
import_op(replica, Op),
replay();
last_trans ->
testcase ! done
end.
import_op(Tab, {write, K, V}) ->
ets:insert(Tab, {K, V});
import_op(Tab, {delete, K}) ->
ets:delete(Tab, K).
bootstrapper() ->
{Keys, _} = lists:unzip(ets:tab2list(source)),
[replica ! {bootstrap, K, V} || K <- Keys, {_, V} <- ets:lookup(source, K)],
replica ! bootstrap_done.
Follow-up к треду про то, как делать снепшоты.