Skip to content

Instantly share code, notes, and snippets.

View anushshukla's full-sized avatar
💭
Silently and secretly building awesome applications

Anush Shukla anushshukla

💭
Silently and secretly building awesome applications
View GitHub Profile
@anushshukla
anushshukla / upload-file-validations.js
Created September 29, 2020 20:24
File uploading validations for MIME
const util = require('util');
const FileType = require('file-type');
var mmm = require('mmmagic'),
Magic = mmm.Magic;
var magic = new Magic(mmm.MAGIC_MIME_TYPE);
const exec = util.promisify(require('child_process').exec);
(async () => {
console.log('FileType csv', await FileType.fromFile('/path/to/file-name.csv'));
console.log('FileType png', await FileType.fromFile('/path/to/file-name.png'));
magic.detectFile('/path/to/file-name.csv', (err, res) =>
@anushshukla
anushshukla / s3-util.js
Last active May 5, 2021 19:45
S3 Util to Upload files and fetch uploaded files
const fs = require('fs'); // npm i fs
const AWS = require('aws-sdk'); // npm i aws-sdk
const arguments = {};
process.argv.forEach(arg => {
const [index, value] = arg.split("=");
console.log(index, value);
arguments[index] = value;
});
@anushshukla
anushshukla / http-error.js
Created September 22, 2020 19:47
JavaScript Custom Error (HTTP)
function HttpError(
message = 'Unknown',
status = 500,
code = 'InternalServerError'
) {
this.name = "HttpError";
this.status = status;
this.code = code;
this.message = message;
this.success = false;
@anushshukla
anushshukla / check-versions.js
Created August 27, 2020 12:04
Check NodeJS and NPM versions
import semver from 'semver';
import childProcess from 'child_process';
import packageJson from './package.json';
const exec = command => new Promise((resolve) => {
childProcess.exec(command, (error, stdout, stderr) => {
if (error) {
return resolve([error]);
}
if (stderr) {
@anushshukla
anushshukla / promise-callback-sample.js
Created October 25, 2019 08:15
Promise and callback example
var promise = canReject => new Promise((resolve, reject) => canReject ? reject('bye') : resolve('hi'))
const thenCallback = message => console.log(message);
const catchCallback = message => console.log(message);
promise()
.then(thenCallback)
.catch(catchCallback)
promise(true)
.then(thenCallback)
.catch(catchCallback)
@anushshukla
anushshukla / redshiftSetup.txt
Created August 1, 2019 18:13
Setup AWS Redshift in J SQL Workbench on Ubuntu
Step.1
- download j workbench
- install java
- java -jar ~/Documents/Workbench-Build124/sqlworkbench.jar &
Step.2
- download postgres driver
Step.3
- Add path to postgres downloaded zip at AWS Redshift Driver after going to Manager Driver via Menu
@anushshukla
anushshukla / reverseProxyVhost.conf
Created August 1, 2019 18:10
Reverse Proxy Vhost Config file in Apache Server
<VirtualHost *:80>
ServerName insertName.youSiteName.com
DocumentRoot /var/www/html/youSiteName.com
ProxyRequests on
<Proxy *>
Order deny,allow
Allow from all
@anushshukla
anushshukla / fiddlerSetup.txt
Created August 1, 2019 18:05
Fiddler Setup on Linux machine
Alt+Ctrl+T
sudo apt-get update -y
copy paste sudo apt-get install mono-complete -y
cd ~/Downloads
wget http://telerik-fiddler.s3.amazonaws.com/fiddler/fiddler-linux.zip
sudo apt-get install unzip -y
unzip fiddler-linux.zip\?sfvrsn\=2 -d fiddler
cd fiddler/
mono Fiddler.exe
@anushshukla
anushshukla / localSitesSetup.txt
Last active August 1, 2019 18:02
Local Website Application Setup on LAN
# go to the directory where we will keep the codebase for the local sites
cd /var/www/html
git clone githubRepoUrl
sudo apt-get update -y
#install apache2
sudo apt-get install apache2
@anushshukla
anushshukla / .bash_aliases
Last active April 11, 2021 22:27
Bash Aliases to run in terminal in easy and simple commands
alias checkoutsites='cd /var/www/html'
# react coverage html dump
alias getCoverageFilesList='git diff --name-only origin/develop | grep -v public/ | grep -v api/ | grep -v styles | grep -v __tests__ | grep -v action_types'
alias startNodeServer='cd /var/www/html/backend && NODE_ENV=local nvm exec v10.12.0 node . &'
alias opensqlworkbench='java -jar ~/Documents/Workbench-Build124/sqlworkbench.jar &'
alias openlocaldb='mysql -h 127.0.0.1 -u root -p1234 -A'
function spacestotab() {
# $1 -> directory # $2 -> regex matching files within the $1 directory $3 -> tabs count, generally being 2
find $1 -name '$2' ! -type d -exec bash -c 'expand -t ${3:-2} "$0" > /tmp/e && mv /tmp/e "$0"' \{\} \\