Skip to content

Instantly share code, notes, and snippets.

@casualjim
casualjim / bump_version.scala
Created December 1, 2011 23:52
Generates a scala source file with the sbt version number
val bumpPatch = TaskKey[String]("bump-patch")
settings ++ Seq(
bumpPatch <<= (version) map { ver =>
val Array(patch:Int, minor:Int, major:Int) = "0.0.1".split("\\.").reverse.map(_.toInt)
val newVer = "%d.%d.%d".format(major, minor, patch+1)
version := newVer
newVer
}
)
@casualjim
casualjim / base.scala
Created November 30, 2011 23:19 — forked from robb1e/base.scala
Creating API docs for scalatra
class HttpMethod
object HttpPostMethod extends HttpMethod { override def toString = "POST" }
object HttpGetMethod extends HttpMethod { override def toString = "GET" }
object HttpDeleteMethod extends HttpMethod { override def toString = "DELETE" }
object HttpPutMethod extends HttpMethod { override def toString = "PUT" }
trait Param {
def name: String
def description: String
@casualjim
casualjim / actor_specification.scala
Created November 30, 2011 13:42
Specs2 with Akka and jodatime support
trait ActorSpecification extends BaseSpecification
with ArgumentsArgs
with ArgumentsShortcuts
with MustThrownMatchers
with ShouldThrownMatchers
with FormattingFragments
with StandardResults
with StandardMatchResults
with PendingUntilFixed
with TimeHelpers
case class Paginator[A](
val adapter: Adapter[A],
val currentPage: Int = 1,
val maxPerPage: Int = 10
) extends PaginatorLike[A] {
assert(maxPerPage > 0, "Max per page must be greater than zero")
assert(currentPage > 0, "Current page must be greater than zero")

06:52 jakedouglas: [23:22:23] hmm. the example atmosphere code doesn't really click with me
06:52 casualjim: [23:22:34] yes because it's input and output
06:52 casualjim: [23:23:31] i'll map lines
06:52 casualjim: [23:23:33] https://github.com/scalatra/scalatra/blob/develop/example/src/main/scala/org/scalatra/ChatServlet.scala#L13
06:52 casualjim: [23:23:46] https://github.com/scalatra/scalatra/blob/develop/example/src/main/scala/org/scalatra/MeteorChatExample.scala#L53
06:52 casualjim: [23:23:53] that's the same point in the lifecycle
06:52 casualjim: [23:24:11] https://github.com/scalatra/scalatra/blob/develop/example/src/main/scala/org/scalatra/ChatServlet.scala#L22-36
06:52 casualjim: [23:24:27] https://github.com/scalatra/scalatra/blob/develop/example/src/main/scala/org/scalatra/MeteorChatExample.scala#L59-78
06:52 casualjim: [23:24:46] the "success" is just to force flushing the buffer it never arrives in the browser
06:52 casualjim: [23:25:14] https://github.com/scalatra/scalatra/blob

# /etc/haproxy/haproxy.cfg, version 1.5
global
maxconn 4096
#user haproxy
#group haproxy
#daemon
defaults
@casualjim
casualjim / ScalatraServer.scala
Created October 24, 2011 21:33 — forked from rossabaker/ScalatraServer.scala
dsl proposal for embedded servers
object Main {
def main(args: Array[String]) {
MySquerylScheme.initialize()
WebServer("src/main/webapp", Config.webServerPort) { server =>
server.inContext("/api") { context =>
context.mount("validate", new ValidateApp)
context.mount("channels", new MessageChannelApp)
context.mount("streams", new StreamsApp)
@casualjim
casualjim / CORSSupport.scala
Created October 22, 2011 21:20
CORS Support for scalatra
package backchat
package web
import javax.servlet.http.{ HttpServletResponse, HttpServletRequest }
import org.scalatra._
import collection.JavaConversions._
object CORSSupport {
val ORIGIN_HEADER: String = "Origin"
val ACCESS_CONTROL_REQUEST_METHOD_HEADER: String = "Access-Control-Request-Method"
upstream jetty {
server 127.0.0.1:12180;
}
server {
listen 80;
server_name www.api.backchat.io;
rewrite ^/(.*) http://api.backchat.io/$1 permanent;
}
@casualjim
casualjim / recipe.rb
Created October 5, 2011 09:37 — forked from rberger/recipe.rb
S3 File Resource for Chef
# Source accepts the protocol region:// with the host as the bucket
# access_key_id and secret_access_key are just that
# for the eu-west-1 region:
s3_file "/var/bulk/the_file.tar.gz" do
source "s3-eu-west-1://your.bucket/the_file.tar.gz"
access_key_id your_key
secret_access_key your_secret
owner "root"
group "root"