Skip to content

Instantly share code, notes, and snippets.

View dhsathiya's full-sized avatar

Devarshi Sathiya dhsathiya

View GitHub Profile
#!/bin/bash
function date_to_seconds() {
if [[ $# -lt 1 ]]; then
echo "Date argument missing"
echo "Usage: date_to_seconds date"
exit 1
fi
remove_slash_date=$(echo $1 | sed 's/\//\-/g')
@dhsathiya
dhsathiya / readme.md
Last active February 21, 2024 10:20
WireGuard Setup

Setup WireGuard

Definitions

Server

Remote server (eg. DigitalOcean, AWS) where the WireGuard Server will be running.

Peer

@dhsathiya
dhsathiya / tmate.sh
Last active August 2, 2022 14:58
tmate in GitHub Action
function install_tmate () {
apt update
apt install -y locales-all openssh-client xz-utils
ls -al ~/ & mkdir ~/.ssh/
wget https://github.com/tmate-io/tmate/releases/download/2.4.0/tmate-2.4.0-static-linux-amd64.tar.xz
tar xvf tmate-2.4.0-static-linux-amd64.tar.xz
mv tmate-2.4.0-static-linux-amd64/tmate /usr/bin/tmate
tmate -V
echo 'set +e' >/tmp/tmate.bashrc
ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa
@dhsathiya
dhsathiya / zsh_ssh_client_logger.md
Last active April 25, 2022 01:23
ZSH command logging with SSH Client IP

Add following in .zshrc

preexec() {
    echo "[$(date +%d/%m/%Y-%H:%M:%S)] $(echo $SSH_CLIENT | awk '{ print $1}') - $1" >> /var/log/command.log
}

Dockerfile

FROM node:lts

ARG UID=1001
ARG GID=1001

RUN echo "######### $UID"
RUN echo "######### $GID"
@dhsathiya
dhsathiya / last_day.sh
Created November 24, 2020 13:32
Delete unused sites
#!/bin/bash
function date_to_seconds() {
if [[ $# -lt 1 ]]; then
echo "Date argument missing"
echo "Usage: date_to_seconds date"
exit 1
fi
@dhsathiya
dhsathiya / CloudFront_real_ip.js
Created November 17, 2020 09:00
Get Real-IP of a user in a separate request header with CloudFront <-> Lambda@Edge
// Get Real-IP of a user in a separate request header with CloudFront <-> Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
headers['true-client-ip'] = [{
key: 'True-Client-IP',
value: request['clientIp']
# !/bin/bash
# Because GH API was not able to do this.
# 1. Copy cURL request from Inspect > Network.
# 2. Update the URL like line number 8 (?page='"$i"'&q)
# Done!
i=0
curl -s 'https://github.com/pulls?page='"$i"'&q=is%3Aopen+is%3Apr+org%3AEXAMPLE+archived%3Afalse+author%3AUSER' \
-H 'Connection: VALUE_123' \
-H 'Pragma: VALUE_123' \
#!/bin/bash
IP=$(curl -4 icanhazip.com)
#echo $IP > /root/ip-changer/currentIPdd
OLD_IP=$(cat /root/ip-changer/currentIP)
echo "================ $(date) ================" >> /root/ip-changer/checkLog
if [ "$IP" != "$OLD_IP" ]; then
echo $IP > /root/ip-changer/currentIP
#!/bin/bash
# extract the protocol
proto="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
url="$(echo ${1/$proto/})"
# extract the user (if any)
user="$(echo $url | grep @ | cut -d@ -f1)"
# extract the host and port
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"