Skip to content

Instantly share code, notes, and snippets.

View lucascs's full-sized avatar

Lucas Cavalcanti lucascs

View GitHub Profile
@lucascs
lucascs / invariants.clj
Last active March 29, 2016 19:00
Double entry modeling
(def billing-violations [negative-entries small-minimum-payment prepaid-mutual])
(def loss-violations [credit-loss pre-loss])
(def general-violations [minimum-payment-mutual])
(defn all-violations [balances]
(concat billing-violations loss-violations general-violations))
(s/defn fixing-invariants :- [Entry] [initial-balances :- Balances, new-entries :- [Entry]]
@lucascs
lucascs / Capitalize.java
Created April 30, 2015 01:50
Capitalize java 8
import java.util.Arrays;
public class Capitalize {
public static String capitalize (String x) {
return x.substring(0,1).toUpperCase() + x.substring(1).toLowerCase();
}
public static void main(String[] args) {
String text = "gabinete do deputado fulando de tal e de dona maria";
@lucascs
lucascs / 1_basics.rb
Last active August 29, 2015 14:04
TDC
p "Hello World"
#!/usr/bin/ruby
irb
@Specializes
@RequestScoped
public class CidLogicResult extends DefaultLogicResult {
private MutableRequest request;
public CidLogicResult(...., MutableRequest request) {
super(....);
this.request = request;
}
@Override
@lucascs
lucascs / boleto.clj
Created February 26, 2014 01:34
Caelum Stella em Clojure
(ns accounts.adapters.boleto
(:import (br.com.caelum.stella.boleto
Datas Sacado Emissor Boleto
bancos.Santander transformer.GeradorDeBoleto)))
(defn generate []
(let [datas (-> (Datas/novasDatas)
(.comDocumento 15 2 2014)
(.comProcessamento 15 2 2014)
(.comVencimento 17 2 2014))
@lucascs
lucascs / mapper.rb
Last active December 24, 2015 15:19
Tire configuration for pt-BR
class Mapper
def self.map!(options = {})
drop_index! if options[:delete]
Tire.index :index_name do
create :analysis => {
:filter => {
:pt_br_filter => {
:type => :stemmer,
:language => :minimal_portuguese
@lucascs
lucascs / LazyJSONSerialization.java
Created July 13, 2013 17:11
Lazy JSON Serialization
@Component
public class LazyJSONSerialization extends XStreamJSONSerialization {
private SerializerHolder holder;
public LazyJSONSerialization(SerializerHolder holder, HttpServletResponse response, TypeNameExtractor extractor, ProxyInitializer initializer, XStreamBuilder builder) {
super(response, extractor, initializer, builder);
this.holder = holder;
}
@Override
protected SerializerBuilder getSerializer() {
try {
@lucascs
lucascs / PackageResourceHandler.java
Created March 21, 2013 15:01
Resource handler para poder fazer: `${linkTo[controllers.MeuController].metodo}` ou `${linkTo[gerenciador.MeuController]}`
@Component // do vraptor
@ApplicationScoped
@org.springframework.stereotype.Component("stereotypeHandler") // só se for spring
public class PackageResourceHandler implements StereotypeHandler {
private final Map<String, Class> controllers;
private final Map<String, Class> gerenciador;
public PackageResourceHandler(ServletContext context) {
context.setAttribute("controllers", controllers);
context.setAttribute("gerenciador", gerenciador);
@lucascs
lucascs / PackageRoutesParser.java
Created January 10, 2013 02:00
A Routes parser that uses the last package name as the first level of uri: /package/controller/method
@Component
@ApplicationScoped
public class PackageRoutesParser extends PathAnnotationRoutesParser {
//delegate constructor
public PackageRoutesParser(Router router) {
super(router);
}
@Override
@lucascs
lucascs / Redirect.java
Created October 31, 2012 12:25
Redirecting to a ResourceMethod
Result result = //...
ResourceMethod method = //...
Object[] args = //...
Object redirecting = result.redirectTo(method.getResource().getType());
new Mirror().on(redirect).invoke().method(method.getMethod()).withArgs(args);