Skip to content

Instantly share code, notes, and snippets.

View SomajitDey's full-sized avatar

Somajit SomajitDey

View GitHub Profile
@SomajitDey
SomajitDey / dump.bash
Last active March 26, 2021 20:00
Dump input stream at a given path
# This function dumps the input stream to the path given as parameter.
# If PATH gets unlinked by another (cooperative) process, it creates a new file at PATH and continues dump
# Provide a lockfile as the 2nd positional parameter. This is needed so that another process doesn't remove PATH
# when it is being written to.
stream_dump(){
declare -x path="${1}"
local lock="${2}"
local timeout="1" # Interval for polling $path
declare -x line
@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 / 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 / curl.md
Created April 17, 2021 20:20 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API.

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@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 / github_for_file_sharing.md
Created April 21, 2021 07:12
How to use GitHub as a pastebin/file-sharing without increasing your repo size or eating away from your free quota
  1. Create blob using API and extract its URL from the response using jq '.url'
  2. Give the URL to anybody you wanna share the file with. All he needs to do is download

Since no commit is pointing to the blob, it doesn't present itself in your repository history and therefore, doesn't increase repo size.

@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 / Heroku How-To Host Bash or anything for free.md
Created May 3, 2021 10:43
How to host anything on heroku.com in their free-tier 550 hrs/month. Web-apps mostly sleep so very low consumption.

Heroku Bash How-to

Heroku offers PaaS with a generous free-tier of 550 hours/month without requiring any credit-card validation. Official support is for Node.js, Python, Go, Ruby etc. But what if you just need to run a bash script, may be a netcat based server? Or you simply need to serve a webpage over http or https, and all you know is bash? (Of course you can also use the free services of x10hosting.com for the latter.)

Here are some simple steps to deploy a bash-script at Heroku.

  1. Open a Heroku account
  2. Download the Heroku CLI
  3. git init the directory that contains your bash script
  4. heroku login
@SomajitDey
SomajitDey / gist:ea96825c32dbcbf08c968eb2724b1fcd
Created July 4, 2021 13:50 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: πŸ˜„ :smile: πŸ˜† :laughing:
😊 :blush: πŸ˜ƒ :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
πŸ˜† :satisfied: 😁 :grin: πŸ˜‰ :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: πŸ˜€ :grinning:
πŸ˜— :kissing: πŸ˜™ :kissing_smiling_eyes: πŸ˜› :stuck_out_tongue:
@SomajitDey
SomajitDey / urldecode
Last active September 7, 2021 15:10
url-encode and url-decode using bash and xxd
#!/usr/bin/env bash
# Ref: https://unix.stackexchange.com/questions/159253/decoding-url-encoding-percent-encoding
# Ref: https://github.com/sixarm/urldecode.sh
input="${@//+/ }"
echo -e "${input//%/\\x}"