- [Data Structures] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#data-structures)
- [Linked Lists] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#linked-lists)
- [Trees] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#trees)
- [Binary Trees] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#binary-trees)
- [Binary Search Tree] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#binary-search-tree)
- [Red-Black Tree] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#red-black-tree)
- [AVL Tree] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#avl-tree)
- [Tries] (https://gist.github.com/lawloretienne/6f7d7d92f72986f5ebd60f226d9044ee#tries)
This file contains 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
public class DeviceDimensionsHelper { | |
// DeviceDimensionsHelper.getDisplayWidth(context) => (display width in pixels) | |
public static int getDisplayWidth(Context context) { | |
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); | |
return displayMetrics.widthPixels; | |
} | |
// DeviceDimensionsHelper.getDisplayHeight(context) => (display height in pixels) | |
public static int getDisplayHeight(Context context) { | |
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); |
This file contains 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.text.SpannableStringBuilder; | |
import java.util.ArrayDeque; | |
import java.util.Deque; | |
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE; | |
/** A {@link SpannableStringBuilder} wrapper whose API doesn't make me want to stab my eyes out. */ | |
public class Truss { | |
private final SpannableStringBuilder builder; | |
private final Deque<Span> stack; |
This file contains 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
/* | |
* Copyright (C) 2016 Jeff Gilfelt. | |
* | |
* 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 |
This file contains 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
@file:Suppress("NOTHING_TO_INLINE") | |
import android.util.Log | |
import io.reactivex.* | |
inline fun <reified T> printEvent(tag: String, success: T?, error: Throwable?) = | |
when { | |
success == null && error == null -> Log.d(tag, "Complete") /* Only with Maybe */ | |
success != null -> Log.d(tag, "Success $success") | |
error != null -> Log.d(tag, "Error $error") |
This file contains 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
@Test | |
public void switchMap() throws Exception { | |
final List<String> items = Lists.newArrayList("a", "b", "c", "d", "e", "f"); | |
final TestScheduler scheduler = new TestScheduler(); | |
Observable.from(items) | |
.switchMap( s -> { | |
final int delay = new Random().nextInt(10); | |
return Observable.just(s + "x") |
This file contains 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
@Test | |
public void switchMap() throws Exception { | |
final List<String> items = Lists.newArrayList("a", "b", "c", "d", "e", "f"); | |
final TestScheduler scheduler = new TestScheduler(); | |
Observable.from(items) | |
.concatMap( s -> { | |
final int delay = new Random().nextInt(10); | |
return Observable.just(s + "x") |
This file contains 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 class HttpInterceptor implements Interceptor { | |
@Override | |
public Response intercept(Chain chain) throws IOException { | |
Request request = chain.request(); | |
//Build new request | |
Request.Builder builder = request.newBuilder(); | |
builder.header("Accept", "application/json"); //if necessary, say to consume JSON | |
This file contains 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
inline fun <reified T: Any> Activity.extra(key: String, default: T? = null) = lazy { | |
val value = intent?.extras?.get(key) | |
if (value is T) value else default | |
} | |
inline fun <reified T: Any> Activity.extraNotNull(key: String, default: T? = null) = lazy { | |
val value = intent?.extras?.get(key) | |
requireNotNull(if (value is T) value else default) { key } | |
} |
This file contains 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
inline fun <reified T: Any> Fragment.extra(key: String, default: T? = null) = lazy { | |
val value = arguments?.get(key) | |
if (value is T) value else default | |
} | |
inline fun <reified T: Any> Fragment.extraNotNull(key: String, default: T? = null) = lazy { | |
val value = arguments?.get(key) | |
requireNotNull(if (value is T) value else default) { key } | |
} |
OlderNewer