Skip to content

Instantly share code, notes, and snippets.

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

sebastian tellez gorrotowi

🏠
Working from home
View GitHub Profile
@gorrotowi
gorrotowi / UtilsExtensions.java
Created November 29, 2016 18:27
Methods to get current and past Months and name of them
public static int getCurrentYear() {
return Calendar.getInstance().get(Calendar.YEAR);
}
public static int[] getMonthsPos() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 0);
int month1 = new Timestamp(calendar.getTime().getTime()).getMonth();
@gorrotowi
gorrotowi / adbwifi.bash
Created December 24, 2016 19:21
With this commands you can deploy your Android project in a physic device with out usb cable
#ADB enable:
adb tcpip 5555
adb connect device-ip:5555
#ADB to disable:
adb -s device-ip:5555 usb
@gorrotowi
gorrotowi / build_apk.bash
Last active February 23, 2017 22:25
Commands to build a signed APK in terminal for react_native project
#start react-native in port 8088
$ react-native start --port=8088
#download the bundle of android know bug in react-native
$ curl http://localhost:8088/index.android.bundle?platform=android
#inside react-native's android project build the assembleRelease flavor
$ ./gradlew assembleRelease
#go to the apk's android folder
class OPHandleError {
fun getError(code: Int): Throwable {
val messageError: Throwable
when (code) {
//OpenPay General Errors
1000 -> messageError = Throwable("Error interno del servidor")
1001 -> messageError = Throwable("Error al identificar usuario, intenta nuevamente")
1002 -> messageError = Throwable("Error al identificar usuario, intenta nuevamente")
1003 -> messageError = Throwable("La operación no se pudo completar por que el valor de uno o más de los parametros no es correcto")
@gorrotowi
gorrotowi / Galleta.kt
Created October 12, 2017 16:43
Platzi POJO Java vs Kotlin
data class Galleta(val sabor: String, val chispas: String)
@gorrotowi
gorrotowi / bplanet.kt
Last active December 13, 2017 18:20
bplanet
import java.io.File
import java.io.InputStream
import kotlin.math.sqrt
fun main(args: Array<String>) {
val inputStream: InputStream = File("src/test_case.txt").inputStream()
val lineList = mutableListOf<String>()
inputStream.bufferedReader().useLines { lines ->
@gorrotowi
gorrotowi / alphaHexColor.kt
Last active January 5, 2018 21:29
How to set Alpha for HexColor
import kotlin.math.roundToInt
fun main(args: Array<String>) {
println("#2c79a5".alphaColor(0.5F))
println(getColorIntWithAlpha("#2c79a5",0.5F))
}
fun getColorIntWithAlpha(hexColor: String, alpha: Float): Int =
Color.parseColor(hexColor.alphaColor(alpha))
@gorrotowi
gorrotowi / ifnotnull.kt
Created July 26, 2018 00:16
Use data if objects is not null
val name:String? = null
val l:Int = if(name != null) name.length else -1
print(l) // -1
@gorrotowi
gorrotowi / elvisoperatorsample.kt
Created July 26, 2018 00:25
Use elvis operator instead if/else
val name:String? = null
val l:Int = name?.length ?: -1
print(l) // -1
val name:String? = null
var length:Int
if(name != null){
length = name.length
} else{
length = -1
}
print(length) // -1