Skip to content

Instantly share code, notes, and snippets.

View zfael's full-sized avatar

Rafael Bertelli zfael

View GitHub Profile
@zfael
zfael / nodejs.checksum.js
Created June 20, 2017 13:57
NODE.JS - How to generate file's Checksum (CRYPTO)
var fs = require('fs');
var crypto = require('crypto');
fs.readFile('file.pdf', function(err, data) {
var checksum = generateChecksum(data);
console.log(checksum);
});
function generateChecksum(str, algorithm, encoding) {
return crypto
@zfael
zfael / nodejs.signfile.js
Last active October 5, 2021 16:21
Node.JS - CRYPTO How to sign a file
//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
@zfael
zfael / nodejs.verifysignedfile.js
Last active October 11, 2021 08:52
Node.Js - CRYPTO How to verify a signed file
//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 / uncommitLastCommit.md
Created April 19, 2018 17:45 — forked from alexislucena/uncommitLastCommit.md
Git: How to uncommit my last commit in git

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 / git-restore-file.sh
Created July 12, 2018 11:57 — forked from infusion/git-restore-file.sh
Find and restore a deleted file in a Git
# 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 / .bash_profile - NVM for windows
Last active October 23, 2018 12:59 — forked from allenhwkim/.bash_profile
usage of .nvmrc
# 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-search-deleted-line
Last active October 11, 2018 14:59
Git - Search for Deleted Lines
"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
@zfael
zfael / sync-gitignore
Created December 18, 2018 19:09
Resync git repo with new gitignore file
# 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 / killport-shortcut.sh
Last active January 7, 2020 18:46
shortcut to kill a specific port
# 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 / load-test.ts
Last active February 20, 2022 21:35
Node script for load testing!
/**
* Usage
* - npm install loadtest
* - npx ts-node load-test.ts
*/
import loadtest from 'loadtest';
const method = 'GET';