Skip to content

Instantly share code, notes, and snippets.

@rafarocha
rafarocha / MatcherIterablesOnlyOneElementInList.java
Last active August 29, 2015 14:10
Descobrir se elemento está duplicado em lista
// option 1
@Override protected boolean matchesSafely(Iterable<HttpParameter> parameters, Description desc) {
int count = 0;
for (HttpParameter http : parameters) {
if ( http.equalName(parameter.getName()) ) {
count++;
}
}
return count == 1;
}
// apenas um resumo do código atual
AtualizacaoBatchJDBC.executar() {
String sqlSelect = montaSelect(...);
try {
rsSelect = stmtSelect.executeQuery(sqlSelect);
while (rsSelect.next() && continuar) {
String sqlUpdate = montaUpdate(...);
stmtUpdate.addBatch(sqlUpdate);
// tratamento e algumas condicoes
stmtUpdate.executeBatch();
@rafarocha
rafarocha / sonar-plugin-problem.md
Last active August 29, 2015 14:13
Plugin Sonar Qube

Resumo

O plugin SonarQube 3.4.0.X não funciona no Eclipse Luna SR1 4.4.1 Estou usando o Ubuntun 13.04 e no eclipse, ativei a opção do proxy para direct antes dos passos abaixo

Passos

  1. Cliquei no botão direito em projeto
  2. Selecionei SonarQube > Change Project Association (apenas para testar vínculo com servidor) - deu ok
  3. Selecionei SonarQube > Analyze
  4. Deu a mensagem abaixo
@rafarocha
rafarocha / RestfullClient.java
Last active August 29, 2015 14:14
Rascunho de desenho para evolução na usabilidade do cliente
// isso é apenas uma idéia para discussão aberta e democrática
Configuration conf = new PropertyConfiguration( properties );
Request request = RequestModel.get( "produtos", Parameters.of(offset(5), limit(10)) );
Future<PaginationList<Produto>> future = Restfull .define( conf ) .at( request ). execute( new Callback() {
onSucess(PaginationList<Produtos> produtos) {
}
onFailure(ClientException e) {
@rafarocha
rafarocha / TemplatePostSemanticError.java
Last active August 29, 2015 14:16
Como tratar erro semântico com inclusão de informações adicionais. Caso em que o cliente deseja retornar a pessoa com campos adicionais
public PessoaFisica salvar(PessoaFisica pessoa) {
PessoaFisicaId id = null;
try{
// em caso status code 201, o core preenche o nit e digio
id = broker.salvar( pessoa );
} catch(ClientBusinessException e ) {
ErroSemantico erro = e.get("PESSOA_JA_EXISTE");
if ( erro == null ) {
throw new ExcecaoNegocio(); // por exemplo nacionalidade invalida
}
@rafarocha
rafarocha / git_tips.md
Last active August 29, 2015 14:23 — forked from fguillen/git_tips.md

(Several of these git examples have been extracted from the book 'Pragmatic guide to GIT' of Travis Swicegood )

Git tips

Global git user

git config --global user.name "Fernando Guillen"
git config --global user.email "fguillen.mail+spam@gmail.com"

Repository git user

cd /develop/myrepo

@rafarocha
rafarocha / error.project.similar.mongodb-music
Created September 3, 2011 12:34
error when run project with 'CrudRepository' and 'QueryDslPredicateExecutor'
23:57:52,652 ERROR ramework.test.context.TestContextManager: 324 - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@3bc486f2] to prepare test instance [com.bisai.common.repository.QuestionRepositoryTest@63779885]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.bisai.common.repository.QuestionRepositoryTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.bisai.server.repository.QuestionRepository com.bisai.common.repository.QuestionRepositoryTest.questionRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.bisai.server.repository.QuestionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframew
@rafarocha
rafarocha / Main.java
Created September 27, 2011 23:53
Problem on FastJSON when generate no public classes and no methods getters and setters
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSON;
public class Main {
public static void main(String[] args) {
Structure structure = new Structure();
List<Group> groups = new ArrayList<Group>();
@rafarocha
rafarocha / draw_image_canvas.cpp
Created November 19, 2011 03:34
preview sample image on canvas
Image* pImage = new Image();
pImage->Construct();
Rectangle rect(FORM_X, FORM_Y, FORM_WIDTH, FORM_HEIGHT);
Bitmap* pBitmap = pImage->DecodeN(L"/Res/bada.jpg", BITMAP_PIXEL_FORMAT_RGB565, 50, 50 );
r = __pOverlayCanvas -> DrawBitmap(rect, *pBitmap);
if (IsFailed(r)){
AppLog("nao carregou imagem");
}
120120 16:14:06 [Warning] Can't create test file /usr/local/mysql-5.6.4-m7-osx10.6-x86_64/data/rafarocha.lower-test
120120 16:14:06 [Warning] Can't create test file /usr/local/mysql-5.6.4-m7-osx10.6-x86_64/data/rafarocha.lower-test
120120 16:14:06 [Note] Plugin 'FEDERATED' is disabled.
./mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
120120 16:14:06 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
120120 16:14:06 InnoDB: The InnoDB memory heap is disabled
120120 16:14:06 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120120 16:14:06 InnoDB: Compressed tables use zlib 1.2.3
120120 16:14:06 InnoDB: CPU does not support crc32 instructions
120120 16:14:06 InnoDB: Initializing buffer pool, size = 128.0M