This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.firebase.utils; | |
| import java.util.Date; | |
| /** | |
| * Fancy ID generator that creates 20-character string identifiers with the | |
| * following properties: | |
| * | |
| * 1. They're based on timestamp so that they sort *after* any existing ids. | |
| * 2. They contain 72-bits of random data after the timestamp so that IDs won't |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| LocalActivityManager mgr = getLocalActivityManager(); | |
| Intent i = new Intent(this, SomeActivity.class); | |
| Window w = mgr.startActivity("unique_per_activity_string", i); | |
| View wd = w != null ? w.getDecorView() : null; | |
| if(wd != null) { | |
| mSomeContainer.addView(wd); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Context; | |
| import android.util.Log; | |
| public class Logger { | |
| private static final boolean shouldLog = true; | |
| public static void i(String tag, String msg) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int x = targetView.getTop() + targetView.getWidth() / 2; | |
| int y = targetView.getTop() + targetView.getHeight() / 2; | |
| int fromX = sourceView.getTop() + sourceView.getWidth() / 2; | |
| int fromY = sourceView.getTop() + sourceView.getHeight() / 2; | |
| final int dx = x - fromX; | |
| final int dy = y - fromY; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //In src folder | |
| public class HelloWorld { | |
| public static void main(String[] args) { | |
| System.out.println("Hello World!"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.graphics.Canvas; | |
| import android.graphics.Color; | |
| import android.graphics.ColorFilter; | |
| import android.graphics.Paint; | |
| import android.graphics.Rect; | |
| import android.graphics.RectF; | |
| import android.graphics.drawable.Drawable; | |
| import android.util.DisplayMetrics; | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static int blendColors(int color1, int color2, float ratio) { | |
| final float inverseRation = 1f - ratio; | |
| float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation); | |
| float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation); | |
| float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation); | |
| return Color.rgb((int) r, (int) g, (int) b); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Date; | |
| import java.util.Locale; | |
| import java.util.TimeZone; | |
| import java.text.SimpleDateFormat; | |
| import java.text.DateFormat; | |
| public class DateFormatterDemo { | |
| public static void main(String[] args) throws Exception { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Collection; | |
| import java.util.Iterator; | |
| import java.util.concurrent.LinkedTransferQueue; | |
| import java.util.concurrent.ThreadPoolExecutor; | |
| import java.util.concurrent.TimeUnit; | |
| import java.util.concurrent.TransferQueue; | |
| import java.util.concurrent.locks.ReentrantLock; | |
| public final class ScalableThreadPoolExecutor extends ThreadPoolExecutor { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Find the Levenshtein distance | |
| private int distance(String a, String b) { | |
| a = a.toLowerCase(); | |
| b = b.toLowerCase(); | |
| int[] costs = new int[b.length() + 1]; | |
| for (int j = 0; j < costs.length; j++) | |
| costs[j] = j; | |
| for (int i = 1; i <= a.length(); i++) { | |
| costs[0] = i; |