Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
JakeWharton / OkHttpStack.java
Created May 21, 2013 01:14
A `HttpStack` implementation for Volley that uses OkHttp as its transport.
import com.android.volley.toolbox.HurlStack;
import com.squareup.okhttp.OkHttpClient;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* An {@link com.android.volley.toolbox.HttpStack HttpStack} implementation which
* uses OkHttp as its transport.
*/
@JakeWharton
JakeWharton / BindingAdapter.java
Last active July 25, 2023 05:49
An adapter base class that uses a new/bind pattern for its views.
// Apache 2.0 licensed.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
/** An implementation of {@link BaseAdapter} which uses the new/bind pattern for its views. */
public abstract class BindableAdapter<T> extends BaseAdapter {
@cyrilmottier
cyrilmottier / gist:5292270
Created April 2, 2013 13:39
Passing additional information into a Cursor
package com.cyrilmottier.android.avelov.database;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.os.Bundle;
/**
* A Cursor that completely re-writes the actual Cursor capabilities related to extras. It allows clients to use the setExtras(Bundle) (this
* method is actually hidden in the Android framework).
*
@swankjesse
swankjesse / Rip.java
Created February 8, 2013 23:27
Stream editor for Java nerds. Use Java regular expressions to break up lines, and Java format strings to put them back together again.
/*bin/mkdir /tmp/rip 2> /dev/null
javac -d /tmp/rip $0
java -cp /tmp/rip Rip "$@"
exit
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.regex.Matcher;
@cyrilmottier
cyrilmottier / ClassA.java
Created January 10, 2013 09:16
Java puzzle: field instantiation
package com.cyrilmottier.test;
public class ClassA {
public ClassA() {
System.out.println("ClassA()");
method();
}
public void method() {
@devunwired
devunwired / GifDecoder.java
Last active January 26, 2024 21:14
An optimized implementation of GifDecoder for Android devices.
/**
* Copyright (c) 2013 Xcellent Creations, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@johnkil
johnkil / FileUtils.java
Last active February 9, 2021 21:13
File Util's. Set of basic static final methods for working with the file system on Android OS.
import java.io.File;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
/**
* File Util's.
@cyrilmottier
cyrilmottier / LicensesActivity.java
Created November 21, 2012 11:10
"Open source licenses" screen
package com.cyrilmottier.android.citybikes;
import android.os.Bundle;
import com.cyrilmottier.android.avelov.R;
import com.cyrilmottier.android.citybikes.app.BaseActivity;
public class LicensesActivity extends BaseActivity {
private WebView mWebView;
@romannurik
romannurik / CheatSheet.java
Last active May 16, 2023 13:42
Android helper class for showing cheat sheets (tooltips) for icon-only UI elements on long-press. This is already default platform behavior for icon-only action bar items and tabs. This class provides this behavior for any other such UI element.
/*
* Copyright 2012 Google 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
@thomasbiddle
thomasbiddle / librarian-puppet-rake-task
Created October 22, 2012 23:24
Librarian-Puppet Rake Task for Templating the Puppetfile
#!/usr/bin/ruby
require 'erb'
desc "Templates the Puppetfile to the specified environment"
task :template_puppetfile, [:env] do |t, args|
unless args[:env].nil?
@environment = args[:env]
read_file = 'Puppetfile.erb'
write_file = 'Puppetfile'