Created
May 20, 2017 16:21
-
-
Save DevPicon/2de88f80563cea69f6666fe415f2ae75 to your computer and use it in GitHub Desktop.
Algunos ejemplos de como usar Kotlin de una mejor manera
This file contains hidden or 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
fun getDataSource(): MysqlDataSource { | |
val fileInputStream = FileInputStream("myfile.properties") | |
val properties = Properties() | |
properties.load(fileInputStream) | |
val mySqlDataSource = MysqlDataSource()?.apply { | |
setURL(properties.getProperty("MYSQL_DB_URL")) | |
user = properties.getProperty("MYSQL_DB_USERNAME") | |
setPassword(properties.getProperty("MYSQL_DB_PASSWORD")) | |
port = properties.getProperty("MYSQL_DB_PORT").toInt() | |
databaseName = properties.getProperty("MYSQL_DB_NAME") | |
maxQuerySizeToLog = properties.getProperty("MYSQL_DB_QUERYSIZE").toInt() | |
} | |
return mySqlDataSource | |
} | |
fun makeDir(path: String) = File(path).apply { mkdirs() } |
This file contains hidden or 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
fun findPhoneNumber(number: String, locale: String = "MX"): String { | |
TODO("Implementa tu búsqueda") | |
} |
This file contains hidden or 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
fun String.countAmountOfX(): Int { | |
return this.length - this.replace("x", "").length | |
} |
This file contains hidden or 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
db?.let { | |
try { | |
db.beginTransaction() | |
comicValues.forEach { db.insert(ComicContract.ComicEntry.TABLE_NAME, null, it) } | |
db.setTransactionSuccessful() | |
} catch (e: SQLException) { | |
Log.e(javaClass.simpleName, "Ha ocurrido un error durante la inserción.", e) | |
} finally { | |
db.endTransaction() | |
} | |
} |
This file contains hidden or 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
fun getDefaultLocale(deliveryArea: String) = when (deliveryArea.toLowerCase()) { | |
"mexico", "peru" -> MyLocale.SPANISH | |
"brazil" -> MyLocale.PORTUGUESE | |
"usa" -> MyLocale.ENGLISH | |
else -> MyLocale.SPANISH | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment