Skip to content

Instantly share code, notes, and snippets.

View lawloretienne's full-sized avatar
💭
Check out the surf report app I'm working on https://pitted.app

Etienne Lawlor lawloretienne

💭
Check out the surf report app I'm working on https://pitted.app
View GitHub Profile
  • Consider static factory methods instead of constructors
    • One advantage of static factory methods is that, unlike constructors, they have names.
    • A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked.
    • A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type.
    • A fourth advantage of static factory methods is that they reduce the verbosity of creating parameterized type instances.
    • The main disadvantage of providing only static factory methods is that classes without public or protected constructors cannot be subclassed.
    • A second disadvantage of static factory methods is that they are not readily distinguishable from other static methods.
  • Consider a builder when faced with many constructor parameters
  • The telescoping constructor pattern works, but it is hard to write client code when there are many parameters, and hard
@OnClick(R.id.fab)
public void onFiltersButtonClicked(View view) {
Event event = new Event(EventNames.EVENT_FILTERS_FAB_CLICKED, null);
EventLogger.logEvent(event);
if(getActivity().isFinishing())
return;
Intent intent = new Intent(view.getContext(), EventFiltersActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  • CacheControl.FORCE_CACHE adds an only-if-cache flag and also sets the max-stale to a very high value which overrides the max-stale value.
  • The max-age request directive indicates that the client is unwilling to accept a response whose age is greater than the specified number of seconds. Unless the max-stale request directive is also present, the client is not willing to accept a stale response.
  • The max-stale request directive indicates that the client is willing to accept a response that has exceeded its freshness lifetime. If max-stale is assigned a value, then the client is willing to accept a response that has exceeded its freshness lifetime by no more than the specified number of seconds.
  • The max-age request directive is the oldest that a response can be, as long as the Cache-Control from the origin server indicates that it is still fresh. The max-stale request directive indicates that, even if the response is known to be stale, you will also accept it as long as it's only stale by
public class NetworkLogUtility {
public static void logFailure(Call call, Throwable throwable){
if(call != null){
if (call.isCanceled())
Timber.e("Request was cancelled");
Request request = call.request();
if(request != null){
HttpUrl httpUrl = request.url();
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = recyclerView.getChildCount();
int totalItemCount = recyclerView.getAdapter().getItemCount();
int[] positions = layoutManager.findFirstVisibleItemPositions(null);
int firstVisibleItem = positions[1];
if (!isLoading && !isLastPage) {
public class RxImageView extends ImageView {
// region Member Variables
private PublishSubject<Boolean> publishSubject = PublishSubject.create();
// endregion
// region Constructors
public RxImageView(Context context) {
super(context);
}
  • Functional Programming is a model of programming that transform and compose stream of immutable sequences by applying map, filter and reduce. Events are immutable because you can't change history.
  • Reactive Programming is a model of programming focuses on data flow and change propagation.
  • ReactiveX is an API that focuses on asynchronous composition and manipulation of observable streams of data or events by using a combination of the Observer pattern, Iterator pattern, and features of Functional Programming.
  • RxJava is the open-source implementation of ReactiveX in Java.
  • RxJava is a Java VM implementation of ReactiveX (Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.
  • RxAndroid is a lightweight extension to RxJava that providers a Scheduler for Android’s Main Thread, as well as the ability to create a Scheduler that runs on any given Android Handler class.
  • The two main classes are Observable and Subscriber.
  • `O
while true; do
    ./adb shell input swipe 100 400 4000 400 400;
done
public class CustomViewGroup extends FrameLayout {
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
Timber.d("");
if(event != null){
int keyCode = event.getKeyCode();
if(keyCode == KeyEvent.KEYCODE_BACK){
// hide search suggestions UI