Skip to content

Instantly share code, notes, and snippets.

@orip
orip / AnimationUtils.java
Last active December 25, 2015 02:09
Helper to simulate withEndAction in NineOldAndroids http://nineoldandroids.com/
package com.example;
import com.nineoldandroids.animation.Animator;
/*
* animate(view).alpha(0).setListener(AnimationUtils.withEndAction(new Runnable() {
* public void run() {
* view.setVisibility(View.GONE);
* view.setAlpha(1); // restore alpha
* }
@orip
orip / AlarmHelper.java
Last active December 24, 2015 22:49
AlarmHelper that helps scheduling repeating non-wakeup inexact alarms. Define how to create the pending intent (e.g. getBroadcast vs getService), the alarm interval, and the first delay.
package com.example;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;
/**
@orip
orip / build.gradle
Created October 7, 2013 17:52
Define an Android app's versionName and versionCode from git tags. http://orip.org/2013/10/versioning-android-apps-with-git-tags.html
android {
def gitTag = {
def tagMatchOptions
try {
tagMatchOptions = "--match ${tagToBuildFrom}"
} catch (MissingPropertyException) {
tagMatchOptions = ""
}
"git describe --exact HEAD ${tagMatchOptions}".execute().text.trim()
}()
@orip
orip / build.gradle
Last active April 19, 2016 11:56
ProGuard rules for using Dagger 1.1.0 with gradle.
dependencies {
def dagger_version = "1.1.0"
compile "com.squareup.dagger:dagger:${dagger_version}"
compile "com.squareup.dagger:dagger-compiler:${dagger_version}"
}
@orip
orip / JdkBasedTimeZoneProvider.java
Last active January 14, 2017 03:20
A Joda time zone provider based on the JVM's TimeZone implementation, instead of Joda's Olson database. This can reduce Joda's initialization time (during class loading) by several seconds on Android. Inspired by http://stackoverflow.com/a/6298241/37020, but implemented from scratch. Requires Guava, for ImmutableSet.
/*
* Copyright (C) 2013 Onavo 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
@orip
orip / build.gradle
Created August 7, 2013 13:00
dagger in gradle
dependencies {
def dagger_version = "1.1.0"
compile "com.squareup.dagger:dagger:${dagger_version}"
compile "com.squareup.dagger:dagger-compiler:${dagger_version}"
}
@orip
orip / PicassoUtils.java
Last active July 18, 2018 08:39
Working around https://github.com/square/okhttp/issues/184 for Picasso 2.x (older revisions for Picasso 1.1.1)
package com.example;
import android.content.Context;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;
import javax.net.ssl.SSLContext;
import java.io.File;
@orip
orip / android_lint_summarizer.py
Created June 27, 2013 09:15
Summarize the warning categories printed by Android Lint. Usage: lint <src_dir> | android_lint_summarizer.py Reference: http://developer.android.com/tools/help/lint.html
#!/usr/bin/env python
#
# Sample usage:
#
# % lint my_android_app | android_lint_summarizer.py
# 26 SpUsage
# 10 I18N HardcodedText
# 8 Accessibility ContentDescription
# 2 Typos
# 1 IconDuplicates
@orip
orip / vulcan_nginx
Last active December 18, 2015 16:09
UPDATE: a much-improved version is now in the nginx-buildpack repository. Building nginx with rewrite_module for use in heroku buildpacks.
#!/bin/bash
# An improved version is now in the nginx-buildpack repository:
# https://github.com/ryandotsmith/nginx-buildpack/blob/17b290ed880a182ef27f438eab3070f081c0ee0e/scripts/build_nginx.sh
#
# Building nginx with rewrite_module for use in heroku buildpacks - specifically in @ryandotsmith's https://github.com/ryandotsmith/nginx-buildpack.
# Uses heroku's vulcan for building (`gem install vulcan`).
# Can be used as a template for any kind of compile-time configuration of nginx.
cd $(mktemp -d /tmp/vulcan_nginx.XXXXXXXXXX)
echo $PWD
@orip
orip / annotate_gource_log.py
Last active December 17, 2015 22:08
Insert the filename into a custom gource log
# Based on https://code.google.com/p/gource/issues/detail?id=8#c27
#
# Usage:
# for x in *; do
# gource --output-custom-log $x.txt /path/to/repos/$x
# done
# python annotate_gource_log.py *.txt | sort -n > combined.txt
# gource combined.txt
import fileinput, sys