Skip to content

Instantly share code, notes, and snippets.

Agnaldo de Oliveira agnaldo4j

Block or report user

Report or block agnaldo4j

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@agnaldo4j
agnaldo4j / crawler_example.md
Last active Oct 15, 2016
Crawler example with mochiweb_html and mochiweb_xpath.
View crawler_example.md

Elixir simple crawler example

This example uses thease projects:

  1. mochiweb
  2. mochiweb_xpath

The HtmlPageReader goes to html's page and transform that content with mochiweb_html.parse

defmodule Usecase.HtmlPageReader do
@agnaldo4j
agnaldo4j / UserAPI.scala
Created Jan 16, 2016
Exemplo de endpoint acessando usecases
View UserAPI.scala
package com.opportunity.simple.restapi
import javax.persistence.EntityManagerFactory
import com.opportunity.objectives.model.User
import com.opportunity.objectives.usecases.user.{ListUsersUsecase, LoginByFacebookUserUsecase, SaveNewUserUsecase}
import com.opportunity.simple.restapi.response.ProtocolResponse
import com.typesafe.config.Config
class UserAPI(val apiConfig: Config, val entityManagerFactory: EntityManagerFactory) extends Respondable with Authenticable with PersistibleUser {
View SaveNewFriendsUsecase.scala
package com.opportunity.objectives.usecases.user
import com.opportunity.objectives.exceptions.UserInvalidException
import com.opportunity.objectives.model.{Friend, User}
import com.opportunity.objectives.persistence.adapter.user.NewUserPersistenceAdapter
class SaveNewFriendsUsecase(persistenceAdapter: NewUserPersistenceAdapter) {
def save(user:User, friends:List[Friend]): User = {
persistenceAdapter.findUserById(user.id) match {
@agnaldo4j
agnaldo4j / SaveNewFriendsUsecaseSpec.scala
Created Jan 12, 2016
Exemplo de teste usando specs2 e arquitetura limpa
View SaveNewFriendsUsecaseSpec.scala
/**
* https://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html
* https://vimeo.com/43612849
* https://etorreborre.github.io/specs2/guide/SPECS2-3.7/org.specs2.guide.Matchers.html
*
**/
package com.opportunity.objectives.usecases.user
import com.opportunity.objectives.exceptions.UserInvalidException
import com.opportunity.objectives.model.{Friend, User}
@agnaldo4j
agnaldo4j / macro.exs
Last active Jan 7, 2016
Executando código dinâmico em elixir
View macro.exs
Code.eval_quoted(
quote do: unquote(1) + unquote(1 + 1)
)
#code to be parsed 1 + (1 + 1)
#result of execution {3, []}
@agnaldo4j
agnaldo4j / Boot.scala
Created Oct 31, 2015
Implementação de servidor jetty embarcado com Java WebSocket API e Scalatra. :-)
View Boot.scala
def main(args: Array[String]) {
val port = restApiConfig.getInt("port")
println(restApiConfig.getString("resourceBase"))
val server = new Server(port)
val context = new WebAppContext()
context setContextPath "/"
context.setResourceBase(restApiConfig.getString("resourceBase"))
context.setInitParameter(ScalatraListener.LifeCycleKey, "com.opportunity.simple.restapi.ScalatraBootstrap")
context.addEventListener(new ScalatraListener)
@agnaldo4j
agnaldo4j / UserSpec.scala
Last active Oct 31, 2015
Estrutura testes de integração para API. Objetivo esconder ferramentaria e simplificar os testes
View UserSpec.scala
package com.opportunity.simple.restapi.user
import com.opportunity.simple.restapi.basic.BasicBehaviour
class UserSpec extends BasicBehaviour {
"The user endpoint" should {
args(sequential=true)
"Create new user" ! userEndpointForTest().executeTestCreateNewUser()
"Try create a user with same email" ! userEndpointForTest().executeTestTryCreateAUserWithSameEmail()
@agnaldo4j
agnaldo4j / UserAPI.scala
Created Oct 25, 2015
Separação tecnologia da implementação da regra do negócio. Com isso mudar de tecnologia de persistência e framework web fica bem mais fácil
View UserAPI.scala
post("/") {
contentType = "application/json"
authenticated { jsonObject =>
val entityManager = entityManagerFactory.createEntityManager()
val userRepository = new UserRepository(entityManager)
val userPersistenceAdapter = new NewUserPersistenceAdapterJPA(userRepository)
val usecase = new NewUserUsecase(userPersistenceAdapter)
val savedUser = usecase.save( User( jsonObject ) )
@agnaldo4j
agnaldo4j / SpringDataScalaTransactionControl.md
Last active Aug 29, 2015
Controle de transação com SpringData, SpringJPA e Scala
View SpringDataScalaTransactionControl.md

Exemplo de controle de transação com SpringData e Scala

Implementação JDBC

package com.codesimples.jdbc

import com.typesafe.scalalogging.Logger
import org.springframework.transaction.support.{TransactionCallbackWithoutResult, TransactionTemplate}
import org.springframework.transaction.{PlatformTransactionManager, TransactionStatus}
@agnaldo4j
agnaldo4j / UserMeasures.scala
Created Dec 18, 2014
Exemplo de objeto aplicando somente ações a estrutura de dados imutável.
View UserMeasures.scala
case class UserMeasures(state: Map[String,Any]) {
def gender : String = {
state.getOrElse("usr_genero", "").asInstanceOf[String]
}
def measures: List[Map[String,Any]] = {
state.getOrElse("measures", List[Map[String,Any]]()).asInstanceOf[List[Map[String,Any]]]
}
You can’t perform that action at this time.