Skip to content

Instantly share code, notes, and snippets.

@iamazeem
iamazeem / qt_run_notepad.cpp
Created December 16, 2016 07:10
Qt QProcess - Example using Lambda - Run Notepad on Windows
// ----------------------------------------------
// Open Notepad on Windows using QProcess
// Asynchronously using std::async and
// Wait for it to exit with std::future
// ----------------------------------------------
#include <QProcess> // QProcess
#include <QDebug> // qDebug(), qCritical(), ...
#include <future>
@iamazeem
iamazeem / qt_directory_watcher.cpp
Last active January 9, 2023 17:04
Qt QFileSystemWatcher Example - Watch a directory and do some processing if it is changed with QEventLoop
// ----------------------------------------------
// List the contents of a directory if changed
// Using QFileSystemWatcher, QDirIterator and
// QEventLoop, and lambda function for connect
// ----------------------------------------------
#include <QObject>
#include <QEventLoop>
#include <QDebug>
#include <QFileSystemWatcher>
// Validate date using regex
// Format: YYYY/MM/DD
#include <iostream>
#include <regex>
bool isDateValid( const std::string& date )
{
std::regex regexDate { R"(\d{4}/\d{2}/\d{2})" };
std::smatch match;
#include <QApplication>
#include <QDebug>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QIcon>
#include <QThread>
#include <QObject>
#include <QFile>
#include <QIODevice>
#include <QCoreApplication>
#include <QUdpSocket>
#include <QObject>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QUdpSocket _s;
_s.bind( QHostAddress::LocalHost, 9000 );
#include <QObject>
#include <QCoreApplication>
#include <QUdpSocket>
#include <QTimer>
int main( int argc, char *argv[] )
{
QCoreApplication app( argc, argv );
QUdpSocket _s;
@iamazeem
iamazeem / rapidjson_file_read_write_test.cpp
Last active September 4, 2023 14:21
RapidJSON - File Read/Write Test
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/ostreamwrapper.h>
int main()
# Print progress on same line
(1..10).each do |i|
print "\rDownloaded: #{i} of 10"
sleep 1
end
puts
puts 'Rest of the logs here...'
@iamazeem
iamazeem / first_recurring_character.cpp
Created April 10, 2018 11:25
How to find first recurring character in a string
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <array>
#include <utility>
#include <algorithm>
#include <unordered_map>
// https://stackoverflow.com/a/55297349/7670262
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
int main()
{
const auto data = R"({ "Name": "45", "Path": "C:\file.json" })";