Skip to content

Instantly share code, notes, and snippets.

View bst_from_preorder.py
"""
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 Mar 1, 2016
Behavior to use Nuclear JS data in Polymer
View nuclear-js-polymer-behavior-example.html
<!--
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 Oct 22, 2015
The Things Network sensor for Home Assistant
View thingsnetwork.py
"""
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 Jan 31, 2016
Detect Python virtual environments venv and virtualenv
View environment.py
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 Feb 11, 2016
Code to paste into console with GitHub open to remove branches whose PRs are merged, closed or are 0 commits ahead
View github_branch_cleanup.js
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 Dec 1, 2016
Home Assistant light/mqtt.py which turns on based on brightness being set.
View mqtt.py
"""
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 Nov 23, 2021
Example platforms and automation component for Home Assistant
View sensor_example.py
"""
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 Jun 20, 2016
Sketch for the ESP8266 to publish temperature and humidity values received from a DHT22 to MQTT
View MQTT_ESP8266_temperature_humidity.ino
// 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 Nov 10, 2021
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
View config.h
#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 Jul 7, 2016
Jupyter Notebook connecting to Home Assistant
View home-assistant.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.