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
lucascs / SessionCreator.java
Created Aug 28, 2012
SessionCreator for Spring environments
View SessionCreator.java
@Component
@RequestScoped
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
lucascs / RedirectCommitInterceptor.java
Created Aug 15, 2012
Forcing commit on redirects
View RedirectCommitInterceptor.java
@Intercepts
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) {
View MapConverter.java
@Component
public class MapConverter implements Converter { //from XStream
//unmarshal => empty
public boolean canConvert(Class type) { return Map.class.isAssignableFrom(type); }
public void marshal(Object value, HierarchicalStreamWriter writer, MarshalingContext context) {
Map<String, Object> map = (Map<String, Object>) value; //assuming this
@lucascs
lucascs / CalendarParser.scala
Created Jun 29, 2012
Parser de datas em Scala
View CalendarParser.scala
package me.cavalcanti.lucas
import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormatter
import org.joda.time.format.DateTimeFormat
import scala.util.parsing.combinator.JavaTokenParsers
import org.joda.time.Period
class CalendarParser extends JavaTokenParsers {
View .bashrc
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\w$(__git_ps1 "\[\033[0;31m\](%s)")\[\033[00m\]\$ '
alias branch='git br | grep "*" | sed "s/\* //"'
alias gc='git commit -v'
alias gs='git status'
alias gp='git push origin `branch`'
alias gl='git pull origin `branch`'
alias grl='git pull --rebase origin `branch`'
alias ga='git add'
alias gb='git branch'
@lucascs
lucascs / ParametersFilter.java
Created Jun 1, 2012
Filter for removing blank id parameters
View ParametersFilter.java
import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@lucascs
lucascs / DateAndTimeCalendarConverter.java
Created Apr 27, 2012
Calendar converter for date and time
View DateAndTimeCalendarConverter.java
@Convert(Calendar.class)
public class DateAndTimeCalendarConverter extends LocaleBasedCalendarConverter {
private final Localization localization;
public DateAndTimeCalendarConverter(Localization localization) {
super(localization);
this.localization = localization;
}
public Calendar convert(String value, Class<? extends Calendar> type, ResourceBundle bundle) {
if (Strings.nullToEmpty(value).length() > "dd/mm/yyyy".length()) {
@lucascs
lucascs / Jsonable.java
Created Oct 14, 2011
generic converter for Json -> object #VRaptor
View Jsonable.java
public interface Jsonable { }
@lucascs
lucascs / LinkToHandler.java
Created Jul 5, 2011
Anatomia de uma solução - VRaptor linkTo para jsp
View LinkToHandler.java
@Component
@ApplicationScoped
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
lucascs / CustomJSONSerialization.java
Created Jul 4, 2011
overriding json serialization from VRaptor to cope with dates
View CustomJSONSerialization.java
import com.thoughtworks.xstream.converters.basic.DateConverter;
@Component
public class CustomJSONSerialization extends XStreamJSONSerialization {
public CustomJSONSerialization(HttpServletResponse response,TypeNameExtractor extractor, ProxyInitializer initializer) {
super(response, extractor, initializer);
}
@Override
public XStream getXStream() {
You can’t perform that action at this time.