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 org.am.incident | |
object Test extends App { | |
def ??? = throw new IllegalStateException() | |
trait Conv[A, B] { | |
def conv(a: A): B | |
} | |
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 scaldi.{Injector, Module, Injectable} | |
trait Security { | |
type User | |
def authenticate(username: String, password: String): Boolean | |
} | |
class SecuritySample extends Security { | |
def authenticate(username: String, password: String): Boolean = false |
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 scaldi.{Injectable, Module, Injector} | |
class UserService | |
class UserController(implicit inj: Injector) extends Injectable { | |
val userService = inject [UserService] | |
} | |
class OrderService(implicit inj: Injector) extends Injectable { | |
val userService = inject [UserService] |
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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
require 'equivalent-xml' | |
xml = ARGV.map {|file_name| File.open(file_name) {|f| Nokogiri::XML(f)}} | |
print "Same: ", EquivalentXml.equivalent?(xml[0], xml[1]) |
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
var src = 'https:' == location.protocol ? 'https':'http', script = document.createElement('script'); | |
script.src = src+'://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'; | |
script.onload = function () { | |
var $ = jQuery; | |
var elem = $('<div>').text("0").css({position: 'fixed', top: 0, left: 0, width: 250, height: 40, backgroundColor: '#006699', borderBottomRightRadius: 7, color: 'white', padding: 9, fontWeight: 'bold', fontSize: '30px', boxShadow: "0 0px 20px 2px black"}).appendTo(document.body); | |
var sum = 0; | |
var count = 0; | |
$("table td").click(function () { | |
var cell = $(this); |
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 scala.reflect.runtime.universe.TypeTag | |
import scala.annotation.implicitNotFound | |
@implicitNotFound("Sorry, type inference was unable to figure out the type. You need to provide it explicitly.") | |
trait NotNothing[T] | |
object NotNothing { | |
private val evidence: NotNothing[Any] = new Object with NotNothing[Any] | |
implicit def notNothingEvidence[T](implicit n: T =:= T): NotNothing[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
// First you need to create module with actor system and actor bindings in it: | |
// IMPORTANT: `Actor` bindings should always be providers (bound with `toProvider` method, | |
// IMPORTANT: which will create new instances each time it gets injected) | |
implicit val module = new Module { | |
bind [ActorSystem] to ActorSystem("MySystem") | |
bind [GreetPrinter] toProvider new GreetPrinter | |
binding toProvider new GenericPrinter | |
bind [PrintStream] to Console.out |
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 scala.annotation.switch | |
import org.parboiled2._ | |
import scala.io.Source | |
import scala.util.{Failure, Success} | |
class PredicateParser(val input: ParserInput) extends Parser with CommonRules { | |
def And = Keyword("and") | |
def Or = Keyword("or") | |
def Not = Keyword("not") |
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.actor.ActorSystem | |
import akka.stream.ActorFlowMaterializer | |
import akka.http.scaladsl.model.headers._ | |
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.server._ | |
import akka.http.scaladsl.model.StatusCodes._ | |
import akka.http.scaladsl.server.Directives._ | |
object OptionsMethod extends App { |
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
case object DateCoercionViolation extends ValueCoercionViolation("Date value expected") | |
def parseDate(s: String) = Try(new DateTime(s, DateTimeZone.UTC)) match { | |
case Success(date) => Right(date) | |
case Failure(_) => Left(DateCoercionViolation) | |
} | |
val DateTimeType = ScalarType[DateTime]("DateTime", | |
coerceOutput = date => ast.StringValue(ISODateTimeFormat.dateTime().print(date)), | |
coerceUserInput = { |