Skip to content

Instantly share code, notes, and snippets.

Avatar
👇
adrianoluis.net

Adriano Rocha adrianoluis

👇
adrianoluis.net
View GitHub Profile
@adrianoluis
adrianoluis / git-refresh.sh
Last active July 3, 2022 17:50
Update master in all git repo under the provided directory or if missing uses running directory.
View git-refresh.sh
#!/bin/sh
GITROOT="${1:-.}"
find $GITROOT -name .git -type d | cat -n | while read n f
do
cd "$(dirname "$f")"
GITDEFBR="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
GITPROJ="$(pwd -P)"
echo "\033[32m>>> \033[1m$GITPROJ\033[0m\033[21m"
GITBRANCH=$(git rev-parse --abbrev-ref HEAD)
git add .
@adrianoluis
adrianoluis / basic-pom.xml
Last active December 4, 2021 04:25
Basic pom.xml file with JUnit 4.13.2.
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 November 18, 2018 20:06
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 September 4, 2017 02:04
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 August 10, 2017 19:33
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 February 8, 2017 02:51
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 May 24, 2023 19:03
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 sum(int[] weight, char[] numbers, int length) {
if (length <= 0) return 0;