2012-02-03

juan_gandhi: (Default)
2012-02-03 11:09 am

java wtf

Ever tried new File(".").getParent()?

Returns null

as opposed to new File(new File(".").getAbsolutePath()).getParent()

How is it much better than Perl (which, by the way, will work properly in this case)?
juan_gandhi: (Default)
2012-02-03 01:39 pm

a scala snippet again

  val t: Thread = new Thread("Server at " + port) {

    val dispatch = Map("POST /status/success" -> processSuccess _,
                       "POST /status/failure" -> processFailure _,
                       "POST /queryrunstate"  -> processRunQuery _,
                       "GET /comet_request"   -> tellThemToShutUp _
    )
    
    override def run {
      while (!Thread.interrupted()) {
        try {
          val s = ss.accept
          val source = Source.fromInputStream(s.getInputStream)
          val rq = source.getLines.next
          try {
            val f = dispatch.keys.find(rq startsWith _).map(dispatch).getOrElse(ignore _)
            f(rq, s, source)
          } catch {
            case se : SocketException => log(se)
          } finally {
            s.close
          }
        } catch {
          case ioe: IOException => log(ioe)
          case ie: InterruptedException => return
        }
      }
    }
  }

  def tellThemToShutUp(rq: String,  socket: Socket, source: Source) {
    Response("oh shut up, this is not the web server you are lookign for", "410 Gone")
  }

juan_gandhi: (Default)
2012-02-03 03:29 pm
Entry tags:

scala snippet

 
 val serverSocket = try {new ServerSocket(port)} catch {
    case e: java.net.BindException => {
      println("wtf, several copies? what is it? ")
      throw new IllegalStateException("this port, " + port + ", is already taken!")
    }
  }