botbotbot 's blog

Tmux

list binding key

PREFIX ? - list keys

Leaving and Coming Back Again

PREFIX d - leave

# Come Back
$ tmux a

windows

PREFIX c - create window
PREFIX , - rename window
PREFIX n - next window
PREFIX p - previous window
PREFIX {num} - go to {num} window
PREFIX & - exit window

panes

PREFIX % - split pane in vertically
PREFIX “ - split pane in horizontally
PREFIX o - switch between panes
PREFIX {arrow} - move around the panes
PREFIX q - show pane number and its size
PREFIX x - kill pane
PREFIX z - toggle pane to be fullscreen
PREFIX {, } - swap panes
PREFIX ! - turn pane to window

Copy & Paste to System Clipboard

Copying between tmux buffers and the system clipboard
Share buffer with system clipboard
tmux Copy & Paste on OS X: A Better Future
Copy Mode - Linux TMUX Video Tutorial

# .tmux.conf
setw -g mode-keys vi
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection
bind -t vi-copy y copy-pipe 'xclip -in -selection clipboard'
  • Copy to Buffer

    1. PREFIX [ - scroll buffer use arrow key to move around and enter to quit
    2. v - select word
    3. y - copy (yank) word
  • Paste from buffer PREFIX ]

Create Custom Layout

#Window: python dev (Prefix - Meta(Alt) + d)
# -v = split horizontal
bind-key M-d split-window -v -p 30 -t 0 \; \
         send-keys './watchdog_python.py' 'Enter' \; \
         select-pane -t 0

tmuxinator

$ gem install tmuxinator
export EDITOR=vim

wemux

# OSX via Homebrew
$ brew install wemux

Unable to use ‘open’ command in OSX tmux

brew update
brew install reattach-to-user-namespace
echo "set -g default-command \"reattach-to-user-namespace -l ${SHELL}\"" >> ~/.tmux.conf

How to convert 2 horizontal panes to vertical panes in tmux?

Prefix + space

Reference:

  1. A tmux Tutorial and Primer
  2. love hate tmux
  3. Thoughtbot tmux
  4. screen and tmux
  5. screen to tmux: A Humble Quick-start Guide
  6. Tmux: A Simple Start
  7. Humans Present: tmux
  8. tmux tutorial
  9. Practical Tmux
  10. tmuxinator: Save tmux pane and window layouts
  11. Tmuxify your Tmux. Powerful session, window & pane management for Tmux.
  12. Beginner’s Guide to Tmux: Recommended Configuration, Plugins and Navigation Demo
  13. Tmux Plugin Manager - tmux-plugins

All about Python

Tips:

  • Flattened list of list

    >>> l = [[1,5,6], [4,5,9,7] ,[] ,[] ,[9]]
    [[1, 5, 6], [4, 5, 9, 7], [], [], [9]]
    >>> sum(l, [])
    [1, 5, 6, 4, 5, 9, 7, 9]
    >>> [i for x in l for i in x if type(x) is list]
    [1, 5, 6, 4, 5, 9, 7, 9]
    
  • Else with for loop

    >> for i, v in enumerate(range(10)):
    >>   print i,
    >> else:
    >>   print 10
    1 2 3 4 5 6 7 8 9 10
    
  • Zen of Python :: run this command in python console

    import this
    
  • Virtualenv with system package

     virtualenv --system-site-packages <env_name>
    
  • Virtualenv with python3

    virtualenv --python=$(which python3) <env_name>
    
  • Virtualenv can’t move. You must edit environment path in

    <your_env>/bin/activate
    <your_env>/bin/activate.csh
    <your_env>/bin/activate.finsh
    
  • Install py package into python2

    pip install <package>
    
  • Install py package into python3

    pip3 install <package>
    
  • Pip upgrade

    pip install <package> --upgrade
    

    or you can use pip-tool to review all pip-package to upgrade

    pip install pip-tools
    pip-review
    pip-dump
    
  • Install Project as develop via pip

    # same as 'python setup.py develope'
    pip install --use-mirrors --editable .
    
  • Print without newline or spaces

    import sys
    
    for i in xrange(0,10):
        sys.stdout.write(".")
        sys.stdout.flush()
    
  • How to execute a file within the python interpreter?

>>> execfile('filename.py')
import X
reload( X )
$ pip install --download-cache="/pth/to/downloaded/files" package

Tools:

# install
$ pip install --upgrade autopep8
# usage
$ autopep8 --in-place --aggressive --aggressive <filename>
# install
$ pip install pylint
$ apt-get install graphviz

# usage
pyreverse -o png <code>

Python Project

  1. What are good open source projects in Python to contribute to and start learning Python?
  2. OpenHatch find project to contribute
  3. Ask HN: Good Python codebases to read?

Idiomatic Python:

  1. Be Pythonic
  2. What is Pythonic?
  3. Python track: python idioms
  4. Code Like a Pythonista: Idiomatic Python
  5. PEP8
  6. The Hitchhiker’s Guide to Python!
  7. Index of Python Enhancement Proposals
  8. 30 Python Language Features and Tricks You May Not Know About
  9. Transforming code into Beautiful, Idiomatic Python by Raymond Hettinger
  10. Python Tips, Tricks, and Hacks
  11. Writing Idiomatic Python
  12. Python 3 Patterns, Recipes and Idioms
  13. Decorators: A Powerful Weapon in Your Python Arsenal
  14. Anti-Patterns in Python Programming
  15. Best python tricks and one-liners
  16. Python Tips and Traps
  17. Python: faster way Tricks for your code run faster
  18. The Little Book of Python Anti-Patterns

Tutorial Python

  1. Python Koans
  2. New Coder Python
  3. Problem Solving with Algorithms and Data Structures Python
  4. Everyday Python Project
  5. Python Regular Expressions
  6. Python Practice Book

Functional Programming in Python

  1. O’Reilly Functional Programming in Python
  2. FUNCTIONAL PROGRAMMING WITH PYTHON by BY ALEXEY KACHAYEV, 2012
  3. Functional Programming HOWTO

Design Patterns Python:

  1. Python Patterns
  2. Six GoF design patterns, Python style
  3. Generic adapter class in Python
  4. Bridge Patterns Python
  5. Python Best Practice Patterns by Vladimir Keleshev
  6. Python SOLID
  7. The Clean Architecture in Python
  8. Stop Writing Classes

Optimization Python

  1. 10 Ways to Make Python Go Faster
  2. Speeding Up Your Python Code
  3. PythonSpeed
  4. How to Make Python Faster Without Trying That Much

Python Debugger (pdb)

  1. Getting started with the Python Debugger pdb
  2. Python Debugging Techniques
  3. Debugging in Python
  4. Getting Started with the Python Debugger
  5. pdb – Interactive Debugger
  6. Tutorial: Debugging your Python Applications with pdb(Youtube)
  7. Introduction to PDB(Youtube)
  8. setting breakpoints with nosetests –pdb option

Logging

  1. Become a logging expert in 30 minutes(Youtube)

Framework

  1. Awesome Python

Python Tutorial

  1. Must-watch videos about Python
  2. pyvideo.org

Python Testing

ETC.

  1. Terminating a Python script
  2. Should I put #! (shebang) in Python scripts, and what form should it take?
  3. Simple file server to serve current directory
  4. How to reload python module imported using “from module import *”
  5. 10 awesome features of Python that you can’t use because you refuse to upgrade to Python 3
  6. From C++ to Python (1) - ไทย
  7. From C++ to Python (2) - ไทย