Skip to content

Instantly share code, notes, and snippets.

View vadimpiven's full-sized avatar

Vadim Piven vadimpiven

View GitHub Profile
@vadimpiven
vadimpiven / BiosUUID.h
Last active October 29, 2023 11:19
Get SMBIOS UUID (WinAPI, C++ 17, Boost)
// SPDX-License-Identifier: MIT
// MIT Software License: https://opensource.org/licenses/MIT
// Copyright Vadim Piven <[email protected]>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <algorithm>
#include <functional>
#include <iterator>
@vadimpiven
vadimpiven / SystemUUID.swift
Last active October 29, 2023 11:36
Get macOS machine UUID (Swift 5)
// SPDX-License-Identifier: MIT
// MIT Software License: https://opensource.org/licenses/MIT
// Copyright Vadim Piven <[email protected]>
import Foundation
import IOKit
func getSystemUUID() -> String? {
let platformExpert = IOServiceGetMatchingService(
kIOMainPortDefault,
@vadimpiven
vadimpiven / SelfDelete.cpp
Last active October 29, 2023 16:48
Executable self delete (WinAPI, C++ 17) - works only if executable is located on NTFS partition
// SPDX-License-Identifier: MIT
// MIT Software License: https://opensource.org/licenses/MIT
// Copyright Vadim Piven <[email protected]>
#include <Windows.h>
#include <algorithm>
#include <array>
#include <cstddef>
#include <filesystem>
@vadimpiven
vadimpiven / com.example.app.startup.plist
Last active January 7, 2024 10:00
MacOS add application (Example.app) to autostart
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.example.app.startup</string>
<key>AssociatedBundleIdentifiers</key>
<array>
<string>com.example.app</string>
</array>
@vadimpiven
vadimpiven / MainWindow.cpp
Created November 15, 2023 07:45
QMainWindow take high quality screenshot with transparency
// SPDX-License-Identifier: CC0-1.0
// Creative Commons Zero v1.0 Universal License: https://creativecommons.org/publicdomain/zero/1.0/deed
void MainWindow::takeScreenshot()
{
assert(isVisible() || !"call show() before taking screenshot");
QPixmap pixmap(size() * devicePixelRatioF());
pixmap.setDevicePixelRatio(devicePixelRatioF());
@vadimpiven
vadimpiven / example.qml
Created November 22, 2023 15:37
How to use setContextProperty on QQuickWidget to inject JS module in place of QObject (useful for tests)
import QtQuick 2
Rectangle {
width: 400
height: 200
Text {
anchors.centerIn: parent
text: logic.GetText()
}
@vadimpiven
vadimpiven / boolean_array_view.ts
Last active May 23, 2024 18:51
View for Uint8Array emulating BooleanArray or BitSet
// SPDX-License-Identifier: CC0-1.0
// Creative Commons Zero v1.0 Universal License: https://creativecommons.org/publicdomain/zero/1.0/deed
class BooleanArrayView {
array: Uint8Array;
constructor(array: Uint8Array) {
this.array = array;
return new Proxy(this, {