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
type Option[A] = A | Null | |
object Option { | |
inline def apply[A](x: A): Option[A] = x | |
} | |
implicit class OptionMethods[A](val x: Option[A]) extends AnyVal { | |
inline def map[B](f: A => B): Option[A] = x match { | |
case null => null |
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 UnknownHostException(hostname: String) extends RuntimeException(s"Unknown host: $hostname") | |
object NetworkAddress { | |
def apply(address: String): Option[NetworkAddress] = address match { | |
case addr @ IPv4NetworkAddress.pattern(_, _, _, _) => Some(new IPv4NetworkAddress(addr) {}) | |
case addr @ IPv6NetworkAddress.pattern(_, _, _, _, _, _, _, _) => Some(new IPv6NetworkAddress(addr) {}) | |
case addr @ UnresolvedNetworkAddress.pattern() => Some(new UnresolvedNetworkAddress(addr) {}) | |
case _ => None | |
} | |
} |
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.yammer.dropwizard.validation; | |
import com.google.common.base.Joiner; | |
import com.google.common.collect.*; | |
import org.hibernate.validator.internal.engine.ConstraintValidatorFactoryImpl; | |
import javax.validation.*; | |
import javax.validation.groups.Default; | |
import java.util.Set; |
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 App { | |
case class Post(title: String, | |
body: String, | |
tags: List[String]) | |
case class Address(street: String, | |
city: String, | |
state: String, | |
zip: String, | |
tags: List[String]) |
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 Any { | |
implicit def matching[A](a: A): Matchable[A] = new Matchable(a) | |
sealed class Matchable[A](o: A) { | |
// "match" is a reserved word, so lets call it "matchIt" instead | |
def matchIt[B](pf: PartialFunction[A, B]): B = { | |
if(pf.isDefinedAt(o)) { | |
pf(o) | |
} else { | |
throw new MatchError("...") |
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 Either { | |
implicit def aToLeft[A, B](value: A): Left[A, B] = Left(value) | |
implicit def bToRight[A, B](value: B): Right[A, B] = Right(value) | |
} | |
import Either._ | |
case class User(id: Either[Long, String]) | |
User(123L) |
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 Either { | |
def apply[A, B](value: A): Left[A, B] = Left(value) | |
def apply[A, B](value: B): Right[A, B] = Right(value) | |
} | |
val a: Either[Long, String] = Either(123L) | |
// a: Either[Long,String] = Left(123) | |
val b: Either[Long, String] = Either("123") | |
b: Either[Long,String] = Right(123) |
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
// pretend this extractor is performance critical | |
object EvenExtractor { | |
def unapply(x: Int): Option[Int] = { | |
println("Testing for EVEN: " + x) | |
if (x % 2 == 0) Option(x) else None | |
} | |
} | |
// when you use it from a PartialFunction, it gets executed TWICE for all applicable values | |
Seq(1, 2, 3, 4) collect { |
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
INFO [NonPeriodicTasks:1] 2011-05-17 20:47:44,725 SSTable.java (line 147) Deleted /var/lib/cassandra/yyy-f-1201 | |
INFO [COMMIT-LOG-WRITER] 2011-05-17 20:56:48,233 CommitLogSegment.java (line 50) Creating new commitlog segment /var/lib/cassandra/commitlog/CommitLog-1305665808233.log | |
INFO [ScheduledTasks:1] 2011-05-17 21:02:14,513 Gossiper.java (line 226) InetAddress /x.x.x.34 is now dead. | |
INFO [GossipStage:1] 2011-05-17 21:02:14,786 Gossiper.java (line 607) InetAddress /x.x.x.34 is now UP | |
INFO [ScheduledTasks:1] 2011-05-17 21:02:21,514 Gossiper.java (line 226) InetAddress /x.x.x.34 is now dead. | |
INFO [HintedHandoff:1] 2011-05-17 21:03:13,676 HintedHandOffManager.java (line 295) Endpoint /x.x.x.34 died before hint delivery, aborting | |
INFO [GossipStage:1] 2011-05-17 21:06:09,884 Gossiper.java (line 628) Node /x.x.x.34 has restarted, now UP again | |
INFO [GossipStage:1] 2011-05-17 21:06:10,552 StorageService.java (line 724) Node /x.x.x.34 state jump to normal | |
INFO [HintedHandoff:1] 2011-05-17 21:06:15,924 Hinte |
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_connect: | |
if (connect(ptr->fd, | |
(struct sockaddr *)&servAddr, | |
sizeof(servAddr)) < 0) | |
{ | |
switch (errno) | |
{ | |
case EINPROGRESS: | |
case EALREADY: | |
case EINTR: |
NewerOlder