Skip to content

Instantly share code, notes, and snippets.

"""
Constructing a binary search tree from a BST preorder traversel in linear time.
Paulus Schoutsen, Feb 16 2014
"""
import sys
MAX_INT = sys.maxint
MIN_INT = -sys.maxint - 1
@balloob
balloob / nuclear-js-polymer-behavior-example.html
Last active March 1, 2016 05:30
Behavior to use Nuclear JS data in Polymer
<!--
Behavior to connect your NuclearJS app to Polymer.
Add key 'bindNuclear' to your property with as value a
valid NuclearJS getter.
Adapted from the NuclearJS ReactJS mix-in:
https://github.com/jordangarcia/nuclear-react-mixin
-->
<dom-module id='nuclear-example'>
@balloob
balloob / thingsnetwork.py
Created October 22, 2015 07:14
The Things Network sensor for Home Assistant
"""
Sensor platform for Home Assistant that fetches data from the Things network.
Home Assistant: https://home-assistant.io
The Things Network: http://thethingsnetwork.org/
To use:
Copy this file to <config>/custom_components/sensor/thingsnetwork.py
Add to <config>/configuration.yaml:
@balloob
balloob / environment.py
Created January 31, 2016 07:16
Detect Python virtual environments venv and virtualenv
def is_virtual():
""" Return if we run in a virtual environtment. """
# Check supports venv && virtualenv
return (getattr(sys, 'base_prefix', sys.prefix) != sys.prefix or
hasattr(sys, 'real_prefix'))
@balloob
balloob / github_branch_cleanup.js
Created February 11, 2016 23:14
Code to paste into console with GitHub open to remove branches whose PRs are merged, closed or are 0 commits ahead
Array.prototype.slice.call(document.getElementsByClassName('js-branch-row'))
.filter(el => el.getElementsByClassName('state-merged').length > 0 ||
el.getElementsByClassName('state-closed').length > 0 ||
el.getElementsByClassName('count-ahead')[0].innerHTML == '0')
.forEach(el => el.getElementsByClassName('branch-delete')[0].click())
@balloob
balloob / mqtt.py
Last active December 1, 2016 18:35
Home Assistant light/mqtt.py which turns on based on brightness being set.
"""
Support for MQTT lights.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/light.mqtt/
"""
import logging
from functools import partial
import homeassistant.components.mqtt as mqtt
@balloob
balloob / sensor_example.py
Last active November 23, 2021 16:31
Example platforms and automation component for Home Assistant
"""
Copy this file to <config_dir>/example/sensor.py
Add to your configuration.yaml:
sensor:
platform: example
"""
from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity
@balloob
balloob / MQTT_ESP8266_temperature_humidity.ino
Created June 20, 2016 04:11
Sketch for the ESP8266 to publish temperature and humidity values received from a DHT22 to MQTT
// Get ESP8266 going with Arduino IDE
// - https://github.com/esp8266/Arduino#installing-with-boards-manager
// Required libraries (sketch -> include library -> manage libraries)
// - PubSubClient by Nick ‘O Leary
// - DHT sensor library by Adafruit
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
@balloob
balloob / config.h
Last active July 13, 2023 07:40
ESP8266 sketch to control a Whynter ARC-110WD portable air conditioner and monitor temperature using MQTT, infrared transmitter, DHT22. For a list of possible IR codes see https://docs.google.com/spreadsheets/d/1dsr4Jh-nzC6xvSKGpLlPBF0NRwvlpyw-ozg8eZU813w/edit#gid=0
#define wifi_ssid "YOUR_WIFI_NAME"
#define wifi_password "YOUR_WIFI_PASSWORD"
#define mqtt_server "MQTT_SERVER"
#define mqtt_user "MQTT_USER"
#define mqtt_password "MQTT_PASS"
#define ac_topic "device/study_room/ac"
#define temperature_topic "device/study_room/temperature"
#define humidity_topic "device/study_room/humidity"
@balloob
balloob / home-assistant.ipynb
Last active October 5, 2023 10:38
Jupyter Notebook connecting to Home Assistant
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.