Skip to content

Instantly share code, notes, and snippets.

View SomajitDey's full-sized avatar

Somajit SomajitDey

View GitHub Profile
@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 / 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
@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 / UUID-GUID.bash
Last active September 26, 2021 16:08
Bash script to generate 128-bit Universally/Globally Unique Identifiers in GNU/Linux
#!/usr/bin/env bash
# Description: A simple way to generate 128-bit Universally/Globally Unique Identifiers in GNU/Linux
# Usage: ./UUID-GUID.bash ["Any text you wanna put in"]
# Remark: Perhaps the use of so many variables is overkill, but Hey! It's fun ;-)
# Author: Somajit Dey <[email protected]> 2021
user_element="${1}" # Passed by the user as parameter (optional)
device_element="$(cat /sys/class/net/eth0/address)" # MAC address
@SomajitDey
SomajitDey / socat_http_echo_server.sh
Last active September 26, 2021 16:06 — forked from ramn/socat_http_echo_server.sh
Socat HTTP echo server
#!/bin/bash
socat -v -T0.05 tcp-l:8081,reuseaddr,fork system:"echo 'HTTP/1.1 200 OK'; echo 'Connection: close'; echo; cat"
1
2 // Examples for using socat (and filan)
3
4
5 //"$" means normal user, "#" requires privileges, "//" starts a comment
6
7 ///////////////////////////////////////////////////////////////////////////////
8 // similar to netcat
9
10 // connect to 10.1.1.1 on port 80 and relay to and from stdio