Skip to content

Instantly share code, notes, and snippets.

@ankitdbst
ankitdbst / run.sh
Created February 18, 2022 01:05
Run cron with SNS notification on failure
#!/bin/sh
#
# Usage: Add below to crontab -e
# * * * * run.sh script
#
# This would run npm --prefix /path/to/app run script
if [ -z "$1" ]
then
echo "No script specified"
exit;
@ankitdbst
ankitdbst / .gitlab-ci.yml
Created April 29, 2020 14:16
Gitlab CI to deploy magento2 on AWS
image: ruby:2.5
stages:
- deploy
default:
before_script:
# For setting the IP of the runner with Amazon EC2 SG
- apt update
- apt install -y awscli jq
@ankitdbst
ankitdbst / tail-slack.sh
Created July 20, 2019 06:41
Tail logs and send to Slack Webhook
#!/bin/bash
# Ref: https://blog.getpostman.com/2015/12/23/stream-any-log-file-to-slack-using-curl/
# define $MAGE_ENV env var in your .profile
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$MAGE_ENV $1\\n$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done
@ankitdbst
ankitdbst / stop-monit.sh
Created July 20, 2019 06:34
Stop monitoring processes
pkill -f ./tail-slack.sh
@ankitdbst
ankitdbst / start-monit.sh
Created July 20, 2019 06:33
Monitor Nginx + Magento server logs.
echo "Stopping monitoring if running..."
./stop-monit.sh
declare WEBHOOK="https://hooks.slack.com/services/..."; # your web-hook
echo "Starting monitoring..."
nohup ./tail-slack.sh /var/log/nginx/access.log $WEBHOOK " 50[0-3]\{1\} \| 40[0-3]\{1\} " >/dev/null 2>&1 &
nohup ./tail-slack.sh /var/log/nginx/error.log $WEBHOOK "[error]" >/dev/null 2>&1 &
nohup ./tail-slack.sh /var/www/html/current/var/log/exception.log $WEBHOOK "main\.ERROR\|main\.CRITICAL" >/dev/null 2>&1 &
nohup ./tail-slack.sh /var/www/html/current/var/log/system.log $WEBHOOK "main\.ERROR\|main\.CRITICAL" >/dev/null 2>&1 &
echo "Done."
@ankitdbst
ankitdbst / aws-update-dynamic-ip
Last active June 24, 2021 03:11
Add current IP to Security Group in AWS using a description & port as filter
#!/bin/bash
while [[ "$#" -gt 0 ]]; do
case $1 in
-g|--group) group="$2"; shift ;;
-d|--description) description="$2"; shift;;
-p|--port) port="$2"; shift;;
-i|--ip) ip="$2"; shift;;
-f|--force) force=1;;
-h|--help) help=1;;
@ankitdbst
ankitdbst / APIHelper.java
Last active July 12, 2019 05:19 — forked from pallavahooja/APIHelper.java
Retrofit Retry
package app.goplus.in.v2.network;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by pallavahooja on 16/05/16.
*/
public class APIHelper {
@ankitdbst
ankitdbst / remove_idea_from_git
Created December 7, 2014 17:13
Remove .idea from Git
$ echo '.idea' >> .gitignore
$ git rm -r --cached .idea
$ git add .gitignore
$ git commit -m '(some message stating you added .idea to ignored entries)'
$ git push
@ankitdbst
ankitdbst / todo-world_.idea_.name
Created December 7, 2014 12:23
React.JS | Hello World (Todo)
todo-world
/*
** Skip Lists data structures. Equivalent to Balanced Binary Trees
** Insert: O(LogN)
** Remove: O(LogN)
** Search: O(LogN) on average (worst case: O(N))
*/
#include <vector>
#include <ctime>
#include <cstdlib>