Skip to content

Instantly share code, notes, and snippets.

View SamueldaCostaAraujoNunes's full-sized avatar
🏠
Working from home

Samuel da Costa Araujo Nunes SamueldaCostaAraujoNunes

🏠
Working from home
View GitHub Profile
mqtt:
sensor:
- name: "saturn_3_ultra_id"
state_topic: '/sdcp/status/{mainboardID}'
value_template: '{{ value_json.Id }}'
- name: "saturn_3_ultra_current_status"
state_topic: '/sdcp/status/{mainboardID}'
value_template: >
{% set status = value_json.Data.Status.CurrentStatus %}
import socket
import time
import json
SATURN_UDP_PORT = 3000
MQTT_PORT = 1883
TIMEOUT = 2
class SaturnPrinter:
def __init__(self, addr, data):
@RequiresApi(Build.VERSION_CODES.N)
class NetworkConnectivityObserver @Inject constructor(
context: Context
) {
enum class Status {
AVAILABLE, UNAVAILABLE, LOSING, LOST;
fun hasConnection(): Boolean = this == AVAILABLE || this == LOSING
}
data class NotFoundError(val message: String) : Result.Error.ErrorResponse()
#!/bin/sh
echo " "
echo " ################################################"
echo " ## Did you execute 1_format_extroot.sh first? ##"
echo " ################################################"
echo " "
read -p "Press [ENTER] if YES ...or [ctrl+c] to exit"
class FlowResultCallAdapter<R>(
private val responseType: Type,
private val annotations: Array<out Annotation>
) : CallAdapter<R, Flow<Result<R>>> {
override fun adapt(call: Call<R>): Flow<Result<R>> {
return flow {
emit(
suspendCancellableCoroutine { continuation ->
call.clone().enqueue(object : Callback<R> {
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@Repeatable
annotation class ErrorType(val httpStatusCodeError: HttpStatusCodeError, val kClass: KClass<out Result.Error.ErrorResponse>)
fun parseError(statusCode: Int, responseBody: ResponseBody?, annotations: Array<out Annotation>): Result.Error.ErrorResponse? {
val errorBody = responseBody?.charStream()?.readText() ?: return null
val errorType: ErrorType = annotations.find {
it is ErrorType && it.httpStatusCodeError.statusCode == statusCode
enum class GameType(val xp: Int, val duration: Float) {
DisputaDaSpike(1000, 0.167F),
SemClassificacao(4000, 0.548F),
Disparada(800, 0.167F),
MataMata(900, 0.15F),
Replicacao(1700, 0.25F),
BatalhaNevada(825, 0.1F),
}
binding.tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
val position = tab?.position ?: 0
val gameType: GameType = GameType.values()[position]
setListeners(gameType)
}
override fun onTabReselected(tab: TabLayout.Tab?) {}
override fun onTabUnselected(tab: TabLayout.Tab?) {}
})
abstract class BaseListAdapter<T, U : ViewDataBinding>(
callback: DiffUtil.ItemCallback<T>
) : ListAdapter<T, BaseViewHolder<T, U>>(callback) {
abstract fun bindItem(item: T, viewBinding: U)
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): BaseViewHolder<T, U> {