Skip to content

Instantly share code, notes, and snippets.

@wokkaflokka
wokkaflokka / BinaryString.kt
Created May 24, 2019 18:25
Parses a well-formatted binary string and return it's decimal value, showcasing functional style in kotlin along the way
import org.junit.Test
import kotlin.math.pow
class BinStringTest {
@Test
fun test() {
println(BinaryString("111").toInt()) // 7
println(BinaryString("10000").toInt()) // 16
println(BinaryString("1000110").toInt()) // 70
// Write a function parseBinaryInt() that accepts a string of binary digits and converts the value
// to its integer representation.
fun parseBinaryInt(num: String): Int {
if (!valid(num)) {
throw RuntimeException("error")
}
var sum = 0
var offset = 0
@wokkaflokka
wokkaflokka / SwaggerServletInitializer.java
Created November 3, 2015 15:56
Sets a ReaderConfig in the Servlet context
import javax.servlet.ServletContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.context.ServletContextAware;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import io.swagger.jaxrs.config.DefaultReaderConfig;
import io.swagger.jaxrs.config.ReaderConfig;