Skip to content

Instantly share code, notes, and snippets.

@pfn
pfn / RingBuffer.scala
Created August 19, 2013 20:50
a ring buffer
case class RingBuffer[A: ClassManifest](capacity: Int) extends IndexedSeq[A] {
private val buffer = Array.fill[A](capacity)(null.asInstanceOf[A])
private var _length = 0
private var pos = 0
def length = _length
private def zero = (capacity + (pos - _length)) % capacity
def clear() {
_length = 0
@pfn
pfn / repo.py
Last active December 23, 2015 07:09
cheap repo hack for windows
#!/usr/bin/python
from optparse import OptionParser
import sys
import os
from subprocess import Popen
from subprocess import PIPE
import urllib
from xml.parsers import expat
@pfn
pfn / tests.sbt
Created September 18, 2013 14:38
import android.Keys._
TaskKey[Unit]("check-for-properties") <<= (apkFile) map { a =>
val found = findInArchive(a) (_.getName == "com/example/lib/file.properties")
if (!found) error("Properties not found in APK")
}
def findInArchive(archive: File)(predicate: String => Boolean): Boolean = {
import java.io._
import java.util.zip._
@pfn
pfn / build.sbt
Created October 18, 2013 22:39
example build.sbt for a single project with many library projects
import android.Keys._
android.Plugin.androidBuild
name := "project-with-lib-projects"
unmanagedClasspath in Compile <<= ( baseDirectory
, unmanagedClasspath in Compile) map {
(base,cp) =>
val ignores = Set("android-support-v4.jar", "guava-14.0.1.jar")
@pfn
pfn / build.sbt
Created October 22, 2013 14:59
proguard command from this-project
commands <+= thisProject { p =>
Command.command("proguard")(st => {
val extracted = Project.extract(st)
Project.runTask(packageT in (p, Android),
extracted.append(Seq(
useProguard in Android := true,
useProguardInDebug in Android := true
), st)
)
st
@pfn
pfn / futures.java
Last active December 28, 2015 04:19
private static Future<String> requestJson(final String uri) {
return Future.create(new Callable<String>() {
public String call() throws IOException {
OkHttpClient client = new OkHttpClient();
HttpURLConnection conn = client.open(new URL(uri));
InputStreamReader in =
new InputStreamReader(conn.getInputStream(), "utf-8");
try {
return CharStreams.toString(in);
} finally {
Future<Config> config = Feeds.getInstance().getConfig();
Future<Home> homeData = config.flatMap(new Function<Config, Future<Home>>() {
@Override
public Future<Home> apply(Config input) {
return Feeds.getInstance().getHome(input);
}
});
homeData.onSuccess(new Callback<Home>() {
val testTaskDef = ( projectLayout
, debugIncludesTests
, builder
, packageName
, libraryProjects
, classDirectory in Test
, externalDependencyClasspath in Compile
, externalDependencyClasspath in Test
, targetSdkVersion
, minSdkVersion
SettingKey[Attributed[File] => Boolean]("filter-fn") := { e: Attributed[File] =>
val name = e.data.getName
name.startsWith("android-support") ||
name.startsWith("support-v4-r18") ||
name.startsWith("xmlParserAPIs") ||
name.startsWith("android-4") ||
name.startsWith("accessenabler-1.6") ||
name.startsWith("adobe-adms-measurement") ||
name.startsWith("xpp3")
}
@pfn
pfn / emailhack.diff
Last active December 31, 2015 18:22
remove device admin policies from exchange emails (patch written against tag:android-4.4.2_r1) (disable built-in Email/Exchange Services packages prior to installation) Install Email.apk first followed by Exchange2.apk after building 1. Setup AOSP build environment (envsetup.sh; lunch; etc.) 2. make -j16 Email Exchange2 3. adb install out/target…
diff --git a/Android.mk b/Android.mk
index 8bbbd98..59a6398 100644
--- a/Android.mk
+++ b/Android.mk
@@ -41,6 +41,7 @@ LOCAL_ASSET_DIR := $(LOCAL_PATH)/$(unified_email_dir)/assets
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.android.ex.chips:com.android.mail:com.android.email:com.android.emailcommon:com.android.ex.photo:android.support.v7.gridlayout
+LOCAL_AAPT_FLAGS += --rename-manifest-package com.android.emailhack