Skip to content

Instantly share code, notes, and snippets.

View alorma's full-sized avatar
🤡

Bernat Borrás Paronella alorma

🤡
View GitHub Profile
@kchodorow
kchodorow / branch.sh
Created September 23, 2014 15:11
See all git branches with descriptions and last commit date
#!/bin/bash
# Shows branches with descriptions
branches=$(git for-each-ref --format='%(refname)' refs/heads/ | sed 's|refs/heads/||')
for branch in $branches; do
last_used=$(git show --pretty=format:"%Cgreen%cr%Creset" $branch | head -1)
desc=$(git config branch.$branch.description)
if [ $branch == $(git rev-parse --abbrev-ref HEAD) ]; then
branch="*\t$last_used\t\033[0;32m$branch\033[0m"
else
@MarioPerezEsteso
MarioPerezEsteso / InfoPantalla.java
Created April 12, 2015 14:35
Obtener información de la pantalla en Android
Display display = getWindowManager().getDefaultDisplay();
String displayName = display.getName();  // minSdkVersion=17+
Log.i(TAG, "Pantalla          = " + displayName);
 
// Tamaño en píxeles
@sergiandreplace
sergiandreplace / HorizontalListView.java
Created January 22, 2014 15:48
An horizontal listview working just as a simple listview
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/blue_facebook_dark">
<item>
<shape android:shape="rectangle" >
<corners android:radius="10dp"/>
<solid android:color="@color/blue_facebook"/>
</shape>
</item>
</ripple>
@ffgiraldez
ffgiraldez / ToolbarActivity.java
Last active May 4, 2016 16:11
Disable toolbar scroll flag when content it's not enough to fill the screen
public class ToolbarActivity extends AppCompatActivity {
// Set the flags that fit your needs
private static final int ENABLED_SCROLL_BEHAVIOR = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS | AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL;
private static final int DISABLED_SCROLL_BEHAVIOR = 0;
private static final int SCROLL_DOWN = 1;
//Injected via ButterKnife (http://jakewharton.github.io/butterknife)
@InjectView(R.id.toolbar)
Toolbar toolbar;
@InjectView(R.id.recyclerview)
public final class Result<S, F> {
private final Optional<S> success;
private final Optional<F> failure;
public Result(Optional<S> success, Optional<F> failure) {
this.success = success;
this.failure = failure;
}
@pkramme
pkramme / getch.h
Created July 3, 2016 14:48
getch.h
#ifndef _GETCH_H_
#define _GETCH_H_
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
/* reads from keypress, doesn't echo */
int getch(void)
{
@alxsimo
alxsimo / RxFirebaseRemoteConfig.java
Last active December 15, 2016 16:42
[Rx] RxFirebaseRemoteConfig
package com.milanuncios.milanunciosandroid.common.remoteconfig;
import com.alexsimo.toolbelt.optional.Optional;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
import com.milanuncios.milanunciosandroid.BuildConfig;
import java.util.Map;
import rx.AsyncEmitter;
import rx.Observable;
@zeuxisoo
zeuxisoo / gist:1008973
Created June 5, 2011 13:44
[Android] Create and Remove Desktop Shortcut

Create

private void addShortcut(){  
	Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
          
	// Shortcut name
	shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));  
	shortcut.putExtra("duplicate", false);	// Just create once
@rocboronat
rocboronat / DarkOrLightColour.java
Last active June 30, 2018 19:04
Know if a text on a dynamic background colour must be black or white to be easy to read
int color = palette.getVibrantColor(defaultColor);
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
row.setBackgroundColor(color);
//@see http://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black
double luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;