This file contains hidden or 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 unions = Seq(4->3, 3->8, 6->5, 9->4, 2->1, 5->0, 7->2, 6->1, 1->0) | |
val parents = (0 to 9).toArray | |
val depths = Array.fill(10)(1) | |
def connected(p: Int, q: Int) = root(p) == root(q) | |
def union(p: Int, q: Int) { | |
val i = root(p) | |
val j = root(q) | |
val (sm, lg) = if (depths(i) < depths(j)) (i, j) else (j, i) |
This file contains hidden or 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 net.liftweb.sandbox | |
import org.scalatest.FunSuite | |
import net.liftweb.json._ | |
import org.scalatest.matchers.ShouldMatchers | |
/** | |
* @author IL | |
* @see <a href="https://groups.google.com/forum/?fromgroups#!topic/liftweb/GK5DbzCtWdA">forum</a> | |
*/ |
This file contains hidden or 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
scala> def implicitlyEitherImpl[A: c.TypeTag, B: c.TypeTag](c: reflect.makro.Context): c.Expr[Either[A, B]] = { | |
| def i[X](implicit X: c.TypeTag[X]): c.Tree = c.inferImplicitValue(X.tpe, silent = false) | |
| i[A] match { | |
| case c.mirror.EmptyTree => | |
| i[B] match { | |
| case c.mirror.EmptyTree => | |
| sys.error("Neither A nor B are available implicitly") | |
| case b => | |
| c.reify(Right[A, B](c.Expr[B](b).eval)) | |
| } |
This file contains hidden or 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
/* | |
Copyright 2012-2021 Viktor Klang | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
This file contains hidden or 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 class Config(host: String, port: Int) { | |
def prettyPrint(prefix: String, msg: String): String = | |
List(prefix, ": ", msg, " on ", host, ":", port.toString).mkString | |
} | |
/** | |
* Passing a configuration with implicits is like | |
* working in the state monad. You can "put" a | |
* new configuration even though we don't want that | |
* to happen in this particular example. We don't |
This file contains hidden or 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 bootstrap.liftweb { | |
import net.liftweb.common._ | |
import net.liftweb.http._ | |
import js._ | |
import LiftRules._ | |
import net.liftweb.util.Helpers._ | |
/** | |
* Provides automatic reloading of the client on session loss. | |
* |
This file contains hidden or 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 code.mockweb | |
/* | |
* Copyright 2011 WorldWide Conferencing, LLC | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* |
This file contains hidden or 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
trait Bind[M[_]] { | |
def fmap[A, B](ma: M[A], f: A => B): M[B] | |
def bind[A, B](ma: M[A], f: A => M[B]): M[B] | |
} | |
trait Monad[M[_]] extends Bind[M]{ | |
def unit[A](a: => A): M[A] |
This file contains hidden or 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
// Modified SpamLord.java to call clojure code | |
public List<Contact> processFile(String fileName, BufferedReader input) { | |
List<Contact> contacts = new ArrayList<Contact>(); | |
// for each line | |
Matcher m; | |
String email; | |
try { | |
List results = new spamlord().process(input); |
This file contains hidden or 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.net._ | |
import java.util.UUID | |
import com.twitter.conversions.time._ | |
import com.twitter.finagle.builder.ClientBuilder | |
import com.twitter.util._ | |
import java.nio.charset.Charset | |
import org.jboss.netty.buffer.{ChannelBuffers, ChannelBuffer} | |
import org.jboss.netty.handler.codec.http._ | |
import com.twitter.finagle.stream.Stream |