Skip to content

Instantly share code, notes, and snippets.

View msanjaypandit's full-sized avatar

Sanjay Chaturvedi msanjaypandit

View GitHub Profile
@msanjaypandit
msanjaypandit / php-security.md
Last active March 4, 2022 19:55
[PHP-Security] #PHP #Security

PHP-Security

you are uploading the file use below code.

$file = basename(realpath($_GET['file']));

Avoid using mysql(i)_ extensions use PDO

filter_var($_REQUEST['search'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);

@msanjaypandit
msanjaypandit / aws-cli.md
Last active March 29, 2018 05:18
[AWS CLI] #aws-cli #aws #cli #a3

Aws cli configuration

AWS Access Key ID [None]: YOURKEY
AWS Secret Access Key [None]: YOURSECRETKEY
Default region name [None]: us-west-2
Default output format [None]: json

Space in S3 Bucket
aws s3api --profile PROFILE_NAME list-objects --bucket BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]" | awk 'NR!=2 {print $0;next} NR==2 {print $0/1024/1024/1024" GB"}'

@msanjaypandit
msanjaypandit / lamp-centos.md
Last active April 27, 2018 06:16
[LAMP on AMI] #AMI #AWS #EC-2 #Lamp #centos
  1. Clink on launch a virtual machine
  2. Select "Amazon Linux 2 LTS Candidate AMI 2017.12.0" A latest Amazon linux candidate 64 bit.
  3. Select "t2.micro" as Free tire instance.
  4. select auto option "Configure Instance Details"
  5. insert 30GB as storage.
  6. Create security group and assign port.
  7. click on launch using a new key pair (Remember you need to put .pem file at secure place.)
  8. Now your instance is ready.
  9. ssh -i /web/KP-EC2.pem ec2-user@xxx.xxx.xxx.xxx
  10. sudo yum update -y
@msanjaypandit
msanjaypandit / jquery-libraries.md
Last active March 8, 2018 09:17
[jquery Libraries] #jquery #javascript #equal-height #Responsive
@msanjaypandit
msanjaypandit / virtual-host-centos.md
Last active March 8, 2018 09:59
[Virtual host on centos] #lamp #centos #virtual-host #subdomain #configuration

Ubuntu

You may be using a ubuntu machine or you are creating virtual host on ubuntu server. Open terminal using ctrl+alt+T in ubuntu, putty on windows. Connect with ssh if you are going to creating virtual host on ubuntu server.

  1. sudo apt-get update (it will update all libraries)
  2. cd /var/www (Move to www path)
  3. sudo mkdir -p example1.com/public_html (it will create both directory example1.com and example1.com/public_html)
  4. sudo mkdir -p example2.com/public_html (it will create both directory example2.com and example2.com/public_html)
  5. cd /etc/apache2/sites-available/
@msanjaypandit
msanjaypandit / linux-commands.md
Last active February 7, 2022 13:19
[Linux Commands] linux command #linux #commands
  • grep keyword /var/spool/cron/root | egrep -v ^# | grep -v ^$ | awk '{print $1,$2,$3,$4,$5,$8}'
  • cat netstat.log.5 | awk '$4 ~ /:80$/ {c++;print $5 | "sed 's/::ffff://' | sed 's/:.*$//'| sort | uniq -c | sort -n | tail -n 10"} END {print c}'
  • netstat -plantu | grep -c :1433
  • ifconfig eth0
  • Print last 20 lines from the error_log file tail -20 /var/log/httpd/error_log
  • Get max number of client on apache configuration grep -i maxclients /etc/httpd/conf/httpd.conf
  • cat /etc/my.cnf | grep cache -i | grep -v ^#
  • grep "^|" queries-pre-restart.txt | awk '{ print $14 }' | sort | uniq -c | sort -nr
  • mkdir -p www/public_html Will make directory at nested level (it will create both directory)
@msanjaypandit
msanjaypandit / git.md
Last active May 25, 2022 14:21
[Git Commands] A basic git commands #git #commands

1. git checkout master

  • git checkout allows you to move between branches and potentially restore tree files.
  • The command git checkout master switches you to the master branch, which is always the best place to start before making changes to your repo.

2. git pull origin master

  • Get the latest updates on the master branch,
  • This is typically done to merge upstream changes. A git pull is actually a combination of git fetch, which grabs all the latest information, and git merge, which merges the two histories together.
  • Essentially, git pull origin master allows you to do two commands at once. It’s a great time-saver!
  • Always run git pull origin master before starting work on a repository. After all, you want to be sure your repository is up to date with the remote repo where you collaborate.
@msanjaypandit
msanjaypandit / compress.md
Last active January 29, 2018 06:13
[compress/decompress files] Compress and decompress .tar.gz files #tar.gz #compress
##To compress all files of foldername##
tar -cvzf docs.tar.gz /var/www/html/foldername

##extract docs.tar.gz in docs folder##
tar -xvzf docs.tar.gz
@msanjaypandit
msanjaypandit / mysql-queries1.md
Last active December 20, 2018 16:10
[MySQL Queries] Mysql queries #mysql #query
  • Convert DateTime in UnixTimeStamp
    SELECT *,from_unixtime(date_added) FROM TABLE_NAME order by date_added desc

  • Space consume by a table
    SELECT table_schema "Data Base Name",sum( data_length + index_length ) / 1024 / 1024 /1024 "Used GB" FROM information_schema.TABLES GROUP BY table_schema ;

  • Character Set utf8mb4_unicode_ci

  • Set a login path using terminal/putty

@msanjaypandit
msanjaypandit / redirect.md
Last active March 7, 2018 09:28
[www and https Redirection] Redirect all files to https url and www domain name #www #htaccess

Redirection to https file

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirection to https and www page

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]