Skip to content

Instantly share code, notes, and snippets.

View pedrotoliveira's full-sized avatar
:octocat:
Working from home

Pedro Thiago A. G. Oliveira pedrotoliveira

:octocat:
Working from home
View GitHub Profile
@pedrotoliveira
pedrotoliveira / tagerts_ant_cobertura.xml
Created December 3, 2010 19:25
Cobertura Targets NetBeans - Targets Ant Cobertura
<!-- Cobertura Classpath -->
<path id="cobertura.classpath">
<fileset dir="${basedir}">
<include name="dev_libs/cobertura-1.9.4.1/cobertura.jar" />
<include name="dev_libs/cobertura-1.9.4.1/lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
<!-- Cobertura Instrumentations -->
<target name="cobertura-instrument" depends="init,compile,compile-test,-pre-test-run">
@pedrotoliveira
pedrotoliveira / example_jquery_ajax.js
Created August 16, 2011 20:37
Exemplo JQuery.ajax()
$.ajax( {
url : action,
type : "GET",
dataType : "json",
data : {
dispatch : "tabelaProdutosVinculados",
codigoEmpresa : codigoEmpresaVal,
codigoProduto : codigoProdutoVal
},
timeout : 5000,
@pedrotoliveira
pedrotoliveira / gerarBuilder.sh
Created June 20, 2012 20:55
Shell Script to Generate Builder Classes from POJOs
#!/usr/bin/sh
### Escrever Builder ####
function escreverBuilder() {
echo "package domain.builder;";
echo "";
echo "import domain.*;";
echo "";
echo "public final class ${POJO}Builder extends Builder<${POJO}> {";
echo "";
@pedrotoliveira
pedrotoliveira / Builder.java
Created June 21, 2012 16:49
Abstract Builder Classe
package domain.builder;
/**
* Abstract Builder
*
* @author Pedro Oliveira
*/
public abstract class Builder<T> {
protected final T instance;
@pedrotoliveira
pedrotoliveira / CurrencyFormat.java
Created November 1, 2012 19:40
Função de format moeda brasileira
public final class CurrencyFormat {
public static String format(String valor) {
Currency curr = Currency.getInstance(new Locale("PT", "br"));
char[] reversed = new StringBuilder(valor).reverse().toString().toCharArray();
StringBuilder sb = new StringBuilder();
int index = 0;
for (char c : reversed) {
if (index == curr.getDefaultFractionDigits()) {
sb.append(",");
} else if (index == curr.getDefaultFractionDigits() + 3) {
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(60);
robot.turn(45);
@pedrotoliveira
pedrotoliveira / gist:9eb2b1932efe9274ba97
Last active August 29, 2015 14:04
onMessage method
@Override
public final void onMessage(final Message message, final Channel channel) throws IOException {
try {
logger.all().logInfo(String.format("Received Message: %s",message));
Assert.notNull(message, "Unknow message: " + message);
if (consumerEnabled()) {
T object = getObject(message);
this.beforeOnMessage(object);
R response = this.onMessage(object);
this.afterOnMessage(object);
@pedrotoliveira
pedrotoliveira / add_serializable.sh
Last active November 18, 2015 19:17
Add Serializable for all classes in project
#!/bin/bash
function findClassesToImplementSerializable() {
for filename in $(find . -name "*.java");
do
echo $filename | /bin/grep -v "test";
if [ "${?}" -eq 0 ]
then
echo "$filename";
changeline;
fi
@pedrotoliveira
pedrotoliveira / EuclideanAlgorithm.java
Created December 23, 2015 12:17
Euclidean Algorithm
public class EuclideanAlgorithm {
private final List<Long> numbers;
public EuclideanAlgorithm(final List<Long> numbers) {
this.numbers = Collections.unmodifiableList(numbers);
}
public long calculateGCD() {
Iterator<Long> it = numbers.iterator();
@pedrotoliveira
pedrotoliveira / Solution.java
Last active December 28, 2015 16:28
Flipping bits
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int testCases = in.nextInt();
for (int i=0; i< testCases; i++) {
if (in.hasNextLong()) {