Skip to content

Instantly share code, notes, and snippets.

@ichilton
ichilton / notify-or-do-something-when-an-appliance-like-a-dishwasher-or-washing-machine-finishes.yaml Home Assistant Blueprint: Notify or do something when an appliance like a dishwasher or washing machine finishes
blueprint:
name: Appliance has finished
description: Do something when an appliance (like a washing machine or dishwasher)
has finished as detected by a power sensor.
domain: automation
input:
power_sensor:
name: Power Sensor
description: 'Power sensor entity (e.g. from a smart plug device).'
selector:
@ichilton
ichilton / gist:7674331
Last active December 29, 2015 12:59
rspec ordering problem
# This doesn't seem to work because the before(:each) is not called before the inner before(:all) is run...
context "when updating" do
before(:each) { @bible = create(:bible, code: 'OLD_CODE', alias: 'OLD_ALIAS') }
context "when not updating alias" do
before(:all) do
@bible.update_attributes(name: 'Different Name', code: 'UPDATED')
end
it "should have the updated title" do
@ichilton
ichilton / gist:6367730
Last active December 21, 2015 21:19
Add dns record on DNSimple with Chef
dnsimple_credentials = Chef::EncryptedDataBagItem.load("secrets", "dnsimple", Chef::EncryptedDataBagItem::DEFAULT_SECRET_FILE)
if dnsimple_credentials && dnsimple_credentials['domains'].include?(node[:domain])
include_recipe 'dnsimple'
dnsimple_record "#{node['hostname']}.#{node['domain']}" do
domain node['domain']
content node['ipaddress']
type "A"
action :create
@ichilton
ichilton / gist:5599450
Created May 17, 2013 14:36
Mongoid Embedded Documents
2x classes - Topic and TopicTerm
Topic embeds many topic_terms
I can find topics by using elemMatch:
def self.find_by_ref(reference)
where({:topic_terms => {'$elemMatch' => {:references => /^#{reference}(?:\.[0-9]+|$)/}}})
end
I then get an array of Topic objects back, where I can do:
@ichilton
ichilton / git_resources
Created June 13, 2012 14:02
Git Resources
Pro Git - http://git-scm.com/book
http://think-like-a-git.net/
VIDEOS:
Randal Schwartz:
http://vimeo.com/35778382
http://www.slideshare.net/RandalSchwartz/introduction-to-git-11451326
@ichilton
ichilton / gist:1340653
Created November 4, 2011 22:27
MCP79410 RTC Arduino Code
# From: http://web.icedsl.hu/enicke/mcprtc/mcpcode.html
#include <Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
}
@ichilton
ichilton / gist:955047
Created May 4, 2011 10:30
VeeWee Ubuntu 10.10 Build
$ vagrant basebox build 'myubuntubox'
Verifying the isofile ubuntu-10.10-server-i386-netboot.iso is ok.
We found no good state so we are destroying the previous machine+disks
VBoxManage unregistervm 'myubuntubox' --delete
Deleting vm myubuntubox
Creating vm myubuntubox : 384M - 1 CPU - Ubuntu
Creating new harddrive of size 10140
VBoxManage createhd --filename '/Users/ian/VirtualBox VMs/myubuntubox/myubuntubox.vdi' --size '10140' --format vdi > /dev/null
Attaching disk: /Users/ian/VirtualBox VMs/myubuntubox/myubuntubox.vdi