Skip to content

Instantly share code, notes, and snippets.

@CarlosMChica
CarlosMChica / ActionBarBackgroundWorkaround.java
Last active August 29, 2015 14:06
Workaround to change action bar background dynamically
//Looks like drawable is still not ready to be set when applying it to the action bar
//in versions bellow 17 with default method. The action bar needs to be redrawed and it can be forced by using
//the following workarround
public void setActionBarbackground(ColorDrawable colorDrawable) {
ActionBar actionBar = getActionBar();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
actionBar.setBackgroundDrawable(colorDrawable);
//switch true/false values if title is not needed
actionBar.setDisplayShowTitleEnabled(false);
@CarlosMChica
CarlosMChica / DividerItemDecoration
Last active August 29, 2015 14:10
DividerItemDecoration
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.support.v7.widget.RecyclerView;
import android.view.View;
@CarlosMChica
CarlosMChica / animate transition between placeholder and image
Created December 12, 2014 18:06
how to animate transition between placeholder and image.
Dev tip: how to animate transition between placeholder and image.
//Create a bitmap drawable from the bitmap to be shown
Drawable bitmapDrawable = new BitmapDrawable(context,bitmap);
Drawable[] layers = new Drawable[] {
imageView.getDrawable(), //Current placeholder
bitmapDrawable //Image to show
};
@CarlosMChica
CarlosMChica / FizzBuzz
Created November 28, 2016 15:23
Functional FizzBuzz
class FizzBuzz {
private val fizzes = cycle("", "", "Fizz")
private val buzzes = cycle("", "", "", "", "Buzz")
private val fizzBuzzes = fizzes.zip(buzzes).map(x => x._1 ++ x._2)
private lazy val fizzBuzz = fizzBuzzes.zip(Stream.from(1)).map(x => if (x._1.isEmpty) x._2.toString else x._1)
def convert(x: Int): String = {
convert(1 to x)(x - 1)
}
mostPopularLetterWithCount :: String -> (Char, Int)
mostPopularLetterWithCount xs =
swap . maximum . fmap swap . Map.toList . Map.fromListWith (+) $ [(x, 1) | x <- xs, not . isSpace $ x]
mostPopularWordWithCount :: String -> (String, Int)
mostPopularWordWithCount xs =
swap . maximum . fmap swap . Map.toList . Map.fromListWith (+) $ [(x, 1) | x <- words xs]