- 1
- 2
const regExp = new RegExp(filterValue.toLowerCase())
return templates.filter((tmpl) => regExp.test(tmpl.title.toLowerCase()))
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
const regExp = new RegExp(filterValue.toLowerCase())
return templates.filter((tmpl) => regExp.test(tmpl.title.toLowerCase()))
Высрал "синьор", "тимлид" с большим опытом и головой.
+1
var ER={}, x=new TextDecoder('KOI8-R').decode(Uint8Array.from( Array.apply(0,new Uint8Array(64).map( (_,b)=>b&1 ? 128+0x61+b/2 : 65+b/2 ))))
for (var i=0;i<64;i+=2){
if (i<52)
ER[x[ i ]] = x[i+1], ER[ x[i].toLowerCase() ] = x[i+1].toLowerCase()
ER[x[i+1]] = x[ i ], ER[x[i+1].toLowerCase()] = x[ i ].toLowerCase();
}
text=`<Налог>
<Наименование>НДС</Наименование>
<УчтеноВСумме>false</УчтеноВСумме>
</Налог>`
text.replace(/./g,(char,offset,text) => ER[char] || char);
Из юзерскрипта для транслитерации в обоих направлениях.
+1
// Задача: Рисовать в консоли прогресс бар, на сколько дней текущий год завершился
static void ProgressBarOfElapsedDays(DateTime dateTime, bool isRefreshebleat = false) // рефрешеБЛЕАТ! :))
{
int daysOfYear = DateTime.IsLeapYear(dateTime.Year) ? 366 : 365;
int dayInProcents = daysOfYear * 100 / 100; // WAT?
int currentDay = dateTime.DayOfYear * 100;
int daysOfYearNotElapsed = daysOfYear * 100 - currentDay; // Сложный матан
int procent = 100 - (daysOfYear * 100 - currentDay) / dayInProcents;
int buffer = 0;
if (isRefreshebleat)
{
if (Console.CursorTop >= 1 || Console.CursorLeft >= 1)
{
Console.SetCursorPosition(Console.CursorLeft - Console.CursorLeft, Console.CursorTop - Console.CursorTop); // когда Console.SetCursorPosition(0, 0) недостаточно
}
}
// остальной код
}
isRefreshebleat и всё остальное :))
+2
case Type::Instruction:
{
if (o == "movzwl") return OpCode::movzwl;
if (o == "movzbl") return OpCode::movzbl;
if (o == "shrb") return OpCode::shrb;
if (o == "shrl") return OpCode::shrl;
if (o == "xorl") return OpCode::xorl;
if (o == "andl") return OpCode::andl;
if (o == "ret") return OpCode::ret;
if (o == "movb") return OpCode::movb;
if (o == "cmpb") return OpCode::cmpb;
if (o == "movl") return OpCode::movl;
if (o == "jmp") return OpCode::jmp;
if (o == "testb") return OpCode::testb;
if (o == "incl") return OpCode::incl;
if (o == "sarl") return OpCode::sarl;
if (o == "decl") return OpCode::decl;
if (o == "jne") return OpCode::jne;
if (o == "je") return OpCode::je;
if (o == "js") return OpCode::js;
if (o == "subl") return OpCode::subl;
if (o == "subb") return OpCode::subb;
if (o == "addl") return OpCode::addl;
if (o == "addb") return OpCode::addb;
if (o == "sall") return OpCode::sall;
if (o == "orl") return OpCode::orl;
if (o == "andb") return OpCode::andb;
if (o == "orb") return OpCode::orb;
if (o == "decb") return OpCode::decb;
if (o == "incb") return OpCode::incb;
if (o == "rep") return OpCode::rep;
if (o == "notb") return OpCode::notb;
if (o == "negb") return OpCode::negb;
if (o == "sbbb") return OpCode::sbbb;
if (o == "pushl") return OpCode::pushl;
if (o == "retl") return OpCode::retl;
}
Фрагмент транслятора из ассемблера в ассемблер.
https://github.com/lefticus/x86-to-6502
+1
"Performance is easy. All you need to know is everything" (c) S. Kuksenko (@kuksenk0)
Умеете профилировать программы?
Знаете, что такое flame diagram? Умеете посмотреть стектрейс от входа в тред до какого-нить спинлока в ядре? Смотрите асм своего компилятора или джита? Знаете, какая инструкция сколько занимает?
Умеете по vmstat/iostat или xperf/perf counters увидать проблему и соотнести ее с программой? Используете dtrace голый или с instruments? yourkit? vTune? valgrind? bpf?
Или такие же дебилы, как я?
0
#include <stdlib.h>
#define printf() print()
int main(void)
{
int a = 0;
a = a++ + ++a;
print("I'm using macro that redefine printf() function (%d).", a);
return 0;
}
Ыыыыыыыы
суть говнокода же чтоб он собрал максимум красных цифр?
это не мой код честно!!!
−102
Всё. Петухи закончились. Всем спасибо, все свободны.
+1
template < typename T >
T shit (void)
{
return 0;
}
int main()
{
int crap = shit();
// Почему дедукция аргумента шаблона в данном случае не работает?
return crap;
}
//-------------------------------------
int shit (void)
{
return 0;
}
// Почему functions that differ only in their return type cannot be overloaded
double shit (void)
{
return 0;
}
int main()
{
int crap = shit();
return crap;
}
Почему плюсы такое говно?
0
#include <algorithm>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#define __CL_ENABLE_EXCEPTIONS
#include "cl.hpp"
using namespace std::string_literals;
int main(int argc, char * argv[]) {
size_t data_len = (1024 * 1024 * strtoul(argv[1], nullptr, 10)) / sizeof(uint32_t),
out_len = strtoul(argv[2], nullptr, 10),
iter = strtoul(argv[3], nullptr, 10),
block_size = strtoul(argv[4], nullptr, 10);
std::string src = R"(
typedef unsigned int uint32_t;
__kernel void bench(global const uint32_t * data, global uint32_t * out) {
uint32_t res = 0, id = get_global_id(0), next = id;
for(uint32_t i = 0; i < )"s + std::to_string(iter) + R"(; ++i) {
for(uint32_t j = 0; j < )" + std::to_string(block_size / sizeof(uint32_t)) + R"(; ++j)
res ^= data[next + j];
next = data[next];
}
out[id] = res;
}
)"s;
cl::Program::Sources sources = {{src.data(), src.size()}};
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
std::vector<uint32_t> data(data_len);
std::vector<uint32_t> out(out_len);
std::generate(std::begin(data), std::end(data), [=,gen = std::mt19937{}]() mutable {
return gen() % (data_len - (block_size / sizeof(uint32_t)));
});
for(auto & platform : platforms) {
std::cout << "Using platform: " << platform.getInfo<CL_PLATFORM_NAME>() << "\n";
std::vector<cl::Device> devices;
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
for(auto & device : devices) {
try {
std::cout << "Using device: " << device.getInfo<CL_DEVICE_NAME>() << "\n";
cl::Context ctx({device});
cl::Program program(ctx, sources);
program.build({device});
cl::Buffer data_buffer(ctx, CL_MEM_READ_WRITE, data.size() * sizeof(uint32_t));
cl::Buffer out_buffer(ctx, CL_MEM_READ_WRITE, out.size() * sizeof(uint32_t));
cl::CommandQueue queue(ctx, device);
queue.enqueueWriteBuffer(data_buffer, CL_TRUE, 0, data.size() * sizeof(uint32_t), data.data());
cl::make_kernel<cl::Buffer &, cl::Buffer &> bench(program, "bench");
cl::EnqueueArgs eargs(queue,cl::NullRange,cl::NDRange(out.size()),cl::NullRange);
auto start = std::chrono::high_resolution_clock::now();
bench(eargs, data_buffer, out_buffer).wait();
auto time = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now() - start).count();
size_t ops = out_len * iter;
size_t total_tp = ops * block_size;
double miops = (ops / time) / (1000 * 1000);
double tpgbps = (total_tp / time) / (1024 * 1024 * 1024);
fprintf(stderr, "Result: %.2fMIOPS, %.2fGB/s, %.2fsec\n", miops, tpgbps, time);
queue.enqueueReadBuffer(out_buffer, CL_TRUE, 0, out.size() * sizeof(uint32_t), out.data());
} catch(cl::Error e) {
std::cout << e.what() << " : " << e.err() << std::endl;
std::terminate();
}
}
}
}
Код Царя
https://www.linux.org.ru/forum/development/13489159
https://github.com/superhackkiller1997/gpu_mem_benchmark/blob/master/main.cpp
+2000
unsigned int get_spoofed() {
char spa[21];
int a, b, c, d;
srand(time(0));
random_ct = rand();
random_num = ((random_ct % 254) + 1);
a = random_num;
random_ct = rand();
random_num = ((random_ct % 254) + 1);
b = random_num;
random_ct = rand();
random_num = ((random_ct % 254) + 1);
c = random_num;
random_ct = rand();
random_num = ((random_ct % 254) + 1);
d = random_num;
snprintf(spa, sizeof(spa), "%d.%d.%d.%d", a, b, c, d);
return ((unsigned int)host2ip(spa));
}
Ддосбот для роутеров https://github.com/eurialo/lightaidra/blob/master/source/utils.c