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 / auth_controller.rs
Created June 23, 2025 17:44 — forked from anowell/auth_controller.rs
Axum Auth: jwt token, accepts either Authz bearer or session cookie
use argon2::{Argon2, PasswordHash};
use axum_extra::extract::cookie::{Cookie, SameSite};
use axum_extra::extract::CookieJar;
async fn login_user(
ctx: State<ApiContext>,
Json(data): Json<LoginUser>,
) -> Result<(CookieJar, Json<LoginResponse>)> {
let user = models::user::get_user_pass_hash(&ctx.db, &data.email)
.await?

Next.js Starters

A list of CLI generators, starter kits / boilerplates and toolkits to kick start your Next.js apps.

  • What is included in this list:
    • Has ~1K+ Github stars
    • Actively maintained / up to date
    • Includes a style / css solution or UI Framework
    • Includes a database
  • Includes authentication / authorization
@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)