Skip to content

Instantly share code, notes, and snippets.

@MagicMicky
MagicMicky / BundleTestActivity.java
Last active August 29, 2015 14:04
A gist that allows to check whether or not objects given through a Bundle are of the same instance. Used for an example on http://magicmicky.github.io/android_development/loose_coupling_using_otto/
package com.magicmicky.loosecoopling;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
@MagicMicky
MagicMicky / Adapters.java
Created October 12, 2014 17:34
An example showing the Adapter Design pattern, adapted to some account authentication
/*
* We want to auth our user on an application.
* We have two way to auth our user.
* We can either authenticate the user using his mail and password via Google, thanks to the Google SDK
* Or we can use the Facebook SDK to auth our user.
*/
public GoogleAuthenticator() {
public String authenticateViaGoogle(String mail, String password) {
//Android code
@MagicMicky
MagicMicky / audio_detector.sh
Created September 23, 2015 12:55
Audio detection turn on hdmi
#!/bin/bash
SWITCH_ON_CMD="echo 'on 0' > /tmp/cec.fifo"
CHANGE_HDMI="echo 'as' > /tmp/cec.fifo"
if [ -e "/tmp/cec.fifo" ]; then
echo proceeding: file exists
else
echo You need to start the server.
exit
fi
/// twitch-videoad.js
const origFetch = window.fetch;
window.fetch = (url, init, ...args) => {
if (typeof url === "string") {
if (url.includes("/access_token")) {
url = url.replace("player_type=site", "player_type=site");
} else if (
url.includes("/gql") &&
init &&
typeof init.body === "string" &&
@MagicMicky
MagicMicky / InflationPerformanceTestActivity.java
Last active June 16, 2021 22:13
Simple Android program to test performance gain when inflating temporary view programmatically or setting it to GONE and modify to VISIBLE when needed. Used for a blog article http://magicmicky.github.io/android_development/benchmark-using-traceview/
package com.magicmicky.testperfviews;
import android.app.Activity;
import android.graphics.LinearGradient;
import android.os.Debug;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
@MagicMicky
MagicMicky / update_notification.yaml
Last active December 15, 2021 16:59 — forked from Klumper/update_notification.yaml
Home Assistant update notification blueprint
blueprint:
name: Home Assistant update notification
description: Send a notification when there's an update availiable for Home Assistant
domain: automation
input:
updater:
name: Update sensor
description: The sensor which indicates if there's an update
selector:
entity: