Skip to content

Instantly share code, notes, and snippets.

View hasselmm's full-sized avatar
♻️
do:🦝🍀 love:🌳🦋🚆🚴‍♂️

Mathias Hasselmann hasselmm

♻️
do:🦝🍀 love:🌳🦋🚆🚴‍♂️
View GitHub Profile
@hasselmm
hasselmm / README.md
Last active November 12, 2026 15:27
Type safe test data sets for QTest

Ever forgot to add all rows to your QTest data? Ever mixed up types?
Don't worry anymore this tiny set of classes is here to help.
All with a syntax close enough to what you are used to.

class Example : public QObject
{
private slots:
    decode_data()
    {
@hasselmm
hasselmm / arduino-trybuild.md
Last active June 12, 2025 23:43
Try Build - Tries to build selected files of an Arduino Sketch

Try Arduino Build

Building Arduino sketches takes an imense amount of time. This is very annoying when fixing trivial issues like compile errors.

This tool tries to reduce your round-trip times by building only selected files of an Arduino Sketch.

Requirements

function inputsNotEmpty(inArr) {
return inArr.every(inp => {
return inp.value != '';
});
}
inputsNotEmpty([]);
@hasselmm
hasselmm / delete-mok-variables.py
Created November 9, 2024 13:18
Properly from missing mmx64.efi for failed Linux installation
import firmware_variables as firmware
mok_namespace = "{605DAB50-E046-4300-ABB6-3DD810DD8B23}"
mok_variables = ["MokNew", "MokAuth"]
with firmware.privileges():
for name in mok_variables:
try:
firmware.delete_variable(name, namespace=mok_namespace)
print(f"- firmware variable {name} removed")
@hasselmm
hasselmm / aproperty.h
Created December 18, 2023 21:05
André Pönitz Property
#ifndef APROPERTY_H
#define APROPERTY_H
#include <utility>
namespace Private {
template<class T, typename V>
using NotifyMemberFunction = void (T::*)(V);
@hasselmm
hasselmm / constexpr-type-label.cpp
Last active March 6, 2023 10:52
Switch statement on C++ type in Qt
constexpr quint64 label(const char *const s, size_t shift = 0)
{
if (s[0] == '\0')
return 0; // end of string
if (shift == 56)
return 0; // avoid integer overflow
return (static_cast<quint64>(s[0]) << shift) ^ label(&s[1], shift + 1);
}
@hasselmm
hasselmm / ipv4literal.h
Created April 25, 2022 13:30
User defined literal for IPv4 addresses
#include <stdint.h>
namespace detail {
constexpr uint8_t parse_octet(const char *str, const char *end, const char **out = nullptr)
{
uint8_t octet = 0;
if (str < end) {
if (*str >= '3' && *str <= '9') { // 3-9 | 30-99
@hasselmm
hasselmm / twitter-remove-emoji.js
Last active December 3, 2021 01:22
Remove Emoji from Twitter Handles
// ==UserScript==
// @name Remove Emoji from Twitter Handles
// @version 1
// @grant none
// @include https://twitter.com/*
// ==/UserScript==
window.addEventListener('DOMContentLoaded', function() {
// Every 500 ms…
window.setInterval(function() {
@hasselmm
hasselmm / qml-function-binding.cpp
Last active June 7, 2021 14:24
Function binding for QML
// Basic idea is to export the function as a Qt property that holds a JavaScript callable
Q_PROPERTY(QJSValue hasRoles READ hasRolesFunction NOTIFY rolesChanged FINAL)
// Possible implementation of such property
QJSValue ProfileService::hasRolesFunction()
{
// create function factory to bind `this`
auto factory = qmlEngine(this)->evaluate("profileService => (roles => (profileService.roles & roles) === roles)"_l1);
if (factory.isError()) {
@hasselmm
hasselmm / git housekeeping.md
Last active January 5, 2021 17:59
Automatically delete branches that have been merged

Automatically delete branches that have been merged

Add the following line to your git configuration:

$ git config alias.housekeeping
!f() { git checkout -q ${1:-main} && git branch --merged | grep -v ^* | xargs -n1 -r git branch --delete; }; f

After merging branches run: