Posts

Showing posts with the label mac os

Python: Install ansible with pip

Note that ansible can only be run on a machine with Python 2.6 or 2.7 Install ansible package using pip module: sudo pip install ansible Install required packages: sudo pip install paramiko PyYAML Jinja2 httplib2 six To install the latest development version: sudo pip install git+git://github.com/ansible/ansible.git@devel

Python: Creating Virtual Environments and Managing Packages

Creating the Virtual Environment Using virtualenv virtualenv [env_name] source [env_name]/bin/activate Using pyvenv (includes pip in the default packages) pyvenv [env_name] source [env_name]/bin/activate Managing Packages Install the latest version of package: pip install [package_name] Alternatively, you can use python -m to install a package using pip module: python -m [module_name] install [package_name] Install a specific version of a package pip install [package_name]==[version] If you would like to install the flask package with a minimum version, this is how to execute it: pip install flask>=0.10.1 Install packages just for the current user: pip install --user [package_name] Upgrade a package to the latest version: pip install --upgrade [package_name] Remove package(s) from the virtual environment: pip uninstall [package1] [package2] ... [package] Display information about a particular package: pip show [package] Display all the packages installed in...

Vagrant: Installing Vagrant

Download VirtualBox and Vagrant Create a directory for your virtual environment mkdir vagrant_env1 cd vagrant_env1 Install your preferred box (Ubuntu 12.04 LTS 64-bit for this example): vagrant init hashicorp/precise64 or vagrant init vagrant box add hashicorp/precise64 You may check this HashiCorp's Atlas box catalog for more type of boxes. By the way, a "box" is a base image of an operating system. This enables you to quickly clone a virtual machine rather than starting from scratch, which would be a slow and tedious process. Installing may take some time, but after that, you can re-use this box when you want to create another virtual environment. Now run vagrant up: vagrant up To enter the virtual machine, simply SSH: vagrant ssh

Python: Install pip on Mac OS X

Download get-pip.py Run the following command: sudo python get-pip.py Upgrading pip: pip install -U pip

Vim: Using Abbreviations

VIM abbreviations can save typing and/or improve typing accuracy. By using :ab or :abbreviate , you can define abbreviations in VIM editor or the .vimrc file. i.e. This command will automatically replace "cia" with "central intelligence agency" :ab cia central intelligence agency or :abbreviate cia central intelligence agency i.e. You can also shorten a line of code :ab ubb #! /usr/bin/bash The above code will replace ubb with #! /usr/bin/bash The following command will remove a specific abbreviation :una ubb or :unabbreviate ubb This command will remove all abbreviations defined :abc or :abclear

Bash: Caret Substitution

Sample command: echo "dev" && echo "my dev" Replace "dev" with "prod": ^dev^prod Previous command will now be this: echo "prod" && echo "my dev" To replace all occurences of "dev": ^dev^prod^:& Previous command will now be this: echo "prod" && echo "my prod"

Bash: Copy files by extension from sub-directories to another directory

Goal: Copy all image (*.png) files from all sub-directories of dir1 into single directory, dir2. Source: bash_examples/ dir1 - dir3 - f1.png - f2.png - f5.jpg - dir4 - f3.png - f4.png Destination: bash_examples/ dir2 - f1.png - f2.png - f3.png - f4.png 1. Change the directory to dir1 cd ~/Desktop/bash_examples/dir1/ 2. Find all files with .png extension then apply cp command to copy each file from dir1 to dir2 find . -name \*.png -exec cp -v '{}' "/Users/mac0611/Desktop/bash_examples/dir2" ";" ./dir3/f1.png -> /Users/mac0611/Desktop/bash_examples/dir2/f1.png ./dir3/f2.png -> /Users/mac0611/Desktop/bash_examples/dir2/f2.png ./dir4/f3.png -> /Users/mac0611/Desktop/bash_examples/dir2/f3.png ./dir4/f4.png -> /Users/mac0611/Desktop/bash_examples/dir2/f4.png cd ..; ls dir2/ f1.png f2.png f3.png f4.png

Bash: Calculate Date in Ubuntu and Mac OS

Display current date date +'%Y-%m-%d %H:%M' 2015-08-07 17:06 Add 3 mins, 5 days, 2 months, 4 years to current date (Mac OS) date -v +3M -v +5d -v +2m -v +4y +'%Y-%m-%d %H:%M' 2019-10-12 17:09 Add 3 mins, 5 days, 2 months, 4 years to current date (Ubuntu) date -d "3 minutes 5 days 2 months 4 years" +'%Y-%m-%d %H:%M' 2019-10-12 17:09