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
import java.io.OutputStream; | |
import java.net.InetSocketAddress; | |
import com.sun.net.httpserver.HttpServer; | |
public class WebApp { | |
public static void main(String[] args) throws Exception { | |
HttpServer server = HttpServer.create(new InetSocketAddress(9394), 0); | |
server.createContext("/ping").setHandler(h -> { | |
final String response = "pong!"; |
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
@Test | |
void "can send email without errors"() { | |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext() | |
StandardEnvironment environment = new StandardEnvironment() | |
InputStream ins = Resources.getResourceAsStream("/application.properties") | |
Properties props = new Properties() | |
props.load(ins as InputStream); | |
Closeables.closeQuietly(ins); | |
environment.propertySources.addFirst(new PropertiesPropertySource("application", props)) |
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
object CoinMachine { | |
def changeWithBigCoin(accum: Change, changeOwing: Double, avaliableChange: Change): (Change, Double, Change) = { | |
if (changeOwing < 0) throw new Error("Cannot give change with existing coins") | |
else if (changeOwing == 0) return (accum, 0, avaliableChange) | |
else if (changeOwing >= 5 && avaliableChange.fiveDollarsLeft > 0) changeWithBigCoin(accum.changeFiveDollar(1), changeOwing - 5, avaliableChange.changeFiveDollar(-1)) | |
else if (changeOwing >= 2 && avaliableChange.twoDollarsLeft > 0) changeWithBigCoin(accum.changeTwoDollar(1), changeOwing - 2, avaliableChange.changeTwoDollar(-1)) | |
else if (changeOwing >= 1 && avaliableChange.dollarsLeft > 0) changeWithBigCoin(accum.changeDollar(1), changeOwing - 1, avaliableChange.changeDollar(-1)) | |
else if (changeOwing >= 0.5 && avaliableChange.fiftycentsLeft > 0) changeWithBigCoin(accum.changeFiftyCent(1), changeOwing - 0.5, avaliableChange.changeFiftyCent(-1)) | |
else throw new Error("Cannot give change on remainder: " + changeOwi |