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
LiveData<String> source = ....; // | |
final MediatorLiveData<String> result = new MediatorLiveData<>(); | |
result.addSource(source, new Observer<String>() { | |
@Override | |
public void onChanged(@Nullable String x) { | |
// do something here | |
} | |
}); |
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
class GetTodoUsecases(private val repository: TodoRepository) { | |
operator fun invoke() = repository.getTodos() | |
} |
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
class TodoRepository(private val api: TodoApi) { | |
fun getTodos(): ResponseResult<Todo> { | |
val data = MutableLiveData<Todo>() | |
val error = MutableLiveData<ResponseError>() | |
api.getTodos().enqueue(object : Callback<Todo> { | |
override fun onResponse(call: Call<Todo>, response: Response<Todo>) { | |
if (response.isSuccessful) { | |
data.value = 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
import android.arch.lifecycle.LiveData | |
data class ResponseError(val code: Int? = null, val messages: String? = null) | |
data class ResponseResult<T>(val data: LiveData<T>, val error: LiveData<ResponseError>) |
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
import com.google.gson.annotations.SerializedName | |
// https://jsonplaceholder.typicode.com/todo/1 | |
class Todo( | |
@SerializedName("userId") val userId: Int, | |
@SerializedName("id") val id: Int, | |
@SerializedName("title") val title: String, | |
@SerializedName("completed") val completed: Boolean | |
) |
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
from __future__ import print_function | |
from keras.datasets import mnist | |
import matplotlib.pyplot as plt | |
import keras | |
# input image dimensions | |
def plot_image(xTest,YRealValue,YPredic): | |
plt.figure(3) | |
fig, axes = plt.subplots(10, 10, figsize=(28, 28)) | |
test_images = xTest.reshape(-1, 28, 28) |
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
class SearchRepositoriesViewModel(private val repository: GithubRepository) : ViewModel() { | |
private val queryLiveData = MutableLiveData<String>() | |
/** | |
* Search a repository based on a query string. | |
*/ | |
fun searchRepo(queryString: String) { | |
queryLiveData.postValue(queryString) | |
} |
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
import android.util.Log | |
import retrofit2.Response | |
import java.util.regex.Pattern | |
/** | |
* Common class used by API responses. | |
* @param <T> the type of the response object |
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
from flask import Flask | |
import broadlink | |
app = Flask(__name__) | |
TV_POWER_BUTTON = b'&\x00x\x00\x00\x01*\x93\x14\x11\x14\x11\x146\x14\x11\x14\x11\x14\x12\x14\x11\x14\x11\x146\x146\x14\x11\x146\x145\x146\x146\x146\x14\x11\x14\x11\x14\x11\x146\x14\x11\x14\x12\x14\x11\x14\x11\x146\x146\x145\x14\x12\x145\x146\x146\x145\x14\x00\x055\x00\x01)I\x14\x00\x0cL\x00\x01+H\x15\x00\x0cM\x00\x01*H\x14\x00\x0cS\x00\x01*H\x14\x00\x0cH\x00\x01*H\x15\x00\x0cL\x00\x01,G\x15\x00\r\x05' | |
devices = broadlink.discover(timeout=5, local_ip_address='192.168.1.171') # local_ip_address is my raspberryPi IP | |
if(is_devices_found()): |
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
def func(n): | |
return func_1(0, 1, n) | |
def func_1(a, b, n): | |
if( n > 1): | |
return func_1(b, a+b, n-1) | |
else: | |
return b |