Skip to content

Instantly share code, notes, and snippets.

View ipereziriarte's full-sized avatar
🦄
Building Unicorns

Imanol Pérez Iriarte ipereziriarte

🦄
Building Unicorns
View GitHub Profile
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 Circle Internet Financial
*
* 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
@ipereziriarte
ipereziriarte / coverage_report.gradle
Last active August 29, 2015 14:15
Jacoco reports for unit tests in android studio
apply plugin: 'jacoco'
task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
reports {
xml.enabled false
csv.enabled false
html {
enabled true
destination "${buildDir}/jacocoHtml"
}
10-30 16:12:42.375 17465-17465/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.feverup.fever, PID: 17465
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.feverup.fever/com.feverup.fever.ui.activities.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
@ipereziriarte
ipereziriarte / contextual_action_bar
Created July 1, 2014 13:27
Contextual Action bar
private void showActionMode() {
mIsActionMode = true;
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_TITLE | ActionBar
.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
actionBar.setCustomView(mCustomActionBarView);
}
@ipereziriarte
ipereziriarte / magic_numbers
Created February 24, 2014 13:13
Snippet from a popular messaging app
final int arg0 = type;
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int action = 0;
if (arg0 == 1) {
if (i == 0) {
action = 0;
} else if (i == 1) {
action = 1;
@ipereziriarte
ipereziriarte / build.gradle
Created January 29, 2014 22:17
Base build file for coursera Assignments
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
@ipereziriarte
ipereziriarte / showFragment
Created January 25, 2014 12:02
Method to show a fragment properly
private void showFragment(int fragmentIndex, boolean addToBackStack) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
for (int i = 0; i < fragments.length; i++) {
if (i == fragmentIndex) {
transaction.show(fragments[i]);
} else {
transaction.hide(fragments[i]);
}
}
@ipereziriarte
ipereziriarte / git_aliases
Last active January 3, 2016 17:59
Git Aliases
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
ld = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=relative
le = log --oneline --decorate
filelog = log -u
fl = log -u
dl = "!git ll -1"
dlc = diff --cached HEAD^
@ipereziriarte
ipereziriarte / clickDelegate.java
Created December 19, 2013 17:43
A click delegate to increase the click area.
final View parent = (View) mShowDropOffBtn.getParent();
if (parent != null) {
parent.post(new Runnable() {
@Override
public void run() {
final Rect hitRect = new Rect();
parent.getHitRect(hitRect);
hitRect.right = hitRect.right - hitRect.left;
hitRect.bottom = hitRect.bottom - hitRect.top;