Skip to content

Instantly share code, notes, and snippets.

View molekilla's full-sized avatar

Rogelio Morrell molekilla

  • Panama
View GitHub Profile
@molekilla
molekilla / gist:2183411
Created March 24, 2012 14:19
Escuelita de Scala - Parte 3
# Rutas
# ~~~~
# RegPubFinder
GET / controllers.Application.index
GET /about controllers.Application.about
GET /findByName/:searchText controllers.Application.findByName(searchText: String)
GET /typeahead/:searchText controllers.Application.typeahead(searchText: String)
GET /sa/:ficha controllers.Application.show(ficha: String)
@molekilla
molekilla / gist:2183479
Created March 24, 2012 14:25
Escuelita de Scala - Parte 3 - Controller
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.json._
import services.RegPubServices
object Application extends Controller {
def index = Action {
@molekilla
molekilla / gist:2219140
Created March 27, 2012 18:51
Escuelita de Scala - Parte 3a - Main
@(title: String)(navbarContext: Html)(sidebar: Html)(content: Html)
@import tags._
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="RegPubFinder">
<meta name="author" content="Rogelio Morrell">
@molekilla
molekilla / gist:2219280
Created March 27, 2012 19:04
Escuelita de Scala - Parte 3a - Navbar tag
@(navbar: Html)
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
@molekilla
molekilla / gist:2219408
Created March 27, 2012 19:17
Escuelita de Scala - Parte 3a - Index page
@()
@navbarContext = {
<li class="active"><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
}
@sidebar = {
<div class="well sidebar-nav">
<ul class="nav nav-list">
@molekilla
molekilla / gist:2220581
Created March 27, 2012 21:39
Escuelita de Scala - Parte 4 - Modelo de servicios
package services
import play.api.libs.json._
import org.elasticsearch.action.index._
import org.elasticsearch.common.settings._
import org.elasticsearch.client.transport._
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.action.search._
import org.elasticsearch.index.query._
import org.elasticsearch.search.sort._
@molekilla
molekilla / gist:2220670
Created March 27, 2012 21:47
Escuelita de Scala - Parte 4 - RegPubServices
package services
import play.api.libs.json._
import play.api.Logger._
object RegPubServices
{
def apply() = new RegPubServices()
}
@molekilla
molekilla / gist:2228366
Created March 28, 2012 17:17
Escuelita de Scala - Parte 4a - Typeahead
package services
import play.api.libs.json._
import org.elasticsearch.action.index._
import org.elasticsearch.common.settings._
import org.elasticsearch.client.transport._
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.elasticsearch.action.search._
import org.elasticsearch.index.query._
import org.elasticsearch.search.sort._
@molekilla
molekilla / gist:2229438
Created March 28, 2012 18:57
Escuelita de Scala - Parte 4a - typeahead continue
// RegPubServices
class RegPubServices extends SearchService with DataModelService {
def searchTypeahead(query:String):JsValue = {
val hits = typeahead(query)
val companyNames = hits.map( hit => (hit \\ "fields").map( h => Map("item" -> h \ "nombre"))).flatten
// RM: Alternativamente, para no usar Underscore para crear un array
// val companyNames = hits.map( hit => (hit \\ "fields").map( h => h \ "nombre")).flatten
Json.toJson(companyNames)
@molekilla
molekilla / gist:2231130
Created March 28, 2012 22:32
Escuelita de Scala - Parte 4b - mongodb with casbah
package services
import com.mongodb.casbah.Imports._
import com.mongodb.casbah.commons.conversions.scala._
import com.mongodb._
import com.mongodb.ServerAddress
import com.mongodb.util._
import scalaj.collection.s2j._
abstract trait RegpubDataUtil {