Skip to content

Instantly share code, notes, and snippets.

Avatar
:electron:

Rafael Bertelli zfael

:electron:
View GitHub Profile
@zfael
zfael / refresh-token-approach.ts
Last active Aug 13, 2020
Node.js - refresh token approach with 2 way encryption + JWT
View refresh-token-approach.ts
import crypto from 'crypto';
import jwt from 'jsonwebtoken';
import { v4 as uuid } from 'uuid';
const secret = 'your-access-token-secret';
console.log('access token secret\n', secret);
const refreshTokenSecret = 'your-refresh-token-secret';
console.log('refresh token secret\n', refreshTokenSecret);
@zfael
zfael / load-test.ts
Last active May 14, 2020
Node script for load testing!
View load-test.ts
/**
* Usage
* - npm install loadtest
* - npx ts-node load-test.ts
*/
import loadtest from 'loadtest';
const method = 'GET';
@zfael
zfael / killport-shortcut.sh
Last active Jan 7, 2020
shortcut to kill a specific port
View killport-shortcut.sh
# Usage
# 1 - add below snippet on your bashrc/zshrc
# 2 - call it by "killport 4000"
# 3 - profit
killport() {
port=$(lsof -n -i4TCP:$1 | grep LISTEN | awk '{ print $2 }')
kill -9 $port
}
@zfael
zfael / sync-gitignore
Created Dec 18, 2018
Resync git repo with new gitignore file
View sync-gitignore
# rm all files
git rm -r --cached .
# add all files as per new .gitignore
git add .
# now, commit for new .gitignore to apply
git commit -m ".gitignore is now working"
Ref> https://stackoverflow.com/questions/7075923/resync-git-repo-with-new-gitignore-file
@zfael
zfael / git-search-deleted-line
Last active Oct 11, 2018
Git - Search for Deleted Lines
View git-search-deleted-line
"If you know the contents of the line, this is an ideal use case for:
git log -S <string> path/to/file "
Reference > https://stackoverflow.com/questions/4404444/how-do-i-git-blame-a-deleted-line
View .bash_profile - NVM for windows
# To use this, add .nvmrc with contents of 'N.N.N' to your project. e.g. 0.12.7
# Add the following to the end of .bash_profile or .bashrc
#
# if directory is changed
# if `.nvmrc` is found execute `nvm use`
# if `package.json` is round execute `nvm use default`
enter_directory() {
if [ "$PWD" != "$PREV_PWD" ]; then
PREV_PWD="$PWD";
if [ -e ".nvmrc" ]; then
@zfael
zfael / git-restore-file.sh
Created Jul 12, 2018 — forked from infusion/git-restore-file.sh
Find and restore a deleted file in a Git
View git-restore-file.sh
# Find last commit for the deleted file
git rev-list -n 1 HEAD -- $path
# Checkout the commit before the the delete happened
git checkout $commit^ -- $path
@zfael
zfael / uncommitLastCommit.md
Created Apr 19, 2018 — forked from alexislucena/uncommitLastCommit.md
Git: How to uncommit my last commit in git
View uncommitLastCommit.md

To keep the changes from the commit you want to undo

$ git reset --soft HEAD^

To destroy the changes from the commit you want to undo

$ git reset --hard HEAD^

You can also say

@zfael
zfael / nodejs.verifysignedfile.js
Last active Mar 23, 2021
Node.Js - CRYPTO How to verify a signed file
View nodejs.verifysignedfile.js
//how to execute: node verify.js <path file that you want to verify> <certificate path> <hash generate by sign.js>
//output: true if files are equal, false otherwise.
var crypto = require('crypto');
var fs = require('fs');
var args = process.argv.slice(2);
var fileName = args[0];
var certPath = args[1];
var sig = args[2];
@zfael
zfael / nodejs.signfile.js
Last active Mar 23, 2021
Node.JS - CRYPTO How to sign a file
View nodejs.signfile.js
//how to execute: node sign.js <path file> <path private key>
//output: signature of file
var crypto = require('crypto');
var fs = require('fs');
var args = process.argv.slice(2);
var fileName = args[0];
var keyPath = args[1];
//openssl genrsa -out key.pem 1024