Skip to content

Instantly share code, notes, and snippets.

@bkuhns
bkuhns / yet_another_motion_automation.yaml
Last active March 9, 2023 22:40 — forked from networkingcat/yet_another_motion_automation.yaml
Homeassistant blueprint for motion-activated light scene
blueprint:
name: Yet Another Motion Automation (Forked)
description: >
# YAMA V10
Turn on lights or scenes when motion is detected.
Four different scenes can be defined depending on time of day.
@bkuhns
bkuhns / gist:302365673133e90881cdb024aff86eff
Created April 19, 2021 02:18
Command from https://www.youtube.com/watch?v=SDynPbCGvS0&t=616s but hopefully without goofy reformatting on Youtube.
backlog rule1 on system#boot do TCPStart 8888 endon ; rule1 1 ; template {"NAME":"Sonoff ZHABridge","GPIO":[56,208,0,209,59,58,0,0,0,0,0,0,17],"FLAG":0,"BASE":18} ; module 0
@bkuhns
bkuhns / pair2params.hpp
Created February 9, 2015 13:34
The pair2params() function allows you to use a more readable predicate for iterating over std::map's without having to define a custom algorithm. The first argument will "bind" to pair.first and the second argument to pair.second.
#include <map>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
namespace {
@bkuhns
bkuhns / sdl_ptr.h
Last active March 1, 2016 22:17
Defines an `sdl_ptr` type which is an alias for `std::unique_ptr` with custom deleters for SDL. Automatically manages SDL resources through scope-based lifetimes.
#pragma once
#include <SDL.h>
#include <memory>
template<typename T, typename Del>
using sdl_ptr = std::unique_ptr<T, Del>;
@bkuhns
bkuhns / ExampleOutput.txt
Last active August 29, 2015 14:06
Comparing the performance of sorting a large vector of moveable value types vs raw and smart pointers to that type. Written for VisualStudio 2012.
vector<Foobar> took: 2ms
vector<Foobar*> took: 71ms
vector<shared_ptr<Foobar>> took: 75ms
#include <boost/tuple/tuple.hpp>
#include <string>
using namespace std;
typedef boost::tuple<int, string> tuple_type;
struct inherits_from_tuple : public tuple_type
{
auto concept IFoo<class T> {
void do_something();
};
struct Base1 {
virtual void do_something();
};
@bkuhns
bkuhns / 0_main.cpp
Last active December 23, 2015 01:58
In reply to http://stackoverflow.com/a/18803611/245869 "For a value type Foo, why does a shared_ptr<const Foo> act like a value type even though it is a pointer type?"
#include <iostream>
#include <memory>
#include "Foo.hpp"
#include "Bar.hpp"
int main()
{
auto bar = Bar{};
#include <iostream>
#include <cstdint>
using namespace std;
//The following iterative sequence is defined for the set of positive integers:
//
//n → n/2 (n is even)
//n → 3n + 1 (n is odd)
SCENARIO("...", "[...]")
{
QEventLoop eventLoop;
MockRepository mockRepo;
GIVEN("An exporter") {
auto exporterAndMocks = setUpExporterAndMocks();
auto exporter = exporterAndMocks.first;
auto mocks = exporterAndMocks.second;