Skip to content

Instantly share code, notes, and snippets.

@rharter
rharter / SharedPreferenceLiveData.kt
Last active March 19, 2023 08:15
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
@rharter
rharter / copy_res.sh
Created December 6, 2016 18:19
Bash script to copy all versions of an Android resource from one project directory into another, preserving version qualifiers.
#!/bin/bash
function usage {
name=$0
echo "Usage: $name"
echo ""
echo "Searches for and copies all versions of an Android resource"
echo "(currently only drawables) from one project directory into "
echo "another, preserving version qualifiers."
echo ""

Keybase proof

I hereby claim:

  • I am rharter on github.
  • I am rharter (https://keybase.io/rharter) on keybase.
  • I have a public key ASC2PVpf79-TV0qyzGGs0SalYN6fNpE0cnhm0vTLNMsWFwo

To claim this, I am signing this object:

@rharter
rharter / RevealDrawable.java
Created April 3, 2015 17:41
A Drawable that transitions between two child Drawables based on this Drawable's current level value. The idea here is that the center value (5000) will show the 'selected' Drawable, and any other value will show a transitional value between the 'selected' Drawable and the 'unselected' Drawable.
package com.pixite.fragment.widget;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.Callback;
import android.view.Gravity;
package com.ryanharter.mediaroute.widgets;
import android.content.Context;
import android.support.v7.app.MediaRouteActionProvider;
import android.support.v7.app.MediaRouteButton;
/**
* A MediaRouteActionProvider that allows the use of a ThemeableMediaRouteButton.
*/
public class ThemeableMediaRouteActionProvider extends MediaRouteActionProvider {
public Observable<Show> getShows() {
return authClient.getAuthString()
.flatMap(token -> contentApi.getShows(token, selectedMediaServer))
.flatMap(shows -> Observable.from(shows.getShows()))
.flatMap(this::getImdbId);
}
public Observable<Show> getImdbId(Show show) {
return omdbApi.searchByTitle(show.getTitle())
.flatMap(movie -> {
@rharter
rharter / AppRater.java
Created September 5, 2014 14:51
A simple utility class to manage rating (or really anything) call to action display.
package com.ryanharter.android.util;
import android.content.Context;
import android.content.SharedPreferences;
/**
* Keeps track of the number of app launches, and days since first launch, and
* provides an easy way to determine whether you should show a rating prompt
* or not.
*/
#! /bin/bash
# Batch Convert Script by StevenTrux
# The Purpose of this Script is to batch convert any video file to mp4 or mkv format for chromecast compatibility
# this script only convert necessary tracks if the video is already
# in H.264 format it won't convert it saving your time!
# Put all video files need to be converted in a folder!
# the name of files must not have " " Space!
# Rename the File if contain space
@rharter
rharter / google.py
Created April 16, 2014 14:34
Web crawler to look for hidden short links in Google Developers site that (hopefully) lead to I/O tickets.
#!/usr/local/bin/python
import sys
from lxml import html
from urlparse import urljoin
import urllib2
import requests
import logging
visited_links = []
type mogrify >/dev/null 2>&1 || { echo >&2 "» This script requires mogrify. Please install ImageMagick first!"; exit 1; }
IOS_IMAGE_PATH="$1"
OUTPUT_PATH="$2"
mkdir -p $OUTPUT_PATH/res/drawable-hdpi $OUTPUT_PATH/res/drawable-mdpi $OUTPUT_PATH/res/drawable-xhdpi
echo " » Copy all resources to MDPI, this is"
echo " the same density as a non-retina iOS device"
find "${IOS_IMAGE_PATH}"/* -type f -exec cp {} ${OUTPUT_PATH}/res/drawable-mdpi/ \;