This file contains 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
//Given an integer array nums, | |
//find the contiguous subarray (containing at least one number) | |
//which has the largest sum and return its sum. | |
class Solution { | |
public int maxSubArray(int[] nums) { | |
if (nums.length == 1) | |
return nums[0]; | |
int sum = 0; |
This file contains 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
fun factorial(number: Int): Int { | |
var factor = 1 | |
return if (number <= 1) | |
factor | |
else { | |
(1 until number).forEach { factor*=(it+1) } | |
factor | |
} | |
} |
This file contains 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
#!/bin/bash | |
echo -e "yes\n<USERNAME>\n<PASSWORD>" | sudo openconnect <HOST> |
This file contains 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
<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" /> |
This file contains 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
@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(), |
This file contains 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
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>() | |
} |
This file contains 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
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()!!) |
This file contains 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
// 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) |
This file contains 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
public static String formatPrice(double priceAsDouble) { | |
NumberFormat formatter = NumberFormat.getInstance(); | |
if (Math.round(priceAsDouble * 100) % 100 == 0) { | |
formatter.setMaximumFractionDigits(0); | |
} | |
return formatter.format(priceAsDouble); | |
} |
This file contains 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
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; |