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
/** | |
* Lowest common ancestor. One of a very common binary tree puzzle. The implementation in scala is in about 10 lines | |
*/ | |
object Tree { | |
def findLCA(tree: Tree, x: Int, y: Int): Option[Tree] = { | |
if (tree.value == x || tree.value == y) Some(tree) | |
else (if (tree.left != None) findLCA(tree.left.get, x, y) else None, if (tree.right != None) findLCA(tree.right.get, x, y) else None) match { | |
case (Some(r), Some(l)) => Some(tree) | |
case (Some(r), None) => Some(r) | |
case (None, Some(l)) => Some(l) |
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
/** | |
* Challenge: https://www.reddit.com/r/dailyprogrammer/comments/3v4zsf/20151202_challenge_243_intermediate_jennys_fruit/ | |
* Description | |
Little Jenny has been sent to the market with a 5 dollar bill in hand, to buy fruits for a gift basket for the new neighbors. Since she's a diligent and literal-minded kid, she intends to spend exactly 5 dollars - not one cent more or less. | |
The fact that the market sells fruits per piece at non-round prices, does not make this easy - but Jenny is prepared. She takes out a Netbook from her backpack, types in the unit prices of some of the fruits she sees, and fires off a program from her collection - and voil\u00e0, the possible fruit combinations for a $5 purchase appear on the screen. | |
Challenge: Show what Jenny's program might look like in the programming language of your choice. | |
The goal is aways 500 cents (= $5). | |
Solutions can include multiple fruits of the same type - assume they're available in unlimited quantities. | |
Solutions do not need to include all available t |
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
/** | |
* Created by hoangong on 23/12/2015. | |
*/ | |
public class LinkedList { | |
private Node head; | |
private Node tail; | |
private int count; | |
public Node getHead() { |
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.ho.lp; | |
import java.util.Scanner; | |
/** | |
* Created by hoangong on 24/12/2015. | |
*/ | |
public class Main { | |
private String input; |
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
val uuidReads = Reads[UUID](i => i match { | |
case s: JsString => { | |
JsSuccess(UUID.fromString(s.value)) | |
} | |
case _ => { | |
JsError("error") | |
} | |
}) | |
val uuidWrites = Writes[UUID](i => JsString(i.toString)) | |
implicit val uuidFormat: Format[UUID] = Format(uuidReads, uuidWrites) |
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
val accessTokenReads = ( | |
(__ \ "token").read[String] and | |
(__ \ "createdDate").read[LocalDateTime] and | |
(__ \ "expiredDate").read[LocalDateTime] and | |
(__ \ "expired").read[Boolean] | |
) (AccessToken.apply _) | |
val accessTokenWrites = ( | |
(__ \ "token").write[String] and | |
(__ \ "createdDate").write[LocalDateTime] and |
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
#!/bin/sh | |
# check for where the latest version of IDEA is installed | |
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1` | |
wd=`pwd` | |
# were we given a directory? | |
if [ -d "$1" ]; then | |
# echo "checking for things in the working dir given" | |
wd=`ls -1d "$1" | head -n1` |
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
git config --global merge.tool kdiff3 | |
git config --global mergetool.kdiff3.path /Applications/kdiff3.app/Contents/MacOS/kdiff3 | |
git config --global core.editor "atom --wait" | |
or | |
git config --global core.editor nano | |
git config --global push.default simple |
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 akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller} | |
import akka.http.scaladsl.model.{ContentTypes, HttpEntity} | |
import akka.http.scaladsl.server.Directives._ | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.voi.dto.response.HealthCheck | |
trait HealthCheckEndpoint { | |
val mapper = new ObjectMapper() |
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 akka.http.scaladsl.model.HttpRequest | |
import akka.http.scaladsl.server.Directives._ | |
import akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller | |
import akka.stream.Materializer | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.voi.dto.response.HealthCheck | |
import com.voi.micro.services.ImplicitPojoMarshaller | |
import scala.concurrent.duration._ | |
import scala.concurrent.{ExecutionContext, Future} |
OlderNewer