Skip to content

Instantly share code, notes, and snippets.

View dhsathiya's full-sized avatar

Devarshi Sathiya dhsathiya

View GitHub Profile
# bash update_and_sync.sh /tmp/test/ [email protected] /tmp/test/
# syntax bash update_and_sync.sh <source> <user@ip> <destination>
DIRECTORY_TO_WATCH="$1"
REMOTE_SERVER_USER_IP="$2"
REMOTE_SERVER_LOCATION="$3"
inotifywait -m $DIRECTORY_TO_WATCH -e close_write -e delete |
while read path action file; do
rsync -avzhP $path $REMOTE_SERVER_USER_IP:$REMOTE_SERVER_LOCATION --delete
done
# <droplet name> <droplet IP>
doctl compute droplet list -o json | jq -r '.[] | "\(.name) \(.networks.v4[].ip_address)"'
# <instance tag value: Name>
aws ec2 describe-instances | jq -r ".Reservations[].Instances[].Tags[].Value" | perl -lne "print unless /Backup/"
# <Instance IP> <Instance tag value: Name>
aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | "\(.PublicIpAddress) \(.Tags[].Value)"' | perl -lne "print unless /Backup/"
# cURL headers
@dhsathiya
dhsathiya / crontab.txt
Created April 21, 2020 19:26
Notifies if battery is fully charged and/or low.
# Crontab Entries
# Notify if battery is full (equal to 100%)
*/1 * * * * if [ $(cat /sys/class/power_supply/BAT0/capacity) -eq 100 ]; then XDG_RUNTIME_DIR=/run/user/$(id -u) notify-send Hey "Battery Full"; fi
# Notify if battery is low (less than or equal to 10%)
*/1 * * * * if [ $(cat /sys/class/power_supply/BAT0/capacity) -le 10 ]; then XDG_RUNTIME_DIR=/run/user/$(id -u) notify-send Hey "Battery Low"; fi
#!/bin/sh
tmux new-session -s "ctrldev" -d
tmux send-keys -t ctrldev.1 "ssh root@server1" Enter
tmux split-window -h "ssh root@server2"
tmux split-window -h "ssh root@server3"
tmux split-window -v "ssh root@server4"
tmux split-window -v "ssh root@server5"
tmux split-window -v "ssh root@server6"
tmux select-layout tiled
tmux a -t ctrldev
@dhsathiya
dhsathiya / Nginx-Openresty-Dockerfile
Last active March 30, 2020 04:30
Snippets for getinto.in
# Dockerfile - Ubuntu Bionic
# https://github.com/openresty/docker-openresty
ARG RESTY_IMAGE_BASE="ubuntu"
ARG RESTY_IMAGE_TAG="bionic"
FROM ${RESTY_IMAGE_BASE}:${RESTY_IMAGE_TAG}
LABEL maintainer="Devarshi Sathiya <[email protected]>"
#!/usr/bin/env bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt update && \
apt install -y \
git \

Let's consider a constant stream of cache requests with a cache capacity of 3, see below:

A, B, C, A, A, A, A, A, A, A, A, A, A, A, B, C, D

If we just consider a Least Recently Used (LRU) cache with a HashMap + doubly linked list implementation with O(1) eviction time and O(1) load time, we would have the following elements cached while processing the caching requests as mentioned above.

[A]
[A, B]
[A, B, C]
[B, C, A] &lt;- a stream of As keeps A at the head of the list.

Dockerfile

FROM golang:alpine
MAINTAINER [email protected]
RUN apk update && apk add wget
RUN wget https://github.com/actions/migrate/releases/download/2019-08-06%4020-47/migrate-actions-linux.tar
RUN tar -xvf migrate-actions-linux.tar
COPY ./entrypoint.sh /
ENTRYPOINT [ "/entrypoint.sh" ]
A little explanation for those who have no idea what NOBLOGREDIRECT is.
The define(‘NOBLOGREDIRECT’, ‘%siteurl%’); inside of the wp-config.php makes it so that when someone enters a subdomain that does not exist on your site to redirect to whatever url you wish it to. You can use this to have it either go to a specific FAQ page or directly back to the main root installation, anywhere you want to direct it. the %siteurl% can be replaced for example define(‘NOBLOGREDIRECT’, ‘http://frumph.net/FAQ/site-create’);
When someone in their browser tries to go to (for example) http://badsubdomain.frumph.net/ a subomain which doesn’t exist, it will go to what is defined in NOBLOGREDIRECT.
Without using NOBLOGREDIRECT the (for example) http://badsubdomain.frumph.net/ – which is a subdomain that doesn’t exist would direct to the signup page asking which reports whether or not the user can create the bad subdomain in question. This is fine, there’s nothing wrong with it redirecting to the signup page if someone put
@dhsathiya
dhsathiya / i3_scratchpad.md
Last active July 30, 2019 16:37
Experiments with i3 in Virtual Env