Skip to content

Instantly share code, notes, and snippets.

Avatar

Preston Garno prestongarno

View GitHub Profile
@prestongarno
prestongarno / puzzler.kt
Last active May 19, 2018
What is the output of this program?
View puzzler.kt
import kotlin.reflect.KProperty
class ResponsibleDelegate<out T>(initializer: () -> T?) {
private val value by lazy(initializer)
operator fun getValue(thisRef: Any?, property: KProperty<*>): T =
value ?: throw NullPointerException()
}
View destructuregex.kt
fun parsePhoneNumber(text: String): PhoneNumber {
val destructuredRegex = "([0-9]{3})-([0-9]{3})-([0-9]{4})".toRegex()
return destructuredRegex.matchEntire(text)
?.destructured
?.let { (areaCode, prefix, lineNumber) ->
PhoneNumber(areaCode.toInt(), prefix.toInt(), lineNumber.toInt())
}
View CustomFileChooser.java
import java.io.*;
import java.nio.file.*;
import java.nio.file.spi.FileSystemProvider;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.swing.*;
public class CustomFileChooser {