Skip to content

Instantly share code, notes, and snippets.

View SomajitDey's full-sized avatar

Somajit SomajitDey

View GitHub Profile
@SomajitDey
SomajitDey / sudo_without_passwd.md
Last active March 11, 2022 16:56
Setup current USER such that sudo doesn't ask for password
sudo echo hi # This sudo is to accept the current password, so that it won't ask for password for next few minutes
echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$USER

To restore the default behavior of sudo asking for password just remove the /etc/sudoers.d/$USER file

@SomajitDey
SomajitDey / squid_setup_ubuntu_server_win10_client.md
Created March 11, 2022 12:18
Setting up a web proxy server (Squid) on Ubuntu-20.04

Ref:

  1. https://www.digitalocean.com/community/tutorials/how-to-set-up-squid-proxy-on-ubuntu-20-04
  2. https://answers.microsoft.com/en-us/windows/forum/all/adding-credentials-to-windows-proxy-settings/d6fdab82-6163-4aad-8133-43f7706ceb9c#:~:text=Setting%20up%20the%20credentials%20for,user%20name%20and%20the%20password.

Server setup

  • sudo apt update
  • sudo apt install squid
  • Squid should automatically start running. Check with : systemctl status squid.service
  • Now edit config : /etc/squid/squid.conf as described below
@SomajitDey
SomajitDey / install_ifort_ifx.md
Last active February 26, 2025 10:02
Install INTEL Fortran compiler ifort for free on Ubuntu(WSL2). Also install MKL. OpenMP and OpenMPI runtime for coarray support.

My route:

  1. curl -Lo- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | sudo gpg --dearmor -o /usr/share/keyrings/oneapi-archive-keyring.gpg
  2. sudo tee /etc/apt/sources.list.d/oneAPI.list <<< "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main"
  3. sudo apt update
@SomajitDey
SomajitDey / ovito_lammps.config
Created December 25, 2021 15:47
Self-contained Lammps dump for Ovito. Includes position, orientation and aspherical shape. Position as (x,y,z) means unscaled, (xs,ys,zs) means scaled (w.r.t. box size)
ITEM: TIMESTEP
1000
ITEM: NUMBER OF ATOMS
2
ITEM: BOX BOUNDS xx yy zz
0.0 20.0
0.0 20.0
0.0 20.0
ITEM: ATOMS id type x y z c_orient[1] c_orient[2] c_orient[3] c_orient[4] c_shape[1] c_shape[2] c_shape[3]
1 1 1.0 0.0 0.0 1.0 0.0 0.0 0.0 3.0 1.0 1.0
@SomajitDey
SomajitDey / ssl_passthrough.bash
Last active December 1, 2021 19:11
SSL/TLS passthrough reverse proxy/load-balancer: read SNI in Client-Hello and redirect
#!/usr/bin/env bash
# Get localtest.me for curl https://localtest.me
sudo nc -lk 443 | grep -Uzo --line-buffered '[0-9a-z\-\.]*test.me'
# To read length of client hello handshake - the first 4th and 5th byte - record layer
nc -l 8000 | (head -c3 >/dev/null; head -c2 | xxd -p) # for curl https://localtest.me:8000
@SomajitDey
SomajitDey / .gitattributes
Created October 1, 2021 12:14
Convert any IPFS / Libp2p CID to Base36
base36 linguist-language=bash
@SomajitDey
SomajitDey / wildcard_subdomain.md
Created September 20, 2021 19:43
How to test locally with (wildcard) subdomains

Test locally with (wildcard) subdomains

  1. Do nothing if your user-agent is Chrome, IE, Firefox. They connect to localhost with http://*.localhost:post

  2. Edit /etc/hosts or C:\Windows\System32\drivers\etc\hosts: Append lines like

    127.0.0.1 example.com
    127.0.0.1 subdomain1.exmaple.com subdomain2.example.com
    
@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}"
@SomajitDey
SomajitDey / ipcheck.bash
Created August 16, 2021 11:47
Check if any IPv4 address is private or public.
#!/usr/bin/env bash
# Brief: Given any IPv4 address check if it is private or public. IPv4 itself is not validated
# Exit code: 0 (private); 1 (public); 2 (neither private nor public)
# Usage: ipcheck <ip_addr>
_test(){
# Brief: Test if given value if within given limits. No output. Just exitcode.
local limit1="${1}" value="${2}" limit2="${3}"
[[ "$(echo -e "${limit1}\n${value}\n${limit2}" | sort -V | awk NR==2)" == "${value}" ]]
# TODO: May be `-V` is not needed in `sort`
@SomajitDey
SomajitDey / Enable_WSL2.txt
Created August 8, 2021 16:00
How to enable WSL2 in Win10
1. Open "Turn Windows Features On or Off"
Check "Windows Subsystem for Linux" & "Virtual Machine Platform"
Restart
2. Install "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi"
[Ref: https://docs.microsoft.com/en-us/windows/wsl/install-win10#manual-installation-steps]
3. In cmd.exe or PowerShell: wsl --set-default-version 2
4. Install Linux distribution of choice from MS store or if to upgrade existing distro from WSL1 to WSL2: