Skip to content

Instantly share code, notes, and snippets.

View ashmckenzie's full-sized avatar

Ash McKenzie ashmckenzie

View GitHub Profile
@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);
@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 / 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
package main
import (
"fmt"
"log"
"net/http"
"time"
)
type Broker struct {
@ashmckenzie
ashmckenzie / build-tmux.sh
Last active May 17, 2016 01:43 — forked from philipsoutham/build-tmux.sh
Build static tmux
#!/usr/bin/env bash
pushd $(dirname $0) > /dev/null; CURRABSPATH=$(readlink -nf "$(pwd)"); popd > /dev/null; # Get the directory in which the script resides
set -x
MUSLPKG="musl:musl.tgz:http://www.musl-libc.org/releases/musl-1.1.4.tar.gz"
LEVTPKG="libevent:libevent2.tgz:https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz"
TMUXPKG="tmux:tmux.tgz:https://github.com/tmux/tmux/releases/download/1.9a/tmux-1.9a.tar.gz"
NCRSPKG="ncurses:ncurses.tgz:http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz"
TEMPDIR="$CURRABSPATH/tmp"
TMPLIB="tempinstall/lib"
TMPINC="tempinstall/include"
@ashmckenzie
ashmckenzie / run.sh
Created January 22, 2016 00:23
Possible consul KV lookup bug
#!/bin/bash
consul agent \
-bootstrap=true \
-config-file=./consul.hcl \
-data-dir=./consul_data \
-bind=0.0.0.0 \
-client=127.0.0.1 \
-advertise=127.0.0.1
[DEBUG ] Reading configuration from /etc/salt/master
[DEBUG ] Using cached minion ID from /etc/salt/minion_id: master1
[DEBUG ] Missing configuration file: ~/.saltrc
[DEBUG ] Configuration file path: /etc/salt/master
[DEBUG ] Reading configuration from /etc/salt/master
[DEBUG ] Using cached minion ID from /etc/salt/minion_id: master1
[DEBUG ] Missing configuration file: ~/.saltrc
[DEBUG ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG ] LazyLoaded local_cache.get_load
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Wilson Júnior <wilsonpjunior@gmail.com>
import cmd
import sys
import os
import subprocess
import re
import readline
@ashmckenzie
ashmckenzie / .slate.js
Last active August 29, 2015 14:02
Slate JS - goes in ~/.slate.js
function MergeRecursive(obj1, obj2) {
for (var p in obj2) {
try {
// Property in destination object set; update its value.
if ( obj2[p].constructor==Object ) {
obj1[p] = MergeRecursive(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];
}
} catch(e) {
@ashmckenzie
ashmckenzie / .slate
Created June 12, 2014 00:09
My ~/.slate file
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config secondsBetweenRepeat 0.1
config checkDefaultsOnLoad true
config focusCheckWidthMax 3000
config windowHintsIconAlpha 0.3
config windowHintsFontColor 255;255;255;1
config windowHintsBackgroundColor 0;0;0;0.3
config windowHintsShowIcons true