Skip to content

Instantly share code, notes, and snippets.

View patrickbaumann's full-sized avatar

Patrick Baumann patrickbaumann

View GitHub Profile
@patrickbaumann
patrickbaumann / ZoozZEN71.yaml
Last active October 27, 2022 03:33
Automations helper for the Zooz ZEN71 On/Off Switch using the Zwave JS integration for Home Assistant
blueprint:
name: Zooz ZEN71
description: Automations helper for the Zooz ZEN71 On/Off Switch using the
Zwave JS integration.
domain: automation
input:
zooz_zen71:
name: Zooz ZEN71
description: The ZEN72 Switch to interact with.
selector:
@patrickbaumann
patrickbaumann / notify-or-do-something-when-an-appliance-like-a-dishwasher-or-washing-machine-finishes.yaml Home Assistant Blueprint: Notify or do something when an appliance like a dishwasher or washing machine finishes
blueprint:
name: Appliance has finished
description: Do something when an appliance (like a washing machine or dishwasher)
has finished as detected by a power sensor.
domain: automation
input:
power_sensor:
name: Power Sensor
description: 'Power sensor entity (e.g. from a smart plug device).'
selector:
@patrickbaumann
patrickbaumann / MyLogger.java
Created May 20, 2015 18:02
Example of how to wrap android.util.Log so that the tag is managed based on class name or logger name.
/**
* Example of how to wrap android.util.Log so that the tag is managed based on class name or logger name.
*/
public class MyLogger {
private final String mTag;
public MyLogger(String name) {
mTag = "Application:" + name;
}
@patrickbaumann
patrickbaumann / Tree2d.java
Created June 22, 2011 17:03
A 2d Point.Double Collections-based Search tree utitlizing TreeMaps
import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.TreeMap;
public class Tree2d<K extends Point.Double> implements Collection<K> {
@patrickbaumann
patrickbaumann / SiteAuthInterface.java
Created April 1, 2011 20:25
Proposal for basic site authorization interface
import java.util.Map;
public interface SiteAuthInterface {
class AuthorizationFailedException extends Exception{}
public void setRoot(String siteRoot);
public void setAuth(String username, String password);
public String post(String relativePath, Map<String, String> params)
throws AuthorizationFailedException, IOException, ClientProtocolException;
public String get(String relativePath, Map<String, String> params)
@patrickbaumann
patrickbaumann / gist:897830
Created April 1, 2011 06:38
HttpClient post authentication with cookie
import java.io.IOException;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
@patrickbaumann
patrickbaumann / gist:897492
Created March 31, 2011 23:48
Parsing a json tree with gson
String jsonString = "{'ms':1, 'ts':[{'id':1}, {'id':2}]}";
JsonParser gson = new JsonParser();
Type stringCollType = new TypeToken<List<Object>>(){}.getType();
JsonElement element = gson.parse(jsonString);
JsonObject element2 = element.getAsJsonObject();
String t = element2.get("ts").toString();
System.out.println(t); // [{'id':1}, {'id':2}]
@patrickbaumann
patrickbaumann / gist:880022
Created March 21, 2011 19:16
Silly Cobra Browser Snippet
import org.lobobrowser.html.test.*;
import org.lobobrowser.html.gui.*;
// ...
public class CobraBrowserTestView extends FrameView {
HtmlPanel panel;
CobraBrowserTestView(SingleFrameApplication app) {
@patrickbaumann
patrickbaumann / reflectionInJava.java
Created March 19, 2011 21:21
Reflection example in Java
import java.lang.reflect.*;
/* ... */
Class c = module.getClass();
Method configureMethod = c.getDeclaredMethod("configure", new Class[] { } );
configureMethod.setAccessible(true);
configureMethod.invoke(module, new Object[]{});