Skip to content

Instantly share code, notes, and snippets.

Lucas Cavalcanti lucascs

  • Nubank
Block or report user

Report or block lucascs

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
lucascs /
Created Apr 30, 2015
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 /
Created Jul 5, 2011
Anatomia de uma solução - VRaptor linkTo para jsp
public class LinkToHandler implements StereotypeHandler {
private Map<String, Map<String, Linker>> linkTo = Maps.newHashMap();
private final ServletContext context;
private final Router router;
public LinkToHandler(ServletContext context, Router router) {
this.context = context;
lucascs / invariants.clj
Last active Mar 29, 2016
Double entry modeling
View invariants.clj
(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 / mapper.rb
Last active Dec 24, 2015
Tire configuration for pt-BR
View mapper.rb
class Mapper
def!(options = {})
drop_index! if options[:delete]
Tire.index :index_name do
create :analysis => {
:filter => {
:pt_br_filter => {
:type => :stemmer,
:language => :minimal_portuguese
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;
protected SerializerBuilder getSerializer() {
try {
lucascs /
Created Mar 21, 2013
Resource handler para poder fazer: `${linkTo[controllers.MeuController].metodo}` ou `${linkTo[gerenciador.MeuController]}`
@Component // do vraptor
@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 /
Created Jan 10, 2013
A Routes parser that uses the last package name as the first level of uri: /package/controller/method
public class PackageRoutesParser extends PathAnnotationRoutesParser {
//delegate constructor
public PackageRoutesParser(Router router) {
lucascs /
Created Oct 31, 2012
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);
lucascs /
Created Aug 28, 2012
SessionCreator for Spring environments
public class SessionCreator implements ComponentFactory<Session> {
private final SessionFactory factory;
private final Proxifier proxifier;
private Session session;
public SessionCreator(SessionFactory factory, Proxifier proxifier) {
this.factory = factory;
this.proxifier = proxifier;
lucascs /
Created Aug 15, 2012
Forcing commit on redirects
public class RedirectCommitInterceptor implements Interceptor {
private Session session;
private MutableResponse response;
public RedirectCommitInterceptor(Session session, MutableResponse response) {
this.session = session;
this.response = response;
public boolean accept(ResourceMethod method) {
You can’t perform that action at this time.