Skip to content

Instantly share code, notes, and snippets.

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")
}
val testTaskDef = ( projectLayout
, debugIncludesTests
, builder
, packageName
, libraryProjects
, classDirectory in Test
, externalDependencyClasspath in Compile
, externalDependencyClasspath in Test
, targetSdkVersion
, minSdkVersion
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>() {
@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 {
@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 / 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 / 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 / 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 / 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 / widgets.scala
Last active December 21, 2015 05:39
qicr's multi-widget goodness
package com.hanhuy.android.irc
import AndroidConversions._
import android.appwidget.{AppWidgetManager, AppWidgetProvider}
import android.widget.{Toast, RemoteViews, RemoteViewsService}
import android.content.{DialogInterface, Context, BroadcastReceiver, Intent}
import android.app.{AlertDialog, Activity, PendingIntent}
import android.view.View
import com.hanhuy.android.irc.model._