This file contains hidden or 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
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] |
This file contains hidden or 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
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) | |
} |
This file contains hidden or 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
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 | |
}; |
This file contains hidden or 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.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; |
This file contains hidden or 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
//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); |