Skip to content

Instantly share code, notes, and snippets.

@b-epelbaum
b-epelbaum / priority_timed_task_queue.h
Last active March 7, 2024 18:12
Stackable Qt task queue with single timer
#include <functional>
#include <queue>
#include <chrono>
#include <memory>
#include <tuple>
#include <QTimer>
#include <QDateTime>
namespace Helpers
@b-epelbaum
b-epelbaum / safe_cpp.h
Last active August 10, 2023 18:13
Embracing Safe C++ examples
template <typename A, typename B, typename Result = decltype(std::declval<const A&>() + std::declval<const B&>())>
Result loggedSum(const A& a, const B& b)
{
Result result = a + b; // no duplication of the decltype expression
LOG_TRACE << a << " + " << b << "=" << result;
return result;
}
//-------------------------------------------------------------------
class IdCollection
@b-epelbaum
b-epelbaum / create_elevated_process_as_logged_user.cpp
Created July 8, 2023 21:14
Start an elevated process impersonified by currently logged user
BOOL Helpers::create_elevated_process_as_logged_user(const wchar_t* lpApplicationName, wchar_t* lpCommandLine)
{
BOOL ret_val = FALSE;
if (const DWORD session_id = WTSGetActiveConsoleSessionId(); session_id != 0xFFFFFFFF)
{
HANDLE h_token = nullptr;
if (WTSQueryUserToken(session_id, &h_token))
{
HANDLE h_token_dup = nullptr;
if (DuplicateTokenEx(h_token, TOKEN_ALL_ACCESS, nullptr, SecurityImpersonation, TokenPrimary, &h_token_dup))
@b-epelbaum
b-epelbaum / VPN On Adnroid 13
Created April 30, 2023 11:29
How enable XAUTH / MSCHAP VPN on Android 13
I have just got this working using an ASUS RT-AC86U running merlin 386.7_2, which is behind my ISP supplied router and thus NATed. The phone is a Samsung galaxy S20 plus, recently updated to android 13. Prior to (and post) the update I was successfully using VPN type "IPSec / Xauth PSK" per the asus doco. When looking at ikev2, I changed the VPN type but found the Xauth option was removed when I went to revert...There's a lesson in that :/
Random notes:
I have no real idea what I'm doing so take it with a grain of salt but it's connecting and has been up for an hour now. It seemed a bit slow initially but performance seems to have improved.
I messed around a lot with the config, some of which may or may not be necessary or secure or recommended.
On the router
-------------
Advanced settings, VPN, VPN Server Tab, IPSec VPN table:
@b-epelbaum
b-epelbaum / main.cpp
Created April 16, 2023 17:49
A simple console Qt application
// main.cpp
#include <QtCore>
class Task : public QObject
{
Q_OBJECT
public:
Task(QObject *parent = 0) : QObject(parent) {}
public slots:
@b-epelbaum
b-epelbaum / fuzzy.txt
Created February 24, 2023 11:17
fuzzy logic in Qt
<QtGlobal> - Global Qt Declarations
The <QtGlobal> header file includes the fundamental global declarations. It is included by most other Qt header files. More...
Header: #include <QtGlobal>
Obsolete members
Types
typedef QFunctionPointer
typedef QtMessageHandler
enum QtMsgType { QtDebugMsg, QtInfoMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg }
typedef qint8
@b-epelbaum
b-epelbaum / qt_fork_join_example.cpp
Last active February 22, 2023 16:40
Fork-Join pattern in Qt
#include <QtCore>
class MyTask : public QRunnable
{
public:
MyTask(int id, int value) : m_id(id), m_value(value) {}
void run() override
{
qDebug() << "Task" << m_id << "started with value" << m_value;
@b-epelbaum
b-epelbaum / add_qt_privates.txt
Created February 21, 2023 15:43
How to add Qt private includes into project
$(QMake_QT_INSTALL_HEADERS_)/QtNetwork/$(QtVersion)/QtNetwork/private/
@b-epelbaum
b-epelbaum / randomized_mac.txt
Created February 21, 2023 08:41
How detect randomized MAC address
Fortunately it is easy to identify randomized MAC addresses.
There is a bit which gets set in the OUI portion of a MAC address to signify a randomized / locally administered address.
The quick synopsis is look at the second character in a MAC address,
if it is a 2, 6, A, or E it is a randomized address.
@b-epelbaum
b-epelbaum / url_regex.cpp
Created February 19, 2023 18:34
RegEx for URLs
std::regex_match (job_str.toStdString(), std::regex(R"(^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$)" ))) // we have URL