Skip to content

Instantly share code, notes, and snippets.

View shreewatsa's full-sized avatar

shreewatsa shreewatsa

  • kathmandu , nepal
  • 10:15 (UTC +05:45)
View GitHub Profile
@shreewatsa
shreewatsa / gist:49bfe0e27f4e347b2274f8846ce03450
Created July 21, 2022 05:24 — 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:
@shreewatsa
shreewatsa / passwordless_sudo.md
Last active February 22, 2023 05:15
Run commands and scripts requiring sudo without typing the sudo password

Problem:

I want to shutdown my OS without typing the sudo password.

Solution:

Create a new file in /etc/sudoers.d/ directory.

Note that, any files under this directory is sourced in the /etc/sudoers file. And, always use visudo to edit sudoers files, as it safeguards you from getting locked out due to bad sudo configurations.

$ sudo visudo -f /etc/sudoers.d/nosudopassword; # any filename works, just a matter of choice.
@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; 
@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 / 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 / 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 / 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 / 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 / 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 :

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;