Skip to content

Instantly share code, notes, and snippets.

@atetc
atetc / PermissionUtils
Last active December 11, 2015 04:12
Helpful util class template for Android M Permissions
package ***.***.android.utils;
import android.Manifest;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v13.app.FragmentCompat;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
@KodeSeeker
KodeSeeker / LowestCommonAncestorBinaryTree.java
Created March 14, 2013 22:31
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree Avoid storing additional nodes in a data structure NOTE: This is not necessarily a binary search tree
/*
Approach similar to approach for Common ancestor for BST. Keep going down on one side(right or left) if both the nodes
are in the same side(right or left), else the current node is the lowest common ancestor*/
public Tree commonAncestor(Node root, Node p, Node q) {
// 1st check if p and q, both belong to the left of the current root node, if yes then recurse on the left side
if (covers(root.left, p) && covers(root.left, q)) // check out the covers subroutine, can be used elsewhere too!
return commonAncestor(root.left, p, q);
// else, check if both p and q are children of right side of the root, if yes, then recurse on the right side
if (covers(root.right, p) && covers(root.right, q))
package com.ewintory.udacity.popularmovies.ui.adapter;
import android.graphics.PorterDuff;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
@AndrewReitz
AndrewReitz / androidExtras.gradle
Last active December 22, 2015 21:08
Run Lint Tasks on Every Build (Android)
// Adds extra tasks to improve android usage
project.android.applicationVariants.all { variant ->
def adb = new File(project.android.sdkDirectory as File, '/platform-tools/adb')
def variantName = variant.name.capitalize()
def flavor = variant.flavorName
def buildType = variant.buildType.name
@Gregadeaux
Gregadeaux / JsonApiConverter.java
Last active April 15, 2016 15:25
JSONAPI Converter for RetroFit with RxJava and RetroLambda
package ai.cometandroid.network;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.LinkedHashTreeMap;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@mojavelinux
mojavelinux / Gemfile
Last active September 12, 2016 14:24
Guard AsciiDoc and LiveReload minimal setup
source 'https://rubygems.org'
gem 'asciidoctor'
gem 'guard-asciidoc', :github => 'asciidoctor/guard-asciidoc'
gem 'guard-livereload'
gem 'rb-inotify', '~> 0.9.0'
@venator85
venator85 / LibraryProjectTestRunner.java
Created September 6, 2016 10:43
A Robolectric test runner for library projects compatible with Android Gradle plugin 2.2.0-alpha6 and later
import org.junit.runners.model.InitializationError;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.internal.bytecode.InstrumentationConfiguration;
import org.robolectric.manifest.AndroidManifest;
import org.robolectric.res.FileFsFile;
import org.robolectric.res.FsFile;
public class LibraryProjectTestRunner extends RobolectricTestRunner {
/*
* Copyright (C) 2015 Jared Rummler <jared.rummler@gmail.com
*
* 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
@dlew
dlew / gist:3fee09af5ff946997551
Last active December 24, 2017 05:04
Android library artifact tasks
if (project.android.hasProperty('libraryVariants')) {
android.libraryVariants.all { variant ->
Task javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
group = 'artifact'
description "Generates Javadoc for $variant.name"
// Source files from the variant
source = variant.javaCompiler.source
// Classpath from the variant + android.jar
@mislavs
mislavs / BooksAdapter
Created October 29, 2014 19:58
RecyclerView.Adapter implementation for displaying a list of Book objects.
package com.msvs.bookshelf.adapters;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;