- 1
https://m.reddit.com/r/cpp/comments/4pmlpz/what_the_iso_c_committee_added_to_the_c17_working/
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+2
https://m.reddit.com/r/cpp/comments/4pmlpz/what_the_iso_c_committee_added_to_the_c17_working/
Мне остаётся только спросить:
+3
void MyZKbMain::keyPressEvent(QKeyEvent* k)
{
QPixmap pm; pm.load("ruleta_usr.png");
ZConfig Num(QString("numeros.cfg"), true);
ZConfig Hist(QString("historial.cfg"), true);
switch (k->key())
{
case 0x1046: //Boton Verde
break;
case 0x1030: //Boton Verde
calcular=0;
reboot = new ZMessageDlg("zRoulette",
QString("Sistema Ubeda 0.5\nBasado en el Sistema de Cuadros\n\nwww.developermoto.com/es\nwww.modmymoto.com\n\n(C)2009 RacingLocura07, CepiPerez"),
(ZMessageDlg::MessageDlgType)2, 0, this,"about", true, 0);
reboot->setTitleIcon(pm); reboot->show();
break;
case 0x1031: //Boton Rojo
calcular=0;
reboot = new ZMessageDlg("zRoulette", "Desea salir?",
(ZMessageDlg::MessageDlgType)1, 0, this,"about", true, 0);
reboot->setTitleIcon(pm); reboot->show();
if(reboot->exec()==1) { exit(); }
else { update(); break; }
case 0x1012: //Tecla de Navegacion De Izquierda
calcular=0;
if (current > 1 ) { --current; update(); break; } else { break; }
case 0x1013: //Tecla de Navegacion De Arriba
calcular=0;
if ( current > 3 ) { ------current; update(); break; } else { break; }
case 0x1014: //Tecla de Navegacion De Derecha
calcular=0;
if (current < 36 ) { ++current; update(); break; } else { break; }
case 0x1015: //Tecla de Navegacion De Abajo
calcular=0;
if (current < 34 ) { ++++++current; update(); break; } else { break; }
case 0x1038: //Softkey Izquierda
calcular=0;
reboot = new ZMessageDlg("zRoulette", "Desea reinciar la Ruleta?", (ZMessageDlg::MessageDlgType)1, 0, this,"about", true, 0);
reboot->setTitleIcon(pm); reboot->show();
if(reboot->exec()==1) { system("rm numeros.cfg"); system("rm historial.cfg"); current = 1; jugadas = 0; lista.clear(); update(); break; }
else { update(); break; }
case 0x103a: //Softkey Derecha
int temp = Hist.readNumEntry ( QString("HISTORIAL"), QString("18"), 0 );
if ( temp != 0 ) {
reboot = new ZMessageDlg("zRoulette", "Desea limpiar las jugadas dejando las ultimas 18 solamente?",
(ZMessageDlg::MessageDlgType)1, 0, this,"about", true, 0); reboot->setTitleIcon(pm); reboot->show();
if(reboot->exec()==1) {
for ( int l=1; l<37; ++l) { Num.writeEntry ( QString("NUMEROS"), QString("%1").arg(l), QString("0") ); }
for ( int j=1; j<19; ++j) {
int temp = Hist.readNumEntry ( QString("HISTORIAL"), QString("%1").arg(j), 0 );
if ( temp > 0 ) { Num.writeEntry ( QString("NUMEROS"), QString("%1").arg(temp), QString("1") ); }
} calcular=1; update(); break;
} else { break; }
} else {
reboot = new ZMessageDlg("zRoulette", "Deben haber mas de 18 bolas jugadas para el reinicio parcial.",
(ZMessageDlg::MessageDlgType)2, 0, this,"about", true, 0); reboot->setTitleIcon(pm); reboot->show(); break;
}
case 0x1004: //Boton Central
valortemp = Num.readNumEntry(QString("NUMEROS"), QString("%1").arg(current), 0 );
if ( valortemp < 1 ) { valortemp=0; } ++valortemp;
Num.writeEntry(QString("NUMEROS"), QString("%1").arg(current), valortemp);
int lugar=0; for ( int j=18; j>0; --j)
{ int temp = Hist.readNumEntry ( QString("HISTORIAL"), QString("%1").arg(j), 0 ); if ( temp==0 ) { lugar=j; } }
if ( lugar > 0 ) {
Hist.writeEntry ( QString("HISTORIAL"), QString("%1").arg(lugar), QString("%1").arg(current) );
} else {
for ( int j=1; j<18; ++j) {
int temp = Hist.readNumEntry ( QString("HISTORIAL"), QString("%1").arg(j+1), 0 );
Hist.writeEntry ( QString("HISTORIAL"), QString("%1").arg(j), QString("%1").arg(temp) );
}
Hist.writeEntry ( QString("HISTORIAL"), QString("18"), QString("%1").arg(current) );
}
calcular=1;
update();
}
}
Разработчики из солнечной Аргентины. Кусочек кода из кастомного "лаунчера" для телефонов Motorola на платформе MotoMAGX (Linux 2.6.10, Qt 2.3.8, gcc 3.4.3). АДИЩЕ С ЦАРСКИМИ АНРОЛЛАМИ: https://github.com/crutchwalkfactory/motocakerteam/blob/master/Projects/MotoDesk/MyZKbMain.cpp
Что интересно, это всё как-то работало и даже довольно мило выглядело: http://exlmoto.ru/wp-content/Images/AOne/1.gif
+3
#include "stdafx.h"
#include <Windows.h>
#pragma comment(lib, "gdiplus.lib")
#include <gdiplus.h>
#include <vector>
#include <chrono>
wchar_t* path =
L"здесь был путь*";
using namespace Gdiplus;
using namespace std::chrono;
int main()
{
GdiplusStartupInput gdipInput;
ULONG_PTR gdipToken;
GdiplusStartup(&gdipToken, &gdipInput, NULL);
HWND progman = FindWindowW(L"Progman", NULL);
HWND workerw = GetWindow(progman, GW_HWNDPREV);
HDC dc = GetDC(workerw);
std::vector<Bitmap*> images;
WIN32_FIND_DATAW fdata = { 0 };
HANDLE hFind = FindFirstFileW(path, &fdata);
int
scrWidth = GetSystemMetrics(SM_CXSCREEN),
scrHeight = GetSystemMetrics(SM_CYSCREEN);
UINT width, height;
bool isInfoRetrieved = false;
std::wstring wmp(path);
wmp = wmp.substr(0, wmp.length() - 1);
do {
Bitmap* bmp = Bitmap::FromFile((wmp + fdata.cFileName).c_str());
if (bmp->GetLastStatus() != Gdiplus::Ok) continue;
int width = bmp->GetWidth();
int height = bmp->GetHeight();
double ratio = (double)width / height;
if (ratio > 1) {
width = scrWidth;
height = scrWidth / ratio;
}
else {
width = scrHeight * ratio;
height = scrHeight;
}
Bitmap* resized = new Bitmap(width, height, PixelFormat32bppRGB);
Graphics* resizedGr = Graphics::FromImage(resized);
resizedGr->DrawImage(bmp, 0, 0, width, height);
delete resizedGr;
delete bmp;
images.push_back(resized);
} while (FindNextFile(hFind, &fdata));
FindClose(hFind);
Graphics* mainGr = Graphics::FromHDC(dc);
Bitmap* bufBmp = new Bitmap(scrWidth, scrHeight, PixelFormat32bppRGB);
Graphics* bufGr = Graphics::FromImage(bufBmp);
int count = images.size();
int gap = 1000 / count;
while (true) {
for (auto it = images.begin(); it != images.end(); it++) {
milliseconds ms1 = duration_cast<milliseconds>(
system_clock::now().time_since_epoch());
Bitmap* bmp = *it;
int width = bmp->GetWidth();
int height = bmp->GetHeight();
int xOfs = (scrWidth - width) / 2, yOfs = (scrHeight - height) / 2;
bufGr->Clear(Color::Black);
bufGr->DrawImage(*it, xOfs, yOfs, width, height);
mainGr->DrawImage(bufBmp, 0, 0);
milliseconds ms2 = duration_cast<milliseconds>(
system_clock::now().time_since_epoch());
milliseconds delta = ms2 - ms1;
if (gap > delta.count())
Sleep(gap - delta.count());
}
}
return 0;
}
Код для рисования под иконками рабочего стола на винде
Да, в винде можно так делать
Нахуй никому не нужно, но выглядит заебись
+2
const size_t longstring_size = 1000500; // TODO: O RLY magic constant? => Can't load edges >= 1Mbp
char longstring[longstring_size];
Орфография комментариев сохранена.
+1
auto getMaxSize = [](const auto &vec) {
if (vec.size() == 0)
return 0;
const auto &max = *std::max_element(
vec.begin(),
vec.end(),
[](const auto &lhs, const auto &rhs){
return lhs.size() < rhs.size();
});
return max.size();
};
Раньше я не понимал актуальность шутки:
In C++14, you just write auto auto(auto auto) { auto; } The compiler infers the rest from context
+10
http://i.imgur.com/g5MswBc.png
Emotive programming in XCode
+2
#define QVERIFY2(statement, description) \
do {\
if (statement) {\
if (!QTest::qVerify(true, #statement, (description), __FILE__, __LINE__))\
return;\
} else {\
if (!QTest::qVerify(false, #statement, (description), __FILE__, __LINE__))\
return;\
}\
} while (0)
Код из QTest либы Qt4.
+4
data[idata].io_data[i % 4].data
Когда процессишь данные данных для данных
0
void Canvas::drawText(const char* text, SDL_Color sdlColor, int x, int y) const noexcept
{
if (!font)
throw std::runtime_error{"TTF_Font* is null"};
SDL_Surface* const sdlSurface =
::TTF_RenderText_Solid(const_cast<TTF_Font*>(font->getTtfFont()), text, sdlColor);
if (!sdlSurface)
throw std::runtime_error{"SDL_Surface* is null"};
SDL_Texture* const sdlTexture =
::SDL_CreateTextureFromSurface(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlSurface);
if (!sdlTexture)
throw std::runtime_error{"SDL_Texture* is null"};
const SDL_Rect srcrect{0, 0, sdlSurface->w, sdlSurface->h};
const SDL_Rect dstrect{x, y, sdlSurface->w, sdlSurface->h};
::SDL_FreeSurface(sdlSurface);
::SDL_RenderCopy(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlTexture,
&srcrect, &dstrect);
::SDL_DestroyTexture(sdlTexture);
}
+5
template<typename T>
T* sanitize(T* p)
{
return reinterpret_cast<T*>(
reinterpret_cast<uintptr_t>(p) & ~(alignof(T)-1));
}
template<typename T>
constexpr size_t avaliable_width()
{
switch(alignof(T))
{
case 1: return 0;
case 2: return 1;
case 4: return 2;
case 8: return 3;
case 16: return 4;
case 32: return 5;
case 64: return 6;
case 128: return 7;
case 256: return 8;
default: return 0;
}
}
template<size_t bit, typename T>
T* set_tag(T* p, bool tagged = true)
{
static_assert(bit < avaliable_width<T>(), "bad_width");
if(tagged) {
return reinterpret_cast<T*>(
reinterpret_cast<uintptr_t>(p) | 1 << bit);
}
return reinterpret_cast<T*>(
reinterpret_cast<uintptr_t>(p) & ~(uintptr_t(1) << bit));
}
template<size_t bit, typename T>
bool get_tag(T* p)
{
static_assert(bit < avaliable_width<T>(), "bad_width");
return reinterpret_cast<uintptr_t>(p) >> bit & 1;
}
Младшие биты указателей на выравненные типы всегда нулевые. Из за этого (по формуле Шеннона) указатель несёт в себе меньше информации, оставаясь того же размера. Битоёбов это расстраивает.