Skip to content

Instantly share code, notes, and snippets.

View allanfreitas's full-sized avatar
🏠
Working from home

Allan Freitas allanfreitas

🏠
Working from home
View GitHub Profile
@allanfreitas
allanfreitas / phoneMasks.json
Created September 5, 2023 00:52 — forked from mikemunsie/phoneMasks.json
Phone Masks by Country Code JSON
{
"AC": "+247-####",
"AD": "+376-###-###",
"AE": "+971-5#-###-####",
"AE": "+971-#-###-####",
"AF": "+93-##-###-####",
"AG": "+1(268)###-####",
"AI": "+1(264)###-####",
"AL": "+355(###)###-###",
"AM": "+374-##-###-###",
@allanfreitas
allanfreitas / SomeInterceptor.java
Created April 30, 2023 15:28 — forked from ankushs92/SomeInterceptor.java
How to get Path Variables inside a Spring interceptor.[This post assumes that you have an Interceptor registered and set up using XML or Java config]
public class SomeInterceptor extends HandlerInterceptorAdapter{
@Override
public boolean preHandle(final HttpServletRequest request,final HttpServletResponse response,final Object handler)
throws Exception
{
/*Assume the URI is user/{userId}/post/{postId} and our interceptor is registered for this URI.
* This map would then be a map of two elements,with keys 'userId' and 'postId'
*/
final Map<String, String> pathVariables = (Map<String, String>) request
.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
@allanfreitas
allanfreitas / git_submodules.md
Created March 16, 2023 02:00 — forked from gitaarik/git_submodules.md
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of advantages of using submodules:

  • You can separate the code into different repositories.
@allanfreitas
allanfreitas / Encryptor.java
Created February 19, 2023 20:21 — forked from hsanger/Encryptor.java
Methods to encrypt and decrypt Strings and files (file encryption and decryption doesn't work for photos). Requires Apache Commons Lang.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
@allanfreitas
allanfreitas / smarapd_203.php
Created February 19, 2023 19:41 — forked from luizvaz/smarapd_203.php
Assinatura e Envio de XML SMARAPD padrão ABRASF 2.03 (Vila Velha)
<?php
/**
* User: LuizVAz
* Date: 28/02/2021
* Time: 19:46
*/
namespace Provedores\webService;
use DOMDocument;
@allanfreitas
allanfreitas / Sample.java
Created January 6, 2023 02:01 — forked from kinjouj/Sample.java
PDF Extract Text Using Apache Tika
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
@allanfreitas
allanfreitas / postgres-cheatsheet.md
Created June 16, 2022 11:51 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@allanfreitas
allanfreitas / postgres-cheatsheet.md
Created June 16, 2022 11:51 — forked from oradrs/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@allanfreitas
allanfreitas / oracle_compare_schemas.sql
Created June 16, 2022 11:49 — forked from tuksik/oracle_compare_schemas.sql
This script will compare two Oracle schemas and generate a report
REM http://www.dbspecialists.com/files/scripts/compare_schemas.sql
REM
REM compare_schemas.sql
REM ===================
REM
REM This script is provided by Database Specialists, Inc.
REM (http://www.dbspecialists.com) for individual use and not for sale.
REM Database Specialists, Inc. does not warrant the script in any way
REM and will not be responsible for any loss arising out of its use.
REM
@allanfreitas
allanfreitas / axios-catch-error.js
Created March 14, 2022 06:09 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨