This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val x: Int? = 2 | |
| val y: Int = 3 | |
| val sum = x?:0 + y | |
| println(sum) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| os.system("kotlinc src/main/kotlin/Launcher.kt -include-runtime -d launcher.jar") | |
| process = Popen(['java', '-jar', 'launcher.jar', tmp_file_name], stdout=PIPE) | |
| (stdout, stderr) = process.communicate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javafx.beans.property.SimpleBooleanProperty | |
| import javafx.beans.value.ObservableValue | |
| import javafx.collections.FXCollections | |
| import javafx.collections.ObservableList | |
| import javafx.collections.ObservableSet | |
| import javafx.collections.SetChangeListener | |
| import tornadofx.* | |
| class DirtyObservableList<T>(originalList: List<T> = listOf()): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PROBLEM VISUALIZATION (https://i.imgur.com/cwg5LZ9.png) | |
| val treeRowCount = 5 | |
| enum class Direction { | |
| ROOT, | |
| LEFT, | |
| RIGHT; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/ | |
| fun main(args: Array<String>) { | |
| val x1 = Point(0.0, 0.0) | |
| val y1 = Point(4.0, 4.0) | |
| val x2 = Point(0.0, 4.0) | |
| val y2 = Point(4.0, 0.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(prophet) | |
| library(dplyr) | |
| df <- read.csv('http://bit.ly/2po0xPJ') %>% mutate(y=log(y)) | |
| #floor and cap | |
| lower = quantile(df$y, .05) | |
| upper = quantile(df$y, .95) | |
| df <- df %>% mutate(floor = lower, cap = upper) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import javafx.animation.Timeline | |
| import java.util.concurrent.ConcurrentLinkedDeque | |
| class DequeTransition { | |
| private var _queue = ConcurrentLinkedDeque<Timeline>() | |
| operator fun plusAssign(timeline: Timeline) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Property delegate that has a default value, but can only be re-assigned once | |
| * This is helpful for deductive flagging tasks | |
| */ | |
| fun <T> singleAssignWithDefault(defaultValue: T) = SingleAssignWithDefault(defaultValue) | |
| class SingleAssignWithDefault<T>(val defaultValue: T) { | |
| private object UNINITIALIZED_VALUE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T> List<T>.rollingBatches(batchSize: Int) = (0..size).asSequence().map { i -> | |
| subList(i, (i + batchSize).let { if (it > size) size else it }) | |
| }.filter { it.size == batchSize } | |
| enum class RecurrenceMode { PARTIAL_ONLY, FULL_ONLY, ALL } | |
| fun <T> List<T>.rollingRecurrences(slotsNeeded: Int, gap: Int, recurrences: Int, mode: RecurrenceMode = RecurrenceMode.FULL_ONLY) = | |
| (0..size).asSequence().map { i -> | |
| (1..recurrences).asSequence().map { (it - 1) * gap } | |
| .filter { it + i < size} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.ThreadLocalRandom | |
| /** | |
| * Monty Hall Problem Simulation | |
| */ | |
| fun randomDoor() = ThreadLocalRandom.current().nextInt(0,3) | |
| // how many trials do you want to run? | |
| val trialCount = 10000 |