Skip to content

Instantly share code, notes, and snippets.

Avatar

Lucas Cavalcanti lucascs

View GitHub Profile
View ScalaTypeFinder.scala
@Component
@ApplicationScoped
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
lucascs / Provider.java
Created May 16, 2011
spring provider accepting overridings from jars
View Provider.java
public class Provider extends SpringProvider {
private static final Logger logger = LoggerFactory.getLogger(Provider.class);
@Override
protected SpringBasedContainer getContainer() {
final SpringBasedContainer delegate = super.getContainer();
final ConfigurableWebApplicationContext parentContext = new Mirror().on(delegate).get().field("parentContext");
return new SpringBasedContainer(parentContext) {
@Override
public <T> T instanceFor(Class<T> type) {
@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() {
@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 / Jsonable.java
Created Oct 14, 2011
generic converter for Json -> object #VRaptor
View Jsonable.java
public interface Jsonable { }
@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 / 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;
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 / 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 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