Skip to content

Instantly share code, notes, and snippets.

Avatar

Adriano Rocha adrianoluis

View GitHub Profile
@adrianoluis
adrianoluis / basic-pom.xml
Last active Feb 26, 2020
Basic pom.xml file with JUnit 4.12.
View basic-pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
@adrianoluis
adrianoluis / BarcodeUtilsTest.java
Created Nov 18, 2018
Testcase for BarcodeUtils.java
View BarcodeUtilsTest.java
import org.junit.Test;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static junit.framework.TestCase.*;
public class BarcodeUtilsTest {
@adrianoluis
adrianoluis / BarcodeUtils.java
Created Sep 4, 2017
This class validate a barcode and convert it to "Linha Digitável".
View BarcodeUtils.java
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* This class validate a barcode and convert it to "Linha Digitável".
*
* @author adriano
* @since Set 25, 2014
@adrianoluis
adrianoluis / StringUtil.kt
Created Aug 10, 2017
Simple class to slugify text in Kotlin.
View StringUtil.kt
import java.text.Normalizer
object StringUtil {
fun slugify(word: String, replacement: String = "-") = Normalizer
.normalize(word, Normalizer.Form.NFD)
.replace("[^\\p{ASCII}]".toRegex(), "")
.replace("[^a-zA-Z0-9\\s]+".toRegex(), "").trim()
.replace("\\s+".toRegex(), replacement)
.toLowerCase()
@adrianoluis
adrianoluis / QRCodeUtil.java
Created Feb 8, 2017
Simple utility class to create QR Code as Bitmap on Android using ZXing library
View QRCodeUtil.java
import android.graphics.Bitmap;
import android.graphics.Color;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
public class QRCodeUtil {
@adrianoluis
adrianoluis / DocumentUtil.java
Last active Nov 10, 2020
Utility class to validate CPF and CNPJ document types. For CPF use isValidSsn and for CNPJ use isValidTfn. Added to repo https://github.com/adrianoluis/misc-tools
View DocumentUtil.java
public class DocumentUtil {
// CPF
private static final int[] WEIGHT_SSN = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
// CNPJ
private static final int[] WEIGHT_TFN = {6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2};
private static int recursiveSum(int[] weight, char[] chr, int number) {
if (number <= 0) return 0;
You can’t perform that action at this time.