Skip to content

Instantly share code, notes, and snippets.

View diefferson's full-sized avatar
🎯
Focusing

Diefferson Santos diefferson

🎯
Focusing
View GitHub Profile
@diefferson
diefferson / JsonEncodeError.php
Created April 11, 2017 19:26
Returns what error occurred while executing the json_decode or json_encode functions
<?php
//After executing json_encode or json_decode call this function
function jsonError(){
$errors = "";
switch (json_last_error()) {
case JSON_ERROR_NONE:
$errors .= ' - No errors';
break;
@diefferson
diefferson / Keymap.sublime-keymap
Created April 11, 2017 19:42
Sublime Settings
[
{ "keys": ["f1"], "command": "goto_documentation" },
{ "keys": ["f6"], "command": "expand_fqcn" },
{ "keys": ["shift+f6"], "command": "expand_fqcn", "args": {"leading_separator": true} },
{ "keys": ["f5"], "command": "find_use" },
{ "keys": ["f4"], "command": "import_namespace" },
{ "keys": ["shift+f12"], "command": "goto_definition_scope" },
]
@diefferson
diefferson / webSocket client android
Last active September 27, 2017 14:57
Websocket client with android
package br.com.disapps.sockettest.websocket;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.jakewharton.rxrelay2.PublishRelay;
import br.com.disapps.sockettest.Message;
@diefferson
diefferson / CSVUtils.java
Created October 25, 2017 23:55
CSV Parser Java
package br.com.diefferson;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
@diefferson
diefferson / Preferences.java
Created December 12, 2017 00:47
Android Preferences Example
package com.eventifly.core.data.prefs;
import android.content.Context;
import android.content.SharedPreferences;
import com.eventifly.core.data.model.Profile;
import com.eventifly.core.data.model.Settings;
import com.eventifly.core.data.model.Tag;
import com.eventifly.core.data.ws.RestClient;
import com.eventifly.core.data.ws.response.AuthLoginResponse;
@diefferson
diefferson / DownloadClient.kt
Created June 1, 2018 18:07
Retrofit Download Progress
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.net.ssl.HostnameVerifier
object DownloadClient{
@diefferson
diefferson / CoroutinesUseCase.kt
Created September 26, 2018 13:53
Use Case with Coroutines
/**
* Abstract class for a UseCase that returns an instance of a [T].
*/
abstract class UseCase<T, in Params> internal constructor(
private val postExecutionContext:CoroutineContext,
private val logException: LogException) : CoroutineScope {
private val executionJob: Job by lazy { Job() }
override val coroutineContext: CoroutineContext by lazy {
@diefferson
diefferson / AsyncLiveData.kt
Created October 12, 2018 12:59 — forked from STAR-ZERO/AsyncLiveData.kt
LiveData + Kotlin Coroutine
// compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:0.16"
// compile "android.arch.lifecycle:runtime:1.0.0-alpha3"
// compile "android.arch.lifecycle:extensions:1.0.0-alpha3"
// kapt "android.arch.lifecycle:compiler:1.0.0-alpha3"
class AsyncLiveData<T> private constructor(private val exec: suspend () -> T) : LiveData<T>() {
private var observer: Observer<T>? = null
private var job: Job? = null
@diefferson
diefferson / startServiceSample.kt
Last active November 23, 2018 13:57
Start Service Android O
fun startService(context: Context){
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(Intent(context, MyService::class.java))
} else {
context.startService(Intent(context, MyService::class.java))
}
}catch (e :Exception){
e.stackTrace
}
@diefferson
diefferson / CoroutinesUtils.kt
Last active November 28, 2018 13:30
CoroutinesUtils
package br.com.futmundi.app.util
import br.com.myapp.data.repository.exception.KnownError
import br.com.myapp.data.repository.exception.KnownException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.android.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
fun <T> CoroutineScope.safeAsync(action: suspend () -> T,