Skip to content

Instantly share code, notes, and snippets.


Lucas Cavalcanti lucascs

View GitHub Profile
View ScalaTypeFinder.scala
class ScalaTypeFinder(provider:ParameterNameProvider) extends TypeFinder {
implicit def class2raw(klass: Class[_]) = new {
def raw = klass.asInstanceOf[Class[AnyRef]]
implicit def isRoot(name: String) = new {
def isRootOf(path: String) = path.startsWith(name + ".") || path.equals(name)
lucascs /
Created May 16, 2011
spring provider accepting overridings from jars
public class Provider extends SpringProvider {
private static final Logger logger = LoggerFactory.getLogger(Provider.class);
protected SpringBasedContainer getContainer() {
final SpringBasedContainer delegate = super.getContainer();
final ConfigurableWebApplicationContext parentContext = new Mirror().on(delegate).get().field("parentContext");
return new SpringBasedContainer(parentContext) {
public <T> T instanceFor(Class<T> type) {
lucascs /
Created Jul 4, 2011
overriding json serialization from VRaptor to cope with dates
import com.thoughtworks.xstream.converters.basic.DateConverter;
public class CustomJSONSerialization extends XStreamJSONSerialization {
public CustomJSONSerialization(HttpServletResponse response,TypeNameExtractor extractor, ProxyInitializer initializer) {
super(response, extractor, initializer);
public XStream getXStream() {
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 /
Created Oct 14, 2011
generic converter for Json -> object #VRaptor
public interface Jsonable { }
lucascs /
Created Apr 27, 2012
Calendar converter for date and time
public class DateAndTimeCalendarConverter extends LocaleBasedCalendarConverter {
private final Localization localization;
public DateAndTimeCalendarConverter(Localization 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 /
Created Jun 1, 2012
Filter for removing blank id parameters
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;
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 / 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 {
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