Skip to content

Instantly share code, notes, and snippets.

View dhsathiya's full-sized avatar

Devarshi Sathiya dhsathiya

View GitHub Profile

useful command for debugging.

tail -f <filename>
tail -f -n <number-of-tailing-lines> <filename>

#example to tail from last 1000 files
tail -f -n 1000 <filename>
fields @timestamp, @message
| parse @message '*Query_time: * Lock_time: * Rows_sent: * Rows_examined: *\n*' as host, query_time, lock_time, rows_sent, rows_examined, query
| sort query_time desc
| limit 100
@dhsathiya
dhsathiya / i3_scratchpad.md
Last active July 30, 2019 16:37
Experiments with i3 in Virtual Env
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

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" ]

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.
#!/usr/bin/env bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt update && \
apt install -y \
git \
@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]>"
#!/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 / 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