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 / 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 / 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 / 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 / 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.
View keybase.md

Keybase proof

I hereby claim:

  • I am balloob on github.
  • I am balloob (https://keybase.io/balloob) on keybase.
  • I have a public key whose fingerprint is BBAD 245E 7174 B2E5 AD56 CBFB 322A D3E1 BB02 7C65

To claim this, I am signing this object:

@balloob
balloob / release_the_kraken.py
Created Sep 25, 2016
Stress test Home Assistant via the HTTP api
View release_the_kraken.py
from multiprocessing.dummy import Pool
import sys
import time
from homeassistant import remote
# Docs: remote.API(host, [password], [port], [use_ssl])
api = remote.API('127.0.0.1')
start_time = time.time()
@balloob
balloob / spectacles.py
Last active Nov 13, 2016
Track spectacle bots in Home Assistant https://home-assistant.io
View spectacles.py
"""
Component to track where spectacles are being sold.
To install:
- Install Home Assistant (duh): https://home-assistant.io
- Add this file as <config dir>/custom_components/sensor/spectacles.py
- Add to configuration.yaml:
sensor:
platform: spectacles
@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 / async_logger.py
Last active Dec 16, 2016
Async friendly logger
View async_logger.py
class AsyncFileHandler():
def __init__(self, loop, handler):
"""Initialize async logging file handle."""
self.handler = handler
self.loop = loop
self._queue = asyncio.Queue(loop=loop)
self._thread = threading.Thread(target=self._process)
def start_thread(self):
"""Start thread for processing."""