понедельник, июня 24, 2013

Минималистичный twitter finagle сервер

По мотивам http://twitter.github.io/twitter-server/index.html

1) Выкачиваем скрипт запуска sbt
curl -O https://raw.github.com/twitter/finagle/master/sbt
chmod 775 sbt

2) Создаем файл project/Build.scala для sbt
mkdir project
cat > project/Build.scala

import sbt._
import Keys._
import Tests._
import sbtassembly.Plugin._

object TestTwitterServer extends Build {

  lazy val testTwitterServer = Project(
    id = "test-twitter-server",
    base = file("."),
    settings = Project.defaultSettings ++
      assemblySettings
  ).settings(
    name := "test-twitter-server",
    libraryDependencies ++= Seq(
      "com.twitter" %% "twitter-server" % "1.0.1"
    ),
    resolvers += "twitter-repo" at "http://maven.twttr.com"

  )

}

CTRL-D

3) Создаем файл project/plugins.sbt для sbt
cat > project/plugins.sbt

resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.9.0")

CTRL-D

4) Создаем файл приложения app.scala

cat > app.scala

import com.twitter.conversions.time._
import com.twitter.finagle.http.HttpMuxer
import com.twitter.finagle.{Http, Service}
import com.twitter.server.TwitterServer
import com.twitter.util.{Await, Duration, Future, Time}
import java.net.InetSocketAddress
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.util.CharsetUtil.UTF_8

object AdvancedServer extends TwitterServer {

  val what = flag("what", "hello", "String to return")
  val addr = flag("bind", new InetSocketAddress(0), "Bind address")
  val durations = flag("alarms", (1.second, 5.second), "2 alarm durations")
  val counter = statsReceiver.counter("requests_counter")

  val service = new Service[HttpRequest, HttpResponse] {
    def apply(request: HttpRequest) = {
      log.debug("Received a request at " + Time.now)
      counter.incr()
      val response =
        new DefaultHttpResponse(request.getProtocolVersion, HttpResponseStatus.OK)
      val content = copiedBuffer(what() + "\n", UTF_8)
      response.setContent(content)
      Future.value(response)
    }
  }

  def main() {
    // We can create a new http server but in that case we profit from the
    // one already started for /admin/*
    // The `TwitterServer` trait exposes a `httpServer` that serve all routes
    // registered in the HttpMuxer object, we just have to add our own.
    HttpMuxer.addHandler("/echo", service)
    // And wait on the server
    Await.ready(httpServer)
  }
}

CTRL-D

5) Стартуем
$ ./sbt run

CTRL-C

6) Собираем в один jar
$ ./sbt assembly

среда, июня 19, 2013

Ссылки 2013-06

Scala

http://eed3si9n.com/learning-scalaz/
learning Scalaz

http://mauricio.github.io/2013/04/29/async-database-access-with-postgresql-play-scala-and-heroku.html
Async database access with PostgreSQL, Play, Scala and Heroku

AngularJS

http://ngmodules.org/
Find Modules for AngularJS

http://plnkr.co/tags/angularjs
online community for creating, collaborating on and sharing your web development ideas

http://it-ebooks.info/book/2076/
AngularJS book

http://www.egghead.io/
AngularJS video

https://github.com/btford/angular-dragon-drop
Drag and Drop for AngularJS

https://github.com/angular/angularjs-batarang
AngularJS WebInspector Extension for Chrome

http://tombatossals.github.io/angular-leaflet-directive/
Leaflet directive for AngularJS

https://github.com/jeffbcross/ngswipe-demo
Angular reader is a simple Atom feed reader app that shows off some new features in AngularJS, and generally shows off the simplicity of building apps with Angular.

https://github.com/yeoman/yeoman
Yeoman, Yo + Bower + Grunt = Javacript application generator + Package manager + Compiler


вторник, июня 11, 2013

Mac OS X 10.7.X и HP M1120

Самая advanced операционная система не дружит со сканером многофункциональных HP.
К примеру, чтобы отсканировать на HP M1120 в Mac OS X 10.7.X, надо установить драйвер для Mac OS X 10.5.X, а потом ручками запустить HP Setup Assistant для установки HP Director

$ sudo /Applications/HP\ LaserJet\ M1120\ MFP\ Series/HP\ Setup\ Assistant.app/Contents/MacOS/HP\ Setup\ Assistant

Такие дела.

Мой список блогов