I hereby claim:
- I am renaudcerrato on github.
- I am renaudcerrato (https://keybase.io/renaudcerrato) on keybase.
- I have a public key ASABbJwczM3qvM1NIE5Nv6myqn1Ou-ypR6p5XFAcsvCf-Qo
To claim this, I am signing this object:
#!/bin/sh | |
error () { | |
echo "error: $1" | |
usage | |
} | |
usage () { | |
echo "usage: $0 -u <username> -p <password> -d <domain> -i <seconds> <subdomain>"; | |
exit 1 |
#!/usr/bin/env bash | |
KOTLIN=$(find . -name "*.kt" -exec cat {} \; | wc -l) | |
JAVA=$(find . -name "*.java" -exec cat {} \; | wc -l) | |
echo Kotlin: $KOTLIN lines \($(echo scale=2\; 100 \* $KOTLIN / \( $KOTLIN + $JAVA \) | bc -l)%\) | |
echo Java : $JAVA lines \($(echo scale=2\; 100 \* $JAVA / \( $KOTLIN + $JAVA \) | bc -l)%\) | |
I hereby claim:
To claim this, I am signing this object:
val list = listOf("Kotlin", "", "Java", "Groovy") | |
fun main() { | |
list.forEach { | |
if(it.isNullOrEmpty()) return@forEach // return with implicit label | |
println(it) | |
} | |
println("Done!") | |
} |
// Kotlin's standard library extension | |
inline fun Array<String>.forEach(action: (String) -> Unit) { | |
for(str in this) { | |
action(str) | |
} | |
} | |
val list = listOf("Kotlin", "Java", "Groovy") | |
// a bare return statement in a lambda called from |
inline fun greeter(action: () -> Unit) { | |
try { | |
println("Hello!") | |
action() | |
}finally{ | |
println("Goodbye!") | |
} | |
} | |
greeter { |
// the returned value is the last expression of the try or catch block | |
val a: Int? = try { parseInt(input) } catch (e: NumberFormatException) { null } | |
fun printNumber(reader: BufferedReader) { | |
val number = try { | |
parseInt(reader.readLine()) | |
} catch (e: NumberFormatException) { | |
return | |
} |
enum class Direction { | |
NORTH, SOUTH, WEST, EAST | |
} | |
enum class Color(val rgb: Int) { | |
RED(0xFF0000), | |
GREEN(0x00FF00), | |
BLUE(0x0000FF) | |
} |
// until and step are infix functions | |
for(i in 0 until 100 step 2) println("$i") | |
// equivalent to: | |
for(i in 0.until(100).step(2)) println("$i") | |
// downTo is an infix function | |
for(i in 100 downTo 0) println("$i") | |
// shl, and, xor are infix functions | |
val i = (0x65acf9 shl 6) and 0x55 xor 0x80 |
class Price(val value: Double, val currency: Currency) | |
infix fun Int.euro(cents: Int): Price { | |
return Price(toDouble() + cents / 100.0, Currency.EURO) | |
} | |
val price = 1 euro 42 | |
// equivalent to: | |
val price = 1.euro(42) |