Skip to content

Instantly share code, notes, and snippets.

View prokash-sarkar's full-sized avatar
🎯
Focusing

Prokash Sarkar prokash-sarkar

🎯
Focusing
View GitHub Profile
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
public class HelloWorld {
@prokash-sarkar
prokash-sarkar / Android Transparent Color Codes
Created January 12, 2016 04:32
A list of transparent color codes that can be used to get the exact amount of transparency.
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
@prokash-sarkar
prokash-sarkar / Facebook KeyHash
Created December 18, 2017 13:52
A simple code snippet for generating Facebook KeyHash in Android
public void getKeyHash(Context context) {
try {
PackageInfo info = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.i("Base64", Base64.encodeToString(md.digest(),Base64.NO_WRAP));
}
} catch (PackageManager.NameNotFoundException e) {
Log.d("Name not found", e.getMessage(), e);
// ./gradlew clean build generateRelease
apply plugin: 'maven'
def groupId = project.PUBLISH_GROUP_ID
def artifactId = project.PUBLISH_ARTIFACT_ID
def version = project.PUBLISH_VERSION
def localReleaseDest = "${buildDir}/release/${version}"
task androidJavadocs(type: Javadoc) {
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@prokash-sarkar
prokash-sarkar / File Header.kt
Created September 8, 2019 16:36
IntellijIDEA File Header Example
/**
@author ${USER}
@since ${DAY_NAME_SHORT}, ${MONTH_NAME_FULL} ${DAY}, ${YEAR}
@version 1.0
**/
@prokash-sarkar
prokash-sarkar / Scoping Functions.kt
Created September 15, 2019 06:33
Exmaples of 5 Kotlin Scoping functions, Run, With, Let, Apply, Also
class ScopingFunctions {
fun main() {
val firstPerson = Person("Prokash", 28, "Programmer")
val secondPerson = Person("Elizabeth", 34, "Singer")
//Calls the specified function block with this value as its receiver and returns its result.
run {
if (firstPerson.age > secondPerson.age) firstPerson else secondPerson
}.printPerson()
@prokash-sarkar
prokash-sarkar / LiveDataReactiveStreams.kt
Created September 28, 2019 04:39
Using LiveDataReactiveStreams to convert Flowable
fun <T> LiveData<T>.toFlowable(owner: LifecycleOwner): Flowable<T> =
Flowable.fromPublisher(LiveDataReactiveStreams.toPublisher(owner, this))
fun <T> Flowable<T>.toLiveData(): LiveData<T> = LiveDataReactiveStreams.fromPublisher(this)
@prokash-sarkar
prokash-sarkar / BaseViewModel.kt
Last active November 7, 2019 12:36
BaseViewModel
abstract class BaseViewModel: ViewModel()
{
protected val _viewState: MutableLiveData<ViewState> = MutableLiveData()
// don't expose the MutableLiveData outside of the class
val viewState: LiveData<ViewState>
get() = _viewState // only getter / no setter
fun setViewState(viewState: ViewState){
@prokash-sarkar
prokash-sarkar / AuthenticationInterceptor.kt
Last active January 27, 2021 09:18
Example of runtime modification of an auth token and base URL of the okHttp client using Interceptor and Dagger injection.
class AuthenticationInterceptor @Inject constructor(baseUrl: String, jwtToken: String) :
Interceptor {
private var baseUrl: HttpUrl
private var jwtToken: String
companion object {
private const val LOG_TAG = "AuthenticationInterceptor:"
private const val AUTHORIZATION = "Authorization"
private const val BEARER = "Bearer"