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 / 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:
<dom-module id='nuclear-example'>
balloob /
Created Oct 22, 2015
The Things Network sensor for Home Assistant
Sensor platform for Home Assistant that fetches data from the Things network.
Home Assistant:
The Things Network:
To use:
Copy this file to <config>/custom_components/sensor/
Add to <config>/configuration.yaml:
balloob /
Created Jan 31, 2016
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 / 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'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 /
Last active Dec 1, 2016
Home Assistant light/ which turns on based on brightness being set.
Support for MQTT lights.
For more details about this platform, please refer to the documentation at
import logging
from functools import partial
import homeassistant.components.mqtt as mqtt
balloob /
Last active Nov 23, 2021
Example platforms and automation component for Home Assistant
Copy this file to <config_dir>/example/
Add to your configuration.yaml:
platform: example
from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity
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
// -
// 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 / 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
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 / home-assistant.ipynb
Last active Jul 7, 2016
Jupyter Notebook connecting to Home Assistant
View home-assistant.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.