Skip to content

Instantly share code, notes, and snippets.

View arifNislam's full-sized avatar

Md. Ariful Islam arifNislam

View GitHub Profile
@arifNislam
arifNislam / ByteArray.kt
Created April 18, 2018 13:29 — forked from fabiomsr/ByteArray.kt
ByteArray and String extension to add hexadecimal methods in Kotlin
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])
@arifNislam
arifNislam / MockResponseInterceptor.java
Created April 26, 2018 12:57 — forked from mbunyard/MockResponseInterceptor.java
OkHttp3 interceptor which provides a mock response from local resource file.
package com.rogerthat.network.util;
import android.content.Context;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import okhttp3.Interceptor;
@arifNislam
arifNislam / AppInfoActivity.kt
Last active October 15, 2018 14:09
Application information in multi-module android project
class AppInfoActivity : AppCompatActivity() {
private val tag = javaClass.simpleName
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d(tag, "Application Id: ${applicationInfo.packageName}")
val packageInfo = packageManager.getPackageInfo(applicationInfo.packageName, 0)
Log.d(tag, "Version name: ${packageInfo.versionName}")
Log.d(tag, "Version code: ${packageInfo.versionCode}")
/**
* Implementation of [SSLSocketFactory] that adds [TlsVersion.TLS_1_2] as an enabled protocol for every [SSLSocket]
* created by [delegate].
*
* [See this discussion for more details.](https://github.com/square/okhttp/issues/2372#issuecomment-244807676)
*
* @see SSLSocket
* @see SSLSocketFactory
*/
class Tls12SocketFactory(private val delegate: SSLSocketFactory) : SSLSocketFactory() {