Skip to content

Instantly share code, notes, and snippets.

View awmpietro's full-sized avatar

Arthur Mastropietro awmpietro

  • São Paulo/SP - Brazil
View GitHub Profile
@awmpietro
awmpietro / gist:596c27a26306f1bf690f303b48b66a07
Created May 8, 2023 23:35
how to delete files permanently from your local and remote git repositories
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
@awmpietro
awmpietro / fetch_all_branches.sh
Created May 8, 2023 21:29
run this shell script to recreate all remote branches locally from a remote repository
#!/bin/bash
for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done
git fetch --all

Keybase proof

I hereby claim:

  • I am awmpietro on github.
  • I am amcode (https://keybase.io/amcode) on keybase.
  • I have a public key ASCA4Lvf3plKE_21E-FZNUXUV1Azs96nIAQyQpFvO3KRkAo

To claim this, I am signing this object:

@awmpietro
awmpietro / errorHandler.js
Created March 15, 2021 18:14
Simple error message handler if you use Axios
const errorHandler = (error) => {
if (error.response) {
// error message returned from axios request
return error.response.data;
} else {
// default error message
return error.message;
}
};
const bcrypt = require("bcrypt");
// Generate a new hashed password from a given string
const generateHashedPassword = async plainPassword => {
return new Promise( async (resolve, reject) => {
try{
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(plainPassword, salt);
resolve(hashedPassword);
} catch(error) {
@awmpietro
awmpietro / gist:e8f750e6429c9f6bcf9a9a95a0d4483e
Created January 30, 2018 01:02 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@awmpietro
awmpietro / leapYear.c
Created December 12, 2017 13:58
Calculate a leap year in C
int main() {
int year;
printf("Enter year");
scanf("%d", &year);
if(year % 4 == 0) {
if(year % 100 == 0) {
if(year % 400 == 0) {
printf("Yes, the year is leap year\n");
} else {
printf("No, this is not a leap year\n");
@awmpietro
awmpietro / group_values.sql
Created June 28, 2017 20:04
Group a count of values in specific label
SELECT
(case when field not in('value1', 'value2') then 'OUTROS'
when field in('value3') then 'value3'
count(est_des_descricao) as total
FROM
tables
GROUP BY
field DESC
@awmpietro
awmpietro / pangram.py
Last active June 28, 2017 20:02
Pangram function in Python
/*
** Check is a given string is a Pangram (https://en.wikipedia.org/wiki/Pangram)
** @params string
** @return bool
*/
def is_pangram( str ):
abc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x' ,'y', 'w', 'z']
abcClone = list(abc)
str = ''.join(str.split())
for l in str:
@awmpietro
awmpietro / paises.sql
Created April 9, 2016 03:48
SQL com lista de países em português e inglês
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`name_en` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=253 ;
INSERT INTO `country` (`id`, `name`, `name_en`) VALUES
(1, 'AFEGANISTÃO', 'AFGHANISTAN'),
(2, 'ACROTÍRI E DECELIA', 'AKROTIRI E DEKÉLIA'),