Skip to content

Instantly share code, notes, and snippets.

View wolph's full-sized avatar

Rick van Hattem wolph

View GitHub Profile
# - alias: close curtains
# trigger:
# - event: sunset
# platform: sun
# condition: []
# action:
# - data:
# entity_id: cover.qubino_zmnhod1_flush_shutter_dc_level
# service: automation.turn_off
@wolph
wolph / non_blocking_read.py
Created September 19, 2018 11:57
Read all available data from file handle and return (with optional timeout)
def read(fh, timeout=0):
output = []
while select.select([fh], [], [], timeout)[0]:
output.append(fh.read(1))
return ''.join(output)
@wolph
wolph / colortest.py
Last active March 30, 2024 02:44
Testing 256 color shells using background colors and automatic shell width detection
#!/usr/bin/env python
from __future__ import print_function
import os
import shutil
import subprocess
def get_width(default=80):
'''Attempt to detect console width and default to 80'''
@wolph
wolph / sj1221.ino
Created April 2, 2018 11:19
SJ1221 led strip test
/* vim: ts=8
Example code for the SJ1221 control protocol
Based on: http://wp.josh.com/2014/05/11/ws2812-neopixels-made-easy/
*/
// Change this to be at least as long as your pixel string (too long will work fine, just be a little slower)
#define PIXELS 96*11 // Number of pixels in the string
// color multiplier since we've got 0-4096 instead of 0-256
@wolph
wolph / main.py
Last active January 18, 2018 20:16 — forked from jorenham/main.py
Best exception handling in Python
import sys
import webbrowser
def main():
return 42/0
def excepthook(type_, value, traceback):
webbrowser.open_new_tab('https://stackoverflow.com/search?q=[python] {} {}'.format(type_, value))
@wolph
wolph / update_wan_ip.rsc
Created March 25, 2017 16:37
Mikrotik script to detect WAN IP updates and call scripts if it changes.
:global wanInterface "wan1"
:global wanIP "$wanIP"
# Get the current IP on the interface
:local currentIPtemp [/ip address get [find interface="$wanInterface" disabled=no] address];
# IP without netmask
:local currentIP [:pick $currentIPtemp 0 ([:len $currentIPtemp]-3)];
:if ($currentIP != $wanIP) do={
@wolph
wolph / __init__.py
Last active October 13, 2016 23:40
RFXtrx
# -*- coding: utf-8 -*-
#
# This file is a plugin for EventGhost.
# Copyright (C) 2012 Walter Kraembring <krambriw>.
#
# ALL RIGHTS RESERVED. The development of this software is based on information
# provided by RFXCOM and is protected under Netherlands Copyright Laws and
# Treaties and shall be subject to the exclusive jurisdiction of the Netherlands
# Courts.
# This pluginís source code and other versions eventually based on it may be
@wolph
wolph / django_admin_edit_fields.js
Last active December 2, 2016 00:02
Firefox console script to extract `fields` and `fieldset` definitions from django admin form/edit pages
console.clear();
function getFields(fields, parent){
var rows = [" fields = ("];
$(fields, parent).each(function(){
var regex = /field-([^ ]+)/g;
var columns = [];
while(match = regex.exec(this.className)){
columns.push(match[1]);
}
@wolph
wolph / computer_futures_usability.user.js
Last active July 19, 2016 09:25
Computer futures usability enhancer
// ==UserScript==
// @name Computer Futures Worksheet Usability Enhancer
// @namespace http://wol.ph/
// @description try to take over the world!
// @author Wolph
// @match https://worksheets.computerfutures.com/index.php?*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
@wolph
wolph / y_combinator_quicksort.py
Created May 30, 2016 21:06
Implementing the Quick sort algorithm using the Y Combinator
Y = lambda f: lambda *args: f(Y(f))(*args)
quicksort = Y(lambda f:
lambda x: (
f([item for item in x if item < x[0]])
+ [y for y in x if x[0] == y]
+ f([item for item in x if item > x[0]])
) if x else [])