Skip to content

Instantly share code, notes, and snippets.

View SerggioC's full-sized avatar
🎯
Focusing

Sergio C SerggioC

🎯
Focusing
  • Portugal
View GitHub Profile
@SerggioC
SerggioC / Criar nova chave SSH.txt
Created August 15, 2024 15:25
Criar nova chave SSH
Criar nova chave SSH
1- Gerar chave:
ssh-keygen -t ed25519 -C "[email protected]"
2- Adicionar chave ao agente:
#macOS
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
@SerggioC
SerggioC / UnsafeOkHttpClient trustAllCerts
Created May 8, 2023 13:20
UnsafeOkHttpClient trustAllCerts
private fun getUnsafeOkHttpClientBuilder(): OkHttpClient.Builder {
try {
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
override fun checkClientTrusted(
chain: Array<java.security.cert.X509Certificate>,
authType: String
) {
}
override fun checkServerTrusted(
@SerggioC
SerggioC / load certificate from resources file
Created May 8, 2023 13:19
Load certificate from resources file
@Throws(
CertificateException::class,
KeyStoreException::class,
NoSuchAlgorithmException::class,
KeyManagementException::class
)
private fun getSSLConfig(context: Context): SSLContext {
val certificateFactory = CertificateFactory.getInstance("X.509")
context.resources.openRawResource(R.raw.tpv_certificate).use { inputStream ->
@SerggioC
SerggioC / IPEditText
Created September 6, 2022 16:34
IPEditText
import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.LinearLayout
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@SerggioC
SerggioC / get String from InputStream
Last active August 12, 2022 11:00
get String from InputStream
@Throws(java.lang.Exception::class)
fun convertStreamToString(input: InputStream?): String? {
input ?: return null
val reader = BufferedReader(InputStreamReader(input))
val sb = StringBuilder()
var line: String?
while (reader.readLine().also { line = it } != null) {
sb.append(line).append("\n")
}
reader.close()
@SerggioC
SerggioC / get InputStream from Uri
Created August 11, 2022 14:17
get InputStream from Uri
InputStream inputStream = context.getContentResolver().openInputStream(urifont);
@SerggioC
SerggioC / getUriFromAssetsFile
Created August 11, 2022 14:16
get Uri from Android assets file
Uri fontUri = new Uri.Builder()
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(BuildConfig.APPLICATION_ID)
.path(String.valueOf(R.font.roboto_regular))
.build();
@SerggioC
SerggioC / retrieveAllManifestPermissions
Created August 4, 2022 16:15
Retrieve All Android Manifest Permissions
@JvmStatic
fun retrieveAllManifestPermissions(context: Context): Array<String> {
return try {
context
.packageManager
.getPackageInfo(context.packageName, PackageManager.GET_PERMISSIONS)
.requestedPermissions
} catch (e: Exception) {
emptyArray()
}
@SerggioC
SerggioC / SHA hash with HMAC256 kotlin
Created July 10, 2022 21:28
SHA hash with HMAC256 kotlin
private fun generateHashWithHmac256(message: String): String? {
try {
val key = BuildConfig.HASH
val bytes = hmac(key.toByteArray(), message.toByteArray())
if (bytes != null) return bytesToHex(bytes)
} catch (e: Exception) {
e.printStackTrace()
}
return null
}
@SerggioC
SerggioC / write to Buffer from Retroft interceptor
Created July 10, 2022 21:28
write to Buffer from Retroft interceptor
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val firebaseToken = Utils.getFirebaseToken(context)
val originalRequest: Request = chain.request()
var newRequest = originalRequest.newBuilder()
.addHeader("content-type", "application/json;charset=UTF-8")
.addHeader("accept", "application/json")
.addHeader("api-version", "1.0")
.addHeader("authorization", "Bearer $firebaseToken")