Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Perry christopherperry

View GitHub Profile
@JakeWharton
JakeWharton / README.md
Last active January 20, 2023 08:52
A JUnit @rule which launches an activity when your test starts. Stop extending gross ActivityInstrumentationBarfCase2!
View README.md
@granoeste
granoeste / EachDirectoryPath.md
Last active January 19, 2023 15:05
[Android] How to get the each directory path.
View EachDirectoryPath.md

System directories

Method Result
Environment.getDataDirectory() /data
Environment.getDownloadCacheDirectory() /cache
Environment.getRootDirectory() /system

External storage directories

@romannurik
romannurik / CheatSheet.java
Last active July 12, 2022 10:17
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.
View CheatSheet.java
/*
* 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
@abhiaiyer91
abhiaiyer91 / reduxSelectorPattern.md
Last active April 29, 2022 06:00
Redux Selector Pattern
View reduxSelectorPattern.md

Redux Selector Pattern

Imagine we have a reducer to control a list of items:

function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
  switch(action.type) {
    case 'SHOW_ALL_ITEMS':
      return action.data.items
    default:
@Takhion
Takhion / ArcUtils.java
Last active April 11, 2022 02:29
Collection of methods to achieve better circular arc drawing, as Canvas.drawArc() is unreliable. See the related article: https://medium.com/p/9155f49166b8
View ArcUtils.java
/**
* ArcUtils.java
*
* Copyright (c) 2014 BioWink GmbH.
*
* 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
@peter
peter / creating-edgerails-app.sh
Created June 30, 2012 21:03
Creating and Deploying an EdgeRails (Rails 4) Application to Heroku
View creating-edgerails-app.sh
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it
gem install bundler
# 1. Get edge Rails source (master branch)
git clone https://github.com/rails/rails.git
@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.
View Rip.java
/*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;
@kimkidong
kimkidong / gist:3346007
Created August 14, 2012 03:10
Convert YUV420 to RGB8888
View gist:3346007
// decode Y, U, and V values on the YUV 420 buffer described as YCbCr_422_SP by Android
// David Manpearl 081201
public void decodeYUV(int[] out, byte[] fg, int width, int height)
throws NullPointerException, IllegalArgumentException {
int sz = width * height;
if (out == null)
throw new NullPointerException("buffer out is null");
if (out.length < sz)
throw new IllegalArgumentException("buffer out size " + out.length
+ " < minimum " + sz);
@sebaslogen
sebaslogen / LiveObservable.kt
Created July 9, 2017 21:15
LiveObservable: Android lifecycle aware wrapper for an RxJava Observable
View LiveObservable.kt
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
import android.arch.lifecycle.OnLifecycleEvent
import com.jakewharton.rxrelay.BehaviorRelay
import rx.Observable
import rx.android.schedulers.AndroidSchedulers
import rx.functions.Action1
import rx.subscriptions.CompositeSubscription
@arpit
arpit / layout_transition_stagger.java
Created July 13, 2012 22:27
Stagger LayoutTransitions in Android
View layout_transition_stagger.java
package com.arpit.animatortest;
import android.animation.AnimatorSet;
import android.animation.LayoutTransition;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;