Skip to content

Instantly share code, notes, and snippets.

View wcang's full-sized avatar
🐴
Horsing around

Ang Way Chuang wcang

🐴
Horsing around
View GitHub Profile
open class Something<WTF>(val wtf: WTF)
{
init {
println("init something")
}
}
interface Blargh<T> {
fun getArg(): T
}
@wcang
wcang / BoardImpl.kt
Created October 17, 2021 02:36
Solution to Coursera's Kotlin for Java Developer Week 4 Board Assignment
package board
import board.Direction.*
fun createSquareBoard(width: Int): SquareBoard = ConcreteSquareBoard(width)
fun <T> createGameBoard(width: Int): GameBoard<T> = ConcreteGameBoard(createSquareBoard(width))
private fun Cell.coordinate(direction: Direction) =
when (direction) {
@wcang
wcang / Finally.java
Created February 20, 2022 13:05
I just realized that the code in finally block will be called when if the method exits in prior code block
public class Finally {
public static int tryFinally() {
try {
return 1;
} finally {
System.out.println("Finally block");
}
}
@wcang
wcang / AddTwoNumberList.kt
Last active April 23, 2022 13:52
Add Two Numbers. Problem is described here: https://leetcode.com/problems/add-two-numbers/
import kotlin.math.max
fun add(left: List<Int>, right: List<Int>) : List<Int> {
val l = left.asReversed()
val r = right.asReversed()
val result = mutableListOf<Int>()
val max = max(l.size, r.size)
var carry = 0
repeat(max) {
@wcang
wcang / Main.java
Created April 25, 2022 12:00
PrimeNumberCollector that collects prime numbers into a list from an Integer stream. OptimizedPrimeNumberCollector is an optimized version of the collector using the accumulated list of prior prime numbers to weed out a prime number candidate. Refers to Java 8 In Action for details
package com.wcang;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main {