Skip to content

Instantly share code, notes, and snippets.

View shreewatsa's full-sized avatar

shreewatsa shreewatsa

  • kathmandu , nepal
  • 07:02 (UTC +05:45)
View GitHub Profile
@shreewatsa
shreewatsa / alacritty_cheatsheet.md
Created February 23, 2023 08:46
Alacritty Cheatsheet

>Command + b : Search on the visible screen buffer.

@shreewatsa
shreewatsa / git_cheatsheet.md
Last active August 27, 2024 16:29
Git Cheatsheet

Edit global git config. Remove --global flag to edit project wise git configs:

git config --global --edit;

Git aliases

Global aliases are stored in file ~/.gitconfig
Create Git aliases:

git config --global alias.recent-branches "for-each-ref --sort=-committerdate refs/heads/ refs/remotes/ --format='%(committerdate:iso8601) %(refname:short)'";  # Usage: git recent-branches;
git config --global alias.stashsave '!f() { git stash push -m "$1"; }; f' # Usage: git stashsave "foo";
git config --global alias.aliases "config --get-regexp '^alias\.'"; git aliases;  # Usage: git aliases;

mtr : a ping and traceroute combo.

macos:

$brew install mtr;
$sudo ln /usr/local/Cellar/mtr/0.95/sbin/mtr /usr/local/bin/mtr;  
$sudo ln /usr/local/Cellar/mtr/0.95/sbin/mtr-packet /usr/local/bin/mtr-packet;  
$sudo mtr www.google.com;  
@shreewatsa
shreewatsa / ssh_configs.md
Last active July 7, 2023 06:30
SSH Configurations

Copy public key to remote for passwordless authentication:

chmod 600 ~/.ssh/id_rsa;            # set keys permissions
cat id_rsa.pub | ssh [email protected] 'cat >> /home/ubuntu/.ssh/authorized_keys’;
/usr/bin/ssh-add --apple-use-keychain ~/.ssh/id_rsa;  # Run the command given below if you don't want to type private key password every time using the public key to make ssh connection. It stores the passphrase for private key in OSX Keychain, you can verify this by opening "Keychain Access" app. 
ssh-keygen -y -P "password" -f ~/.ssh/id_rsa;  # Verify if the password is correct decrypt the private key.
ssh-keygen -p -f ~/.ssh/id_rsa;     # Run this line to reset the passwor for case like you mistakenly entered wrong password in above command.

SSH Special Characters :

@shreewatsa
shreewatsa / cp.md
Created February 23, 2023 04:57
Competitive Programming Essentials

VIM Configuration :

Requirements: $brew install g++ gdb coreutils;

map <C-s>       = :w<cr>                                           " save file  
map <S-Left>    = :!gdb ./%:r <CR>                                 " Debug  
map <S-Down>    = :!g++-12 -std=c++14 -g % -o %:r<CR>              " build only  
map <S-Up>      = :!./%:r <CR>                                     " run only.  
map <S-Right>   = :!g++-12 -std=c++14 -g % -o %:r && gtimeout 4s ./%:r <CR>                             " build and run.  
@shreewatsa
shreewatsa / rsync_cheatsheet.md
Last active February 22, 2023 09:48
Rsync Cheatsheet

Rsync (Remote sync):

Backup, mirrorring, restoring tool. Uses delta transfer algorithm to only send changes instead of whole file, thereby reducing network load.
Syntax: $rsync [options] <source_destination> <remote_destination>;

Usages:

$rsync -avr --exclude="*.pyc" --exclude="static" remote_host:/opt/backup/ .;  # Pulling from remote to local.
$rsync -avr . remote_host:/opt/backup/;                                       # Pushing from local to remote.

Flags:

@shreewatsa
shreewatsa / mongodb.md
Last active July 4, 2023 13:48
Mongodb Cheatsheet

Installing mongosh in Remote Host:

scp ~/Downloads/GoogleChrome/mongosh-1.6.2-linux-x64.tgz remote_host:/home/sysadmin/;
ssh remote_host;
(sysadmin ~)$ tar -zxvf mongosh-1.6.2-linux-x64.tgz;
(sysadmin ~/mongosh1.6/bin)$ cd mongosh*/bin/;¡
(sysadmin ~/mongosh1.6/bin)$ chmod +x ./*;
(sysadmin ~/mongosh1.6/bin)$ sudo cp mongosh* /usr/local/bin/;
(sysadmin ~)$ mongosh;
@shreewatsa
shreewatsa / shell_script.md
Last active February 4, 2024 07:29
Shell Scripting Tips and Tricks

Get Linux OS name and version (4 ways):

$ lsb_release -a;  
$ cat /etc/os-release;
$ cat /etc/issue;
$ hostnamectl;

Run a command that is shadowed by an alias:

@shreewatsa
shreewatsa / vim_cheatsheet.md
Last active February 22, 2023 08:06
Vim Cheatsheet

Macro :

q[a-z]  : record macro, do something, then press q again to stop recording. ie qa starts recording in register "a".  
@[a-z]  : to repeat the macro previously created.  
q[A-Z]  : Append at the end of the macro. eg qA will start appending to what was recorded in qa previously.  
:register or :reg       : Macro are stored in Vim’s registers.  
“ayy    : Yank current line to register a.  
“Ay$    : Append content from current cursor position to line end into register "a".  
“ap     : Paste contents of register a in normal mode.  
“+p : Paste contents of system clipboard. TODO: research “*p register. 
@shreewatsa
shreewatsa / git_untrack_files.md
Last active February 23, 2023 04:12
Untrack files in git

Untracking Files in Git:

.gitignore is the primary way to untrack files and folders. But, what if you want to do the same without using .gitignore file ?

  1. Ignoring untracked files ie files that are new or has not been added to git yet.

Note: the .git/info/exclude file doesnot get uploaded to remote.

$ touch my_local_file.txt;  # Lets say, you don't want this file to be tracked by git.
$ git status -s;            # You can see that git detects this file, but you don't want this to happen.
$ cd .git;