Skip to content

Instantly share code, notes, and snippets.

View gabfssilva's full-sized avatar
🎯
Focusing

Gabriel Francisco gabfssilva

🎯
Focusing
View GitHub Profile
public class Repository<T>
public Repository<T> fromEntity(){
return this;
}
public Where<T> where(){
Map<String, Object> parameters = new HashMap<String, Object>;
return new Where<T>(parameters);
}
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="my-persistent-unit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>dataSource</jta-data-source>
<properties>
package org.apache.openejb.tomee.boot;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
/**
* @author Gabriel Francisco - [email protected]
interface Command<T>{
void execute(T context);
}
class Chain<T>{
private List<Command<T>> commands;
public Chain(List<Command<T>> commands){
this.commands = commands;
}
package interceptor;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* @author Gabriel Francisco - [email protected]
*/
@Retention(RetentionPolicy.RUNTIME)
@gabfssilva
gabfssilva / example.scala
Created August 15, 2016 14:57
Strategy implemented with pattern matching
case class Transaction(transactionType: String)
trait Payment {
def pay(transaction: Transaction): Transaction
}
class MasterCard extends Payment {
override def pay(transaction: Transaction): Transaction = {
println("paid with master")
transaction
object BSTApp extends App {
def maxValue(head: Node, actual: Int = Int.MinValue): Int = head match {
case Node(v, null, null) => if (actual > v) actual else v
case Node(v, l, null) => maxValue(l, if (actual > v) actual else v)
case Node(v, null, r) => maxValue(r, if (actual > v) actual else v)
case Node(v, l, r) =>
val maxLeft = maxValue(r, if (actual > v) actual else v)
val maxRight = maxValue(l, if (actual > v) actual else v)
if (maxLeft > maxRight) maxLeft else maxRight
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import spark.ResponseTransformer
import spark.Spark._
object MainClass {
val objectMapper = new ObjectMapper with ScalaObjectMapper
objectMapper.registerModule(DefaultScalaModule)
===========================================================================
HTTP GET /frodo/api/products/58ac762ce051672d61af1648/events
[Header] Host -> 127.0.0.1:33324
===========================================================================
2017-02-21T14:17:36.968-0300 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58794 #10 (10 connections now open)
[mongod output] 2017-02-21 17:17:36 [Thread-11] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:10, serverValue:10}] to localhost:27017
---------------------------------------------------------------------------
[Status] Status(200)
[Header] Content-Type -> application/json; charset=utf-8
[Header] Content-Length -> 626
@gabfssilva
gabfssilva / sample.scala
Last active June 14, 2017 02:28
event sourcing
import java.util.{Date, UUID}
import InMemoryEventStore._
import scala.language.dynamics
/**
* @author Gabriel Francisco <[email protected]>
*/
class DynamicData(var data: Map[String, Any] = Map()) extends Dynamic {