Skip to content

Instantly share code, notes, and snippets.

@csokol
csokol / Classe.java
Created February 29, 2012 20:32
Teste
public class Classe {
}
@csokol
csokol / CCMetric
Created April 10, 2012 16:27
CCMetric.java
package tasks.metric.cc;
import japa.parser.JavaParser;
import japa.parser.ast.CompilationUnit;
import java.io.InputStream;
import model.SourceCode;
import tasks.metric.ClassInfoVisitor;
import tasks.metric.Metric;
@csokol
csokol / book.tex
Created April 16, 2012 20:31
book with parts
\documentstyle[11pt]{book}
\newenvironment{tubainapart}
{
\hrule
\Huge\bf \begin{center}
}
{
\end{center}
\hrule
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.ioc.Component;
import br.com.caelum.vraptor.resource.ResourceMethod;
public class S3FileProvider {
private final AmazonS3Client amazonS3Client;
public S3FileProvider(AmazonS3Client amazonS3Client) {
this.amazonS3Client = amazonS3Client;
}
public URL store(File file, String dir, String key) {
PutObjectRequest putObjectRequest = new PutObjectRequest(dir, key, file)
18:16:30 WARN [AbstractLifeCycle ] FAILED vraptor: com.google.inject.CreationException: Guice creation errors:
1) A binding to br.com.caelum.vraptor.ioc.ComponentFactory<org.hibernate.SessionFactory> was already configured at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.registerFactory(GuiceComponentRegistry.java:161).
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.registerFactory(GuiceComponentRegistry.java:161)
1 error
com.google.inject.CreationException: Guice creation errors:
1) A binding to br.com.caelum.vraptor.ioc.ComponentFactory<org.hibernate.SessionFactory> was already configured at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.registerFactory(GuiceComponentRegistry.java:161).
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.registerFactory(GuiceComponentRegistry.java:161)
javax.servlet.ServletException: br.com.caelum.vraptor.VRaptorException: The selected route is invalid for redirection: br.com.caelum.brutal.controllers.MeuController.post
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:944)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:879)
at org.apache.jsp._404_jsp._jspService(_404_jsp.java:295)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
16:43:35 WARN [WebAppContext ] Failed startup of context o.e.j.w.WebAppContext{/,file:/home/csokol/caelum/workspace/brutal/src/main/webapp/}
com.google.inject.CreationException: Guice creation errors:
1) A binding to br.com.caelum.vraptor.interceptor.Interceptor was already configured at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.deepRegister(GuiceComponentRegistry.java:117).
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.deepRegister(GuiceComponentRegistry.java:117)
2) A binding to br.com.caelum.brutal.migration.SimpleMigration was already configured at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.deepRegister(GuiceComponentRegistry.java:117).
at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.deepRegister(GuiceComponentRegistry.java:117)
3) A binding to br.com.caelum.brutal.migration.Migration was already configured at br.com.caelum.vraptor.ioc.guice.GuiceComponentRegistry.deepRegister(GuiceComponentRegistry.java:117).
@csokol
csokol / check_server.rb
Created June 7, 2013 23:00
script to check if a server is up, requires httparty gem and ruby compiled with openssl, to install deps: rvm install ruby-1.9.3-p376 rvm package install openssl gem install httparty
require 'net/smtp'
require 'httparty'
server_up = true
begin
response = HTTParty.get("http://metricminer.org.br/")
rescue
server_up = false
end
server_up = false if not response.nil? and response.code != 200
public String getPhoto(Integer width, Integer height) {
String size = width + "x" + height;
if (photoUri == null) {
String digest = Digester.md5(email);
String robohash = "http://robohash.org/size_"+size+"/set_set1/bgset_any/"+digest+".png";
String gravatar = "http://www.gravatar.com/avatar/" + digest + ".png?r=PG&size=" + size;
try {
return gravatar + "&d=" + java.net.URLEncoder.encode(robohash, "UTF-8");
} catch (UnsupportedEncodingException e) {
return gravatar;