This file contains 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
/* related to: https://x.com/vikhyatk/status/1873033432705712304 */ | |
import java.util.LinkedList | |
data class BinaryTreeNode(val label: String, val left: BinaryTreeNode? = null, val right: BinaryTreeNode? = null) | |
data class NodeAtLevel(val level: Int, val node: BinaryTreeNode) | |
/** | |
* Lazy Breadth First Traversal of the binary tree by node, left to right by level |
This file contains 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
/* related to: https://x.com/vikhyatk/status/1873033432705712304 */ | |
-- Setup | |
DROP TABLE IF EXISTS binary_tree; | |
CREATE TABLE binary_tree ( | |
id INTEGER NOT NULL PRIMARY KEY, | |
label TEXT NOT NULL, | |
left_child INTEGER INTEGER REFERENCES binary_tree(id), | |
right_child INTEGER REFERENCES binary_tree(id) | |
); |
This file contains 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
// myJList => JList component holding type MyObject | |
// sourceList => List<MyObject> (or other colleciton type) to match selection | |
// note MyObject will be checked for referential == if you do not implement equals and hashCode | |
var model = (DefaultListModel<MyObject>) myJList.getModel(); | |
myJList.clearSelection(); | |
int[] indexes = sourceList.stream() | |
.mapToInt(obj -> model.indexOf(obj)) | |
.filter(idx -> idx >= 0).toArray(); |
This file contains 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
func submit() { | |
guard let name = nameField.text else { | |
show("No name to submit") | |
return | |
} | |
guard let address = addressField.text else { | |
show("No address to submit") | |
return | |
} |
This file contains 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
@file:Suppress("NOTHING_TO_INLINE") | |
import java.io.BufferedReader | |
import java.io.File | |
import java.io.InputStream | |
import java.io.InputStreamReader | |
import kotlin.system.measureTimeMillis | |
// Kotlin 1.2.0 (probably 1.6.0 will work as well) | |
// |
This file contains 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
package com.google.classyshark.silverghost.translator.dex | |
object DexlibAdapter { | |
val primitiveTypes = mapOf( | |
"I" to "int", | |
"V" to "void", | |
"C" to "char", | |
"D" to "double", | |
"F" to "float", | |
"J" to "long", |
This file contains 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
// Shown from the Java 8 JDK source code, only comments removed. | |
public static <T> | |
Collector<T, ?, IntSummaryStatistics> summarizingInt(ToIntFunction<? super T> mapper) { | |
return new CollectorImpl<T, IntSummaryStatistics, IntSummaryStatistics>( | |
IntSummaryStatistics::new, | |
(r, t) -> r.accept(mapper.applyAsInt(t)), | |
(l, r) -> { l.combine(r); return l; }, CH_ID); | |
public class IntSummaryStatistics implements IntConsumer { | |
private long count; |
This file contains 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
class Fred : AutoCloseable { | |
override fun close() { | |
} | |
} | |
public fun foo() { | |
Fred().use { | |
// do something then autoclose |
This file contains 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
package com.collokia.webapp.routes; | |
import io.netty.handler.codec.http.HttpHeaders; | |
import io.vertx.core.net.SocketAddress; | |
import io.vertx.ext.web.RoutingContext; | |
import io.vertx.ext.web.Session; | |
import sun.reflect.generics.reflectiveObjects.NotImplementedException; | |
import javax.servlet.*; |
This file contains 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
enum class TimeUnit(val name: String, val divisorFromNanos: Long, val precision: Int) { | |
Seconds : TimeUnit("seconds", 1000000000, 2) | |
Millis : TimeUnit("millis", 1000000, 0) | |
Micros : TimeUnit("micros", 1000, 0) | |
Nanos : TimeUnit("nanos", 1, 0) | |
fun toHumanReadable(nanoTime: Long): String = "%.${precision}f ${name}".format(nanoTime.toFloat() / divisorFromNanos.toFloat()) | |
} | |
class Duration(val duration: Long, val units: TimeUnit, private val durationInNanos: Long = duration * units.divisorFromNanos) : Comparable<Duration> { |
NewerOlder