Skip to content

Instantly share code, notes, and snippets.

View shafirov's full-sized avatar

Maxim Shafirov shafirov

View GitHub Profile
@shafirov
shafirov / BaseApp.kt
Created September 3, 2013 15:34
Kotlin in the wild
intercept { req, resp, cont ->
transaction {
cont(req, resp)
}
}
@shafirov
shafirov / CompactCustomerCard.kt
Created September 6, 2013 19:05
Somewhat boring part of business app's UI. Take note of handling optional order's date though
fun HtmlBodyTag.shortOrdersList(customer: CustomerProfile) {
val orders = customer.orders.toList().sortBy { -(it.date?.getMillis()?:0.toLong()) }
table(s("table table-striped table-condensed")) {
for (order in orders.take(5)) {
tr {
td {
order.date?.let {
small {
+DateTimeFormat.forPattern("dd/MM/yy").print(it)!!
Post("profile/p") class UpdateProfileDetails(val f: String, val l: String, e: String) : Request({
authorize {
update(Account) {
firstName = f
lastName = l
email = e
}
redirect(ProfilePage(null))
}
@shafirov
shafirov / gist:8420175
Created January 14, 2014 15:32
Some funny kotlin take on jodatime API
fun retrySchedule(attempt: Int): DateTime {
return with(DateTime.now()) {
when (attempt) {
1 -> plusSeconds(3)
2 -> plusMinutes(1)
else -> plusHours(1)
}
}
}