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
# set variable identifying the git branch you work in (used in the prompt below)
bashrc_update_prompt() {
git_branch=$(
while [ "$PWD" != "/" ]; do
if [ -d ".git/objects" ]; then
git-branch 2>/dev/null | sed -ne 's/^\* //p'
break
fi
cd ..
//
// Sometimes QML still surprise by really just doing the right thing.
// For instance the following lines:
//
// console.info("Status:", Status.Unknown, Status.Good, Status.Warning, Status.Failing);
// console.info("Sensor:", Sensor.Unknown, Sensor.Good, Sensor.Warning, Sensor.Failing);
//
// really print:
//
// qml: Status: 0 1 2 3
@hasselmm
hasselmm / cities.csv
Created July 2, 2020 16:14
Menschen, die derzeit vom City-Ticket der Deutschen Bahn profitieren
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Rang Name 1970 1980 1990 2000 2010 2018/2019 Bundesland
1. Berlin 3.208.719 3.048.759 3.433.695 3.382.169 3.460.725 3.669.491 Berlin
2. Hamburg 1.793.640 1.645.095 1.652.363 1.715.392 1.786.448 1.847.253 Hamburg
3. München 1.311.978 1.298.941 1.229.026 1.210.223 1.353.186 1.471.508 Bayern
4. Köln 849.451 976.694 953.551 962.884 1.007.119 1.087.863 Nordrhein-Westfalen
5. Frankfurt am Main 666.179 629.375 644.865 646.550 679.664 761.561 Hessen
6. Stuttgart 634.202 580.648 579.988 583.874 606.588 634.830 Baden-Württemberg
7. Düsseldorf 660.963 590.479 575.794 569.364 588.735 621.877 Nordrhein-Westfalen
8. Leipzig 583.885 562.480 511.079 493.208 522.883 593.145 Sachsen
9. Dortmund 640.642 608.297 599.055 588.994 580.444 588.250 Nordrhein-Westfalen
@hasselmm
hasselmm / cities.csv
Last active July 2, 2020 16:18
Menschen, die derzeit vom City-Ticket der Deutschen Bahn profitieren
Rang Name 1970 1980 1990 2000 2010 2018/2019 Bundesland
1. Berlin 3.208.719 3.048.759 3.433.695 3.382.169 3.460.725 3.669.491 Berlin
2. Hamburg 1.793.640 1.645.095 1.652.363 1.715.392 1.786.448 1.847.253 Hamburg
3. München 1.311.978 1.298.941 1.229.026 1.210.223 1.353.186 1.471.508 Bayern
4. Köln 849.451 976.694 953.551 962.884 1.007.119 1.087.863 Nordrhein-Westfalen
5. Frankfurt am Main 666.179 629.375 644.865 646.550 679.664 761.561 Hessen
6. Stuttgart 634.202 580.648 579.988 583.874 606.588 634.830 Baden-Württemberg
7. Düsseldorf 660.963 590.479 575.794 569.364 588.735 621.877 Nordrhein-Westfalen
8. Leipzig 583.885 562.480 511.079 493.208 522.883 593.145 Sachsen
9. Dortmund 640.642 608.297 599.055 588.994 580.444 588.250 Nordrhein-Westfalen
@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:

@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 / 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 / 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 / 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 / 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);