Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
JakeWharton / GuavaCollectors.java
Last active May 10, 2018 09:08
Example Java 8 collectors for Guava.
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@JakeWharton
JakeWharton / hardlinkify.py
Created April 13, 2011 15:56
Python script to facilitate the hardlinking of directories and their files.
#!/usr/bin/env python
#
# Python script to facilitate the hardlinking of directories and their files.
import sys
if sys.version_info < (2, 3):
raise RuntimeError('Python 2.3+ is required.')
import logging
import optparse
@JakeWharton
JakeWharton / IconCheckBoxPreference.java
Created August 9, 2010 16:37
IconCheckBoxPreference: An Android CheckBox preference with an optional Icon
package com.jakewharton.utilities;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import com.jakewharton.wakkawallpaper.R;
@JakeWharton
JakeWharton / README.md
Created June 12, 2014 15:38
Map Java 8 streams to RxJava Observables.

Output

Greeting: Hey
Greeting: Hi
Greeting: Hello

[60, 61, 62, 63, 64, 65, 66, 67, 68, 69]
[70, 71, 72, 73, 74, 75, 76, 77, 78, 79]
[80, 81, 82, 83, 84, 85, 86, 87, 88, 89]
@JakeWharton
JakeWharton / crlf_fix.py
Created May 19, 2011 19:10
Python script to fix common CRLF and Unicode problems when working with Visual Studio and git.
#!/usr/bin/env python
import sys
if sys.version_info < (2, 6):
raise RuntimeError("Python 2.6+ is required.")
import codecs
import logging
import optparse
import os
@JakeWharton
JakeWharton / visibilities.sh
Last active May 24, 2019 00:03
A bash script to count the visibility modifiers in a jar file.
#!/bin/bash
if [ $# != 1 ]; then
echo "Pass jar as sole argument"
exit 1
fi
tmp=`mktemp -d`
unzip -d "$tmp" $1 1> /dev/null
/**
* Execute an {@link AsyncTask} on a thread pool.
*
* @param task Task to execute.
* @param args Optional arguments to pass to {@link AsyncTask#execute(Object[])}.
* @param <T> Task argument type.
*/
public static <T> void execute(AsyncTask<T, ?, ?> task, T... args) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) {
throw new UnsupportedOperationException("This class can only be used on API 4 and newer.");
public class CheckableFrameLayout extends FrameLayout implements Checkable {
private static final int[] CHECKED_STATE_SET = {
android.R.attr.state_activated,
android.R.attr.state_checked,
};
private boolean mChecked;
public CheckableFrameLayout(Context context) {
super(context);
@JakeWharton
JakeWharton / README.md
Last active January 8, 2020 02:13
A special activity which facilitates restarting your application process.
@JakeWharton
JakeWharton / OkConnectionFactory.java
Created June 17, 2013 15:04
A connection factory for using OkHttp with Kevin Sawicki's HttpRequest library.
/**
* A {@link HttpRequest.ConnectionFactory connection factory} which uses OkHttp.
* <p/>
* Call {@link HttpRequest#setConnectionFactory(HttpRequest.ConnectionFactory)} with an instance of
* this class to enable.
*/
public class OkConnectionFactory implements HttpRequest.ConnectionFactory {
private final OkHttpClient client;
public OkConnectionFactory() {