Just a collection of some notes and tips that helps me in my development workflow.
SSH
- Quit an ssh session using
CR~.
and get to your local terminal.~
is the escape character for ssh and dot to quit ssh. But note that tilda has to follow new line. When ever your ssh connection gets disconnected for one reason or the other, say you lost internet connection or some other reason, sometimes the screen wont repsond to any keystroke and it seems like its struck in the ssh session. Its very annoying. Instead of closing the terminal, you can do this insteadCR~.
- Add
ServerAliveInterval 60
to your ssh config file, most probably in~/.ssh/config
. Usually by default your ssh connection closes if it is idle for a long time, by doing this you are pinging every 60 seconds to keep the connection alive. Very helpful as you don’t have to connect to your remote machine again and again.
Useful command line tools
- s3cmd, interact with your s3 buckets
pip install s3cmd
s3cmd --configure
# configure your keyss3cmd ls
# list buckets, contents of a dirs3cmd mb s3://new_bucket/
# make new buckets3cmd put --recursive localfiles s3://uri/
# copy local files to s3s3cmd get --recursive s3://uri/
# get s3 files to local machine
- jq, parse json files and pretty print on terminal
brew install jq
- grep, unix search tool
grep -A2 query file.txt
# prints 2 linesAfter
the queried termgrep -B2 query file.txt
# prints 2 linesBefore
the queried termgrep -C2 query file.txt
# prints 2 lines ofContext
on both sidesgrep -e regex file.txt
# searches for the regexp
- sort, sorting text
sort -nr
# sorts numbers in descending order
- awk, command line programming language?
cat file.txt | awk '{print $2}'
# prints the second column- it does a lot more things, but this is what i end up using the most for
- watch, executes the given command with the time interval mentioned
watch -d -n600 "cat train.log | grep EpRewMean | awk '{print \$2,\$1}' | sort -nr | head"
n
flag gives the time interval, so in above example every 10 minutes it executes the command to give the best mean reward.d
flag highlights the difference between two consecutive runs.
- head tail, head and tail of the files
tail -1000f file.txt
# last 1000 lines and waits for more lines that are being added to the filehead -n 25 file.txt
# first 25 lines
- gist, command line gist utility
brew install gist
gist --login
# loging to your githubgist -p file.txt
# upload private gist
- screen, window manager that multiplexs multiple terminal sessions
screen -rd
reattach to an existing secreen session even if its open somewhere elseCtrl-a d
detach from an existing screen sessionCtrl-a ?
help menu in screenCtrl-a n
next terminalCtrl-a p
previous terminalCtrl-a k
kill the curernt temrinal in screen
python
python -u python_script.py > python_logs.txt
Usually I want to capture all the print statement logs in some text file, so that I can save them for further reference, instead of throwing them off in stdout. So above all my print logs will be inpython_logs.txt
, and I follow along the logs usingtail -100f python_logs.txt
. And the-u
flag forces the print statements to be not bufferred while writing them topython_logs.txt
. Other wise even if your program is running you wont find the logs in the log file as soon as they get executed.Start a simple http server to serve static files temporarily. Change directory to the relevant directory and
python -m SimpleHTTPServer 8001
,8001
is the port number, You can now navigate tolocalhost:8001
to browse files.Use
%autoreload
while developing your jupyter notebooks and inside ipython, so that it will automatically reload changes of the imported modules and files. You don’t have to restart ipython and reimport everything again to see the changes reflected. You have to be careful though, use it only while developing. Type the below two lines in the ipython terminal.
1 2 3 |
|
- Use
?
to get function signature and function doc string, and??
to get function source inside ipython terminal and jupyter notebook.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
- Started using
conda
which made python dev much more saner. No more issues withsix
package in OSX while installing a new package, and other common dependency related issues while installing packages.
1 2 |
|
Bitbar
A utility that helps you write osx menu bar applications, and also use lots of community built plugins/menu bar applications.
brew install bitbar
Community Plugins:
Timezone plugin, shows time in 4-5 major timezones.
Clipboard plugin, clipboard of the last 10 items copied, click on an item to copy it back to clipboard.
My Plugins:
EC2 Plugin
My own ec2 bitbar plugin, that makes all my common EC2 tasks one click, and so much easier to do.
- I can start, stop, restart, teminate my running machines from the menu bar
- Create a low cpu alarm, that sends me an alert email when the cpu is lower than 20%. This is what I use mostly cause I want to get an alert when my machine learning scripts are die/finish.
- Delete the above created alarm.
- Copy ssh command to the clipboard with the right private key file just by a single click. It so annoying everytime I start a machine in ec2, I have to copy the public ip/dns and type where the private key is and type
ubuntu@
. All of this is just single click away now. - Displays various machine types, their cores, memory, normal prices, current spot prices in all the regions I’m interested in.
- Lists all the available AMIs, and launch a spot instance from that AMI
KEYS plugin
By clicking on the above words, the respective thing will be copied to clipboard.
Server setup is to setup my vim/github settings to any new server that I start. which basically copies wget https://github.com/syllogismos/dotfiles/raw/master/server_setup.sh
into clipboard. and sh server_setup.sh
will update my server vimrc and gitconfig files.
git
- add this alias in your
~/.gitconfig
under[alias]
, so that you can dogit hist
that shows pretty tree version of git commit history. This is very useful for my sanity, while rebasing, merging pull requests and etc. This forces me to keep my commit tree sane.hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
vim
You can find my vimrc here
My favourite things in default vim are and find myself using them again and again.
- visual block, this is the feature I miss the most when I use any other editor like say vscode or any other.
Ctrl+Shift+v
- recording, macro recording.
qa
to start recording your operations in thea
register, and end the recording by typingq
again. And repeat those operations by doing@a
. I didqa
for clarity of whats happening, but for speediness, I doqq
to record inq
register. And then end recording withq
. And repeat with@q
. You can also use@@
to just repeat the previous macro operation. .
a simple dot. it just repeats previous insert operation. Its so valuable and it surprises several times. Especially while programming, where things often repeat.
Most used vimrc
settings.
set number
line numberset relativenumber
shows lines numbers relative to the current lineset scrolloff=3
while scrolling all the way down or all the way up it gives you 3 lines of context instead of the default. It starts scrolling when you reach the last 3 lines instead of the bottom.inoremap jk <esc>
andinoremap kj <esc>
escape key is soo far away.. and I just typejk
orkj
quickly to get to normal mode from insert mode.inoremap ,, <C-p>
intellisense of sorts by doing,,
quick completions but only works for the words that already came earlier.noremap <Space> :w<Esc>
space bar to save the file in normal modenoremap <buffer> <silent> k gk
andnoremap <buffer> <silent> j gj
when lines are wrapped around the width and a single line takes up more than one line, normally you have to typegk
to go down but its annoying so bindingk
togk
makes things easier.
Sample video with various vim commands that I use often. like macros, visual block and etc.