Skip to content

Instantly share code, notes, and snippets.

@casualjim
casualjim / build-go-swagger.sh
Last active January 25, 2016 03:14 — forked from anonymous/build-go-swagger.sh
building go-swagger — for a five year old
#---- run this section just once ----#
export GOPATH="${HOME}/go"
export GO15VENDOREXPERIMENT='1'
`
cd $GOPATH/src/github.com/go-swagger/go-swagger
go get -u github.com/asaskevich/govalidator
go get -u github.com/naoina/denco
go get -u github.com/go-swagger/scan-repo-boundary/makeplans
abstract class BaseResource(implicit protected val swagger: Swagger)
extends ScalatraServlet with FutureSupport with JacksonJsonSupport with SwaggerSupport with Imports {
override protected val applicationName = Some("messaging-api")
protected def applicationDescription = "Messaging Services API"
protected implicit val defaultTimeout = Timeout(5 seconds)
override val jsonpCallbackParameterNames: Iterable[String] = Some("callback")
@casualjim
casualjim / scala-interview1.scala
Created May 1, 2013 19:55 — forked from oxbowlakes/scala-interview1.scala
simple exercise around map and flatmap
object GOption {
def some[A](a: A): GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
def none[A]: GOption[A] = new GOption[A] {
def cata[B](n: => B, s: A => B): B = sys.error("Implement me")
}
}
trait GOption[+A] {
implicit class PagePatternHelper(val sc: StringContext) extends AnyVal {
def page(args: Any*): PagePattern = {
val template = sc.standardInterpolator(treatEscapes, args)
val templateUrl = rl.Uri(template)
val path = templateUrl.path
val routeMatcher = new SinatraRouteMatcher(path)
val queryMultiParams = rl.MapQueryString.parseString(templateUrl.query.rawValue)
val queryParams = queryMultiParams.mapValues(_.head)
@casualjim
casualjim / hack.sh
Created March 31, 2012 23:15 — forked from nrk/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
package com.matygo.controllers
import java.io.File
import java.io.PrintWriter
import java.io.StringWriter
import scala.collection.JavaConversions.mapAsScalaMap
import org.scalatra.ScalatraKernel.MultiParamsKey
import org.scalatra.ContentTypeInferrer
import org.scalatra.util.MultiMap
import org.scalatra.CookieSupport
import org.scalatra.RouteMatcher
@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
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")
@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 / 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"