Skip to content

Instantly share code, notes, and snippets.

View lucascs's full-sized avatar

Lucas Cavalcanti lucascs

View GitHub Profile
post '/junit-results' do
result = JSON.parse(request.body.read)
passes = result['stats']['passes']
failures = result['stats']['failures']
File.open(File.dirname(__FILE__) + '/../../target/artifacts/reports/javascript.xml', 'w') do |f|
xml = Builder::XmlMarkup.new
suite = xml.testsuite :errors => 0, :failures => failures, :tests => passes, :name => "javascript.tests" do
result['results'].each do |tc|
unless tc.nil?
tc['specs'].each do |s|
@lucascs
lucascs / HackedParametersProvider.java
Created November 10, 2010 13:37
ignore blank request parameters
@Component
public class HackedParametersProvider extends OgnlParametersProvider {
public HackedParametersProvider(...., HttpServletRequest request, ...) {
super(....., new HackedRequest(request), ....);
}
}
@lucascs
lucascs / FreemarkerPathResolver.java
Created November 23, 2010 02:18
How to change JSP to Freemarker in VRaptor.
@Component
public class FreemarkerPathResolver extends DefaultPathResolver {
//delegate constructor
@Override
protected String getPrefix() {
return "/WEB-INF/freemarker/";
}
@Target(ElementType.METHOD)
@Retention(RetentionType.RUNTIME)
public @interface DisplayTag {
String value();
}
@lucascs
lucascs / Basket.java
Created December 20, 2010 22:29
simple hypermedia example
public class Basket implements HypermediaResource {
private int id;
private String name;
public void configureRelations(RelationBuilder builder) {
builder.relation("self").uses(ItemController.class).showItem(id);
builder.relation("basket").at("/Basket/add/"+id);
}
@lucascs
lucascs / Out.java
Created December 22, 2010 14:40
support for VRaptor2's @out annotation
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Out {
}
@lucascs
lucascs / TenantRoutesParser.java
Created January 5, 2011 21:12
Multi-tenant on VRaptor
@Component
@ApplicationScoped
public class TenantRoutesParser implements RoutesParser {
private final RoutesParser parser;
public TenantRoutesParser(RoutesParser parser) {
this.parser = parser;
}
@lucascs
lucascs / CustomProvider.java
Created February 1, 2011 13:52
overriding guice's module
package my.apps.package;
public class CustomProvider extends GuiceProvider {
static class CustomModule extends AbstractModule {
private final Module module;
CustomModule(Module module) {
this.module = module;
}
@lucascs
lucascs / Calculadora.java
Created February 21, 2011 20:48
Programação funcional em Java
public class Calculadora {
private static final Prova _ = of(Prova.class);
public double mediaDeProvas(List<Prova> provas) {
return mediaPonderada(provas, function(_.getNota()), function(_.getPeso()));
}
public <T> double mediaPonderada(List<T> lista, Function<T, Double> valor, Function<T, Double> peso) {
double soma = 0.0;
double somaPesos = 0.0;
@lucascs
lucascs / ActiveRecord.scala
Created April 5, 2011 16:13
Scala Active Record with DI
@Component
class ActiveRecord[T](session:Session) {
implicit def obj2AR(obj:T) = new AR(session, obj)
}
class AR[T](session:Session, obj:T) {
def save = session.save(obj)
}