Skip to content

Instantly share code, notes, and snippets.

View ashmckenzie's full-sized avatar

Ash McKenzie ashmckenzie

View GitHub Profile
package main
import (
"fmt"
"log"
"net/http"
"time"
)
type Broker struct {
@ashmckenzie
ashmckenzie / sort_hostnames.rb
Last active October 12, 2016 03:56
Sort a set of scrambled hostnames in the format of <app><#>.<location>.<domain>
#!/usr/bin/env ruby
class Location
attr_reader :name, :name_only, :number
def initialize(name)
@name = name
match = name.match(/(^[a-z]+)(\d+)?/)
@name_only = match[1]
@number = match[2].to_i
@ashmckenzie
ashmckenzie / Rakefile
Last active March 16, 2017 03:45
before_all Rake hook
module Rake::DSL
def before_all(*args)
args.each do |pair|
matchers, task_names = pair.to_a.first
tasks = []
[ *matchers ].each do |matcher|
matcher = matcher.to_s if matcher.is_a?(Symbol)
tasks += Rake::Task.tasks.select { |task| !!task.name.match(matcher) }
end
@ashmckenzie
ashmckenzie / CustomSleepComponent.h
Created August 9, 2020 12:15 — forked from ofalvai/CustomSleepComponent.h
Custom ESPHome deep sleep component that's controlled via MQTT (adjustable sleep duration, sleep enter trigger)
#include "esphome.h"
#include "driver/rtc_io.h"
class CustomSleepComponent : public Component, public CustomMQTTDevice {
public:
void setup() override {
subscribe(TOPIC_SLEEP_DURATION, &CustomSleepComponent::on_sleep_duration_message);
subscribe(TOPIC_SLEEP_PREVENT, &CustomSleepComponent::on_prevent_message);
subscribe(TOPIC_SLEEP_ENTER, &CustomSleepComponent::on_enter_message);