Skip to content

Instantly share code, notes, and snippets.

@martinky
martinky / interleave.kt
Last active October 28, 2022 11:22
Kotlin extension function to produce an interleaved flattened list from a collection of iterables
/**
* Produces a flattened [List] that is an interleaved merge of the input iterables.
*
* For example:
*
* ```
* listOf(
* listOf(1, 2, 3, 4),
* listOf('a', 'b')
* ).interleave()
@martinky
martinky / dummy.h
Last active March 23, 2021 11:15
Dummy helper struct that helps to debug when C++ objects get created, copied and destroyed.
#pragma once
/*
Dummy struct that prints a line whenever it is constructed, copied, moved or destructed.
*/
struct dummy {
int val;
dummy() : val(0) { printf("dummy() def ctor\n"); }
dummy(int v) : val(v) { printf("dummy(%d) ctor\n", val); }
dummy(const dummy &d) : val(d.val) { printf("dummy(%d) copy ctor\n", val); }
@martinky
martinky / QML_JS_closure_bug.pro
Last active March 26, 2020 07:15
Minimal example simulating a JS closure capture bug of the QML engine that is only observed while the QML debugger is attached. With the QML debugger attached following error occurs: main.qml:30: ReferenceError: text is not defined. Without QML debugger attached, the code works properly.
QT += quick
CONFIG += c++11
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp
RESOURCES += qml.qrc
@martinky
martinky / Makefile
Last active March 18, 2022 03:28
Makefile used to run complete Ansible playbooks in parallel on individual hosts using make -jN with added timeout constraint.
HOSTS=host_a host_b
INVENTORY=../data/inventory.inv
PLAYBOOK=../playbooks/test.yml
TIMEOUT=600
deploy: all_hosts
all_hosts: $(HOSTS)
$(HOSTS):
#include <stdio.h>
class Component
{
public:
int value;
Component(int v) :
value(v)
{