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
#!/opt/ruby-enterprise/bin/ruby | |
# MODIFIED: Minor fork to run smoothly under Ruby 1.8.6. Heredoc cleanup. | |
require 'rubygems' | |
require 'beanstalk-client' | |
if ARGV.length > 0 && ARGV[0] == 'config' | |
puts <<-END | |
graph_category 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
// scala 2.7 simple type constraint. This can only constrain a type parameter of this function. | |
// Below, in ListW.sumint28, we can't use this approach because we want to constrain T, | |
// a type param of the enclosing trait. | |
def sumint27A[T <: Int](l: List[T]) : Int = l.reduceLeft((a: Int, b: Int) => a + b) | |
trait IntLike[X] extends (X => Int) | |
object IntLike { | |
implicit val intIntLike: IntLike[Int] = new IntLike[Int] { def apply(x: Int) = identity(x) } | |
} |
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
scala> import collection.mutable._ | |
scala> val m = new HashMap[Int, Set[String]] with MultiMap[Int, String] | |
m: scala.collection.mutable.HashMap[Int,scala.collection.mutable.Set[String]] with scala.collection.mutable.MultiMap[Int,String] = Map() | |
scala> m += ((1, Set("rc", "tb"))) | |
res10: m.type = Map((1,Set(tb, rc))) | |
scala> m += ((2, Set("tb"))) | |
res11: m.type = Map((2,Set(tb)), (1,Set(tb, rc))) |
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
// for comprehension | |
scala> for { | |
| l <- List(2,5,10) | |
| m <- List(8,10,11) | |
| } yield l * m | |
res17: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110) | |
// map a pure function into applicatives | |
scala> List(8,10,11) <*> (List(2,5,10) map (((_: Int) * (_: Int)).curried)) | |
res18: List[Int] = List(16, 20, 22, 40, 50, 55, 80, 100, 110) |
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 scalaz._ | |
object ValidationKleisli extends Application { | |
import Scalaz._ | |
// ------------------------------------------------------------------------------------------------ | |
// Monadic use of scalaz.Validation to sequence dependent computations | |
// e.g. processors in a route, see also Kleisli composition of processors in scalaz-camel: http://goo.gl/CUIlQ | |
// ------------------------------------------------------------------------------------------------ |
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 AuthenticatedSession extends Loggable { | |
def logIn(credentialsOption: Option[Credentials]): Twitter = { | |
val (tw, credentials) = credentialsOption match { | |
case Some(cr) => | |
(createTwitter(Some(cr)), cr) | |
case None => | |
val twitter = createTwitter(None) | |
val requestToken = twitter.getOAuthRequestToken | |
DesktopUtil.browse(requestToken.getAuthorizationURL) | |
(twitter, Dialog.showInput(null, "Enter the PIN from the Twitter authorization page in your browser", |
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
trait PostStart { actor: Actor => | |
def postStart: Unit | |
override def preStart { | |
actor.become { | |
case "PostStart" => try { postStart } finally { actor.unbecome } | |
} | |
actor.self ! "PostStart" | |
} | |
} |
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
// This code is unsafe to use in a multithreaded environment. | |
object A { | |
def foo = "foo" | |
B.bar | |
} | |
object B { | |
def bar = "bar" | |
A.foo |
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.osinka.i18n | |
import java.util.{Locale,ResourceBundle} | |
import collection.JavaConversions._ | |
import net.liftweb.common.Box._ | |
import net.liftweb.util.{BundleBuilder,PCDataXmlParser} | |
/** | |
* ResourceBundle.Control implementation for Liftweb resources | |
* |
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 props: Properties = System.getProperties() | |
props.put("mail.smtp.from", "my@mail.from") | |
val session: Session = Session.getInstance(props, null) | |
val message = new MimeMessage(session) | |
message.setFrom(new InternetAddress("my@mail.from", "This is my Name")) | |
message.addRecipient(Message.RecipientType.TO, new InternetAddress("recipient@foo.org"))) | |
message.setSubject("Blubber") |
OlderNewer