Skip to content

Instantly share code, notes, and snippets.

View nicktelford's full-sized avatar

Nick Telford nicktelford

View GitHub Profile
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;
@nicktelford
nicktelford / scala.net.scala
Last active June 1, 2017 10:56
Rough sketch of ideas for a "scala.net" like package
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
}
}
@nicktelford
nicktelford / Option.scala
Created June 26, 2017 11:41
Cheap Options in dotty?
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
@nicktelford
nicktelford / prelude.sh
Last active April 24, 2024 15:02
BASH prelude
#/usr/bin/env bash
set -eEuo pipefail # "strict" mode (http://redsymbol.net/articles/unofficial-bash-strict-mode/)
export SHELLOPTS # propagate strict mode to all subshells
# don't split words on space characters
IFS=$'\n\t'
# absolute path of the directory the invoked script resides in
BASE_PATH="${BASE_PATH:-$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")}"