Skip to content

Instantly share code, notes, and snippets.

View SomajitDey's full-sized avatar

Somajit SomajitDey

View GitHub Profile
@SomajitDey
SomajitDey / fg_proc_list.bash
Last active September 26, 2021 16:10
Emulate job control signals from bash script
# First run the following 2 lines in your interactive bash attached to a controlling terminal
export bashpidfile="/tmp/bashpid" # File that stores the bash pid
export PROMPT_COMMAND='echo $$ > $bashpidfile' # Or, replace $$ with $BASHPID
# From another terminal do the following
### TPGID gives fg proc group on the tty the process is connected to, or -1 if the process is not connected to a tty
fgpg=$(ps --pid $(awk NR==1 $bashpidfile) -o tpgid=)
# Send signal SIG to all foreground processes to emulate user Ctrl- inputs
# Ctrl-C: INT, Ctrl-Z: TSTP, Ctrl-\: QUIT
@SomajitDey
SomajitDey / readline_cword.bash
Created April 3, 2021 03:21
Shell-function to give current word of Bash readline, i.e. "read -e". To be used with key-binding for custom TAB completion
### Source me
readline_cword(){
# Gives current word of Bash readline, viz. the word where the insertion point/cursor is currently at
set -- ${READLINE_LINE}
local length=${#1}
while ((length < READLINE_POINT)); do
shift
length+=${#1}
done
echo -n "${1}"
@SomajitDey
SomajitDey / freemium_port_forwarding_services.md
Last active April 28, 2025 22:21
A list of free or freemium services for exposing localhost to internet with a public ip
@SomajitDey
SomajitDey / ngrok_how_to.md
Last active October 14, 2021 18:22
Get free public URL / IP with ngrok
@SomajitDey
SomajitDey / streambin_pubsub_howto.md
Last active April 17, 2021 07:14
exploit streambin.pbedat.de with cURL for instant messaging to remote-access

How to use streambin for event-based workflow : pubsub (publish/subscribe) model

Push based workflow is more efficient than repeated pulls (polling). Thankfully, there is currently a free service for the same which is easy to use : https://streambin.pbedat.de/. There is also emitter.io and free, public MQTT brokers such as broker.hivemq.com (list).

  1. Create a unique channel-key - it may be the hash of your email id or the hash of your MAC address, or may even be the fingerprint of freshly generated private-public keypair.

  2. url="https://streambin.pbedat.de/streams/${channel_key}"
@SomajitDey
SomajitDey / multiline_read.bash
Created April 14, 2021 07:18
UI to input long logical lines that occupy multiple terminal lines through wrapping
while num=$(read -re -p "type: "|& tee /dev/tty|fold -w "$(tput cols)"|wc -l); do tput cuu $num;tput ed; done
@SomajitDey
SomajitDey / github-api.md
Last active April 21, 2021 07:02
Why updating a file in GitHub repo or updating a Gist through REST API is faster than git-push

Updating a Gist or file using API is much faster (almost 3 times) than git-push

Git-push takes a lot of work figuring out what files need to be pushed. The local copy also needs to query upstream about its current state before it can decide whether a pull is necessary before push.

A local commit, on the other hand, takes almost no work compared to git-push.

Because Gist / file update using the REST API is nothing but a file-ransfer over https + a local commit@upstream, it is supposed to be faster than git-push.

Git-fetch is faster than git-push and is also better than download using API

@SomajitDey
SomajitDey / chat_using_curl.md
Last active January 1, 2024 18:00
Chat using cURL and netcat or ncat. Demo with localhost.run.

Server-side

Create free ephemeral http relay using localhost.run:
port=<port> # Choose your local port that your server will listen to
file=<filename> # Choose file where <subdomain.localhost.run> will be stored

# Create tunnel in background
ssh -n -R 80:localhost:$port [email protected] -- --output json --no-inject-http-proxy-headers --no-inject-proxy-protocol-header 2>/dev/null | jq --unbuffered -r '.address' > ${file} &
@SomajitDey
SomajitDey / remote-access_pipe-to-me.md
Last active April 24, 2021 07:06
Remote shell with pipeto.me
  key=<random but unique key> # Such as the hash of your email id!
  
  ########### Server:
  
  mkfifo pipe
  
  bash --rcfile <(echo 'PS0="$(tput cuu1; tput ed)"') -i <pipe |&
  curl -sf -N -T . https://pipeto.me/${key} >pipe
 
@SomajitDey
SomajitDey / linux-cool-tools.md
Last active April 1, 2023 14:10
Linux tools I never wanna forget about
  • chroot #### Jail :> Confine a command's access within given root directory
  • runuser #### Run command as another user. Compare su
  • stdbuf [-oL] command #### Line buffering in output
  • rlwrap [-cr -aPassword: -p -S -P -o] command #### GNU Readline + History + TAB-Autocompletion + Colored prompt + Password hiding
  • fold #### Pretty line wrapping
  • wrap #### Pretty line wrapping
  • pr ### Paginate text file - prettify
  • more
  • less
  • tty ### Print the file name of the terminal connected to standard input