Skip to content

Instantly share code, notes, and snippets.

View hhariri's full-sized avatar

Hadi Hariri hhariri

View GitHub Profile
fun main(args: Array<String>) {
val httpClient = HttpClient()
httpClient.get("http://site.com") { response -> Unit
println(response.body)
}
}
fun main(args: Array<String>) {
val httpClient = HttpClient()
httpClient.get("http://site.com") {
println(body)
}
}
var o = Observable.from(arrayListOf("1", "2", "3", "4"))
o.subscribe(
onNext = { result -> println(result)},
onError = { (error) -> println(error)},
onComplete = { () -> println("Complete")}
)
val http = EasyHttp()
http.post(
url = "http://httpbin.org/post",
contents = Customer(name = "Joe", email = "joe@gmail.com"),
headers = RequestHeaders(contentType = "application/x-www-form-urlencoded"),
callback = { assertEquals(StatusCode.OK, statusCode) }
)
val server = AppServer()
server.serveStaticFilesFromFolder("/public")
server.useBasicAuthentication("private-area", path = "/private", callback = { (user, pass) -> user == pass })
server.get("/headers", {
request.rawHeaders.forEach {
println("${it.first}: ${it.second}")
}
response.send("Hello!")
var REVEALING = function () {
var privateProp = "Log";
var PIVALUE = 3.14;
log = function (message) {
console.log(privateProp + ": " + message);
};
fun String.extendingStrings() {
}
data class ThisDto(val nameProperty: String, val emailProperty: String) // DTO
// gives me hashCode, toString, equal operator (comparing properties) and two immutable properties name, email
public class PascalHumanizerTests(): Spek() {{
val data = listOf(
"ThisIsATest" to "This Is A Test",
"ThisIsAnotherTest" to "This Is Another Test"
)
given(data) {
on("calling humanize", {
val actual = it.component1().humanize()
public class PascalHumanizerTests(): Spek() {{
val data = listOf(
"ThisIsATest" to "This Is A Test",
"ThisIsAnotherTest" to "This Is Another Test"
)
givenData(data) {
val (input, expected) = it
on("calling humanize", {
public class CustomerController [Inject] (val customerRepository: CustomerRepository) {
fun list() {
customerRepository.getAll()
}
}