Skip to content

Instantly share code, notes, and snippets.

View hhariri's full-sized avatar

Hadi Hariri hhariri

View GitHub Profile
package org.hadihariri.js.basics
import js.dom.html.document
fun main(args: Array<String>) {
document.getElementById("email").setAttribute("value", "[email protected]")
}
<!DOCTYPE html>
<html>
<head>
<title>This page is manipulated with Kotlin</title>
</head>
<body>
<input type="text" id="email">
</body>
</html>
data class Customer(val name: String, val email: String, val country: String)
fun isValidAccount(accountNumber: String): Boolean {
// function logic
}
val appServer = AppServer()
appServer.resolveDependencies(ContainerConfiguration) // this is the IoC container configuration
appServer.get("/customers", {
with<Database> {
response.send(getCustomers()) // see below why this works
data class Customer(val id: Int, val name: String, val email: String, val country: String)
val customerList = arrayListOf<Customer>(
Customer(1, "Joe Smith", "[email protected]", "UK"),
Customer(2, "Jack Jones", "[email protected]", "US"),
Customer(3, "Maria Gonzalez", "[email protected]", "Spain")
)
fun main(args: Array<String>) {
@hhariri
hhariri / sample.kt
Last active December 21, 2015 21:59
data class Customer(val name: String, val email: String, val country: String)
val customerList = object : ArrayList<Customer>() {
}
fun main(args: Array<String>) {
// fill up some dummy customers
server.get("/book",
{
response.negotiate (
"text/html" with { send("Something about me") },
"application/json" with { send("{title: 'Something about me', isbn: 'IS454-12123-A23232'}")}
)
negotiate (
"text/html" to { response.send("Something about me")},
"application/json" to {
response.send("{title: 'Something about me', isbn: 'IS454-12123-A23232'}")
}
)
@hhariri
hhariri / manualconneg.kt
Last active December 20, 2015 22:19
manualconneg
server.get("/book",
{
// automatic negotiation exists, but if you want manual...
negotiate {
on("text/html") {response.send("Something about everyone")}
on("application/json") {
// this is just a sample. automatic json serialization is also available...