Skip to content

Instantly share code, notes, and snippets.

View rezaiyan's full-sized avatar
👋

Ali Rezaiyan rezaiyan

👋
View GitHub Profile
package me.alirezaiyan.gist;
import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.util.AttributeSet;
/**
* @author rezaiyan (alirezaiyann@gmail.com)
* @since 3/13/18 21:42.
*
package com.ott.common.di;
/**
* @author rezaiyan (alirezaiyann@gmail.com)
* @since 6:29 PM.
*/
import android.support.annotation.NonNull;
package com.parvazyab.android.common.adapter;
import android.util.Log;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.lang.annotation.Annotation;
import okhttp3.ResponseBody;
public static String formatPrice(double priceAsDouble) {
NumberFormat formatter = NumberFormat.getInstance();
if (Math.round(priceAsDouble * 100) % 100 == 0) {
formatter.setMaximumFractionDigits(0);
}
return formatter.format(priceAsDouble);
}
@rezaiyan
rezaiyan / UploadFileWithRetrofit.kt
Last active January 14, 2019 11:48
Upload file with retrofit
// Activity
val file = File(path)
val requestFile = RequestBody.create(MediaType.parse(context.contentResolver.getType(data.data)), file)
val body = MultipartBody.Part.createFormData("avatar", file.name, requestFile)
presenter.uploadUserAvatar(body)
// Activity
// Endpoint.kt
@Multipart
@POST(Const.URL.USER_AVATAR_UPDATE)
@rezaiyan
rezaiyan / Retrofit Call coroutine extention
Last active October 28, 2018 06:58
It's an extension function to convert retrofit Call to a coroutine
suspend fun <T> Call<T>.await(): T = suspendCoroutine { continuation ->
enqueue(object : Callback<T> {
override fun onFailure(call: Call<T>, t: Throwable) {
continuation.resumeWithException(t)
}
override fun onResponse(call: Call<T>, response: Response<T>) {
if (response.isSuccessful)
continuation.resume(response.body()!!)
package com.weembee.sdk.base
import retrofit2.HttpException
sealed class Result<out Any> {
data class Ok<T: Any>(val value: T): Result<T>()
data class NetworkError(val code: Int): Result<Nothing>()
data class Error(val throwable: Throwable): Result<Nothing>()
}
@rezaiyan
rezaiyan / Binding.kt
Last active January 14, 2019 11:47
This is an inner Recyclerview sample with dataBindign
@BindingAdapter("setActorsData")
fun setAvatars(recyclerView: RecyclerView, list: ArrayList<Actor>) {
val context = recyclerView.context
val radius = context.resources.getDimension(R.dimen.list_radius)
val peek = context.resources.getDimension(R.dimen.list_peek)
val layoutManager = TurnLayoutManager(context,
TurnLayoutManager.Gravity.END,
TurnLayoutManager.Orientation.HORIZONTAL,
radius.toInt(),
peek.toInt(),
@rezaiyan
rezaiyan / Default for XWin copy.xml
Created January 15, 2019 11:43
Best keymap :))
<keymap version="1" name="Default for XWin copy" parent="Default for XWin">
<action id="$Copy">
<keyboard-shortcut first-keystroke="ctrl c" />
<keyboard-shortcut first-keystroke="ctrl insert" />
<keyboard-shortcut first-keystroke="ctrl #1000632" />
</action>
<action id="$Cut">
<keyboard-shortcut first-keystroke="ctrl x" />
<keyboard-shortcut first-keystroke="shift delete" />
<keyboard-shortcut first-keystroke="ctrl #1000637" />
@rezaiyan
rezaiyan / pleaseconnect.sh
Created February 16, 2019 09:54
It's a simple script to automate your connectivity to a ssh with OpenConnect
#!/bin/bash
echo -e "yes\n<USERNAME>\n<PASSWORD>" | sudo openconnect <HOST>