Skip to content

Instantly share code, notes, and snippets.

@matiangul
matiangul / xml_process.kt
Created March 6, 2017 20:16
Process xml content using java StAX API
while (xmlReader.hasNext()) {
xmlReader.next()
if (xmlReader.eventType == XMLStreamConstants.START_ELEMENT && xmlReader.localName == "F") {
origin = xmlReader.getAttributeValue(null, "o")
destination = xmlReader.getAttributeValue(null, "d")
route = xmlReader.getAttributeValue(null, "r")
} else if (xmlReader.eventType == XMLStreamConstants.START_ELEMENT && xmlReader.localName == "T") {
ticketCode = xmlReader.getAttributeValue(null, "t")
} else if (xmlReader.eventType == XMLStreamConstants.START_ELEMENT && xmlReader.localName == "FF") {
@matiangul
matiangul / data_source_configuration.kt
Created March 7, 2017 17:18
Hikari Data Source configuration
val dataSource = HikariDataSource(HikariConfig(Properties().apply {
setProperty("jdbcUrl", "jdbc:mysql://localhost/rcs_parsing_challenge")
setProperty("dataSource.user", "root")
setProperty("dataSource.password", "password")
put("dataSource.cachePrepStmts", true)
put("dataSource.useServerPrepStmts", true)
put("dataSource.rewriteBatchedStatements", true)
put("maximumPoolSize", 21)
put("idleTimeout", 30000)
put("autoCommit", false)
@matiangul
matiangul / kotlin_http_query_params.kt
Created July 4, 2017 11:34
kotlin http query params
fun getQuery() = mapOf("page" to page)
.filterValues { it != null }
.map { "${it.key}=${it.value}" }
.joinToString(separator = "&", prefix = "?")
.removeSuffix("?")
@matiangul
matiangul / MapMatrix.java
Created January 31, 2019 16:54
Wzorzec projektowy adapter
/**
* @author Mateusz Angulski <mateusz@angulski.pl>.
*/
public class MapMatrix implements Matrix {
private final int size;
private final HashMap<String, Integer> matrix;
public MapMatrix(int size) {
this.size = size;
@matiangul
matiangul / hello_world_threads.java
Last active May 6, 2019 13:34
Hello World Threads!
package pl.angulski.example.threads;
enum State {
HELLO("Hello "),
WORLD("world"),
EXCLAMATION("!\n");
private final String text;
State(String text) {