Friday, August 9, 2019

Git Rebase Tutorial: Going Back in Time with Git Rebase

Thursday, August 1, 2019

Instructions for the C++ Torch installation modified for the Mac

https://github.com/intel/mkl-dnn/releases
https://github.com/intel/mkl-dnn

https://intel.github.io/mkl-dnn/dev_guide_build.html

Linux/macOS

  • Generate makefile: 
    mkdir -p build && cd build && cmake ..
  • Build the library: 
    make -j
  • Build the documentation: 
    make doc
  • Install the library, headers, and documentation: 
    make install
git clone https://github.com/intel/mkl-dnn.git
cd mkl-dnn/
mkdir -p build && cd build && cmake ..
make -j
make doc
make install

Validate the Build

Run unit tests:
ctest


// add this env var to your .bash_profile file

export Torch_DIR=$USER/libtorch

// HACK ALERT
// https://github.com/pytorch/pytorch/issues/14727#issuecomment-516575929

wget https://github.com/intel/mkl-dnn/releases/download/v0.20-rc/mklml_mac_2019.0.5.20190502.tgz
mv ~/Downloads//mklml_mac_2019.0.5.20190502.tar .
tar xvf mklml_mac_2019.0.5.20190502.tar


wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-macos-latest.zip
unzip libtorch-macos-latest.zip 
cd build/
source ~/.bash_profile
cd ..
mv first_example.cc first_example.cpp
cd build

cmake -DCMAKE_PREFIX_PATH=~/libtorch ..

~/torch/build
○ → ./first_example 
 0.9762  0.1762  0.9328
 0.5004  0.3410  0.1637
 0.3285  0.0761  0.6350
[ Variable[CPUFloatType]{3,3} ]
 0.9762  0.1762  0.9328
 0.5004  0.3410  0.1637
 0.3285  0.0761  0.6350

[ Variable[CPUFloatType]{3,3} ]



https://github.com/zdevito/ATen/tree/master/aten/src



Friday, April 19, 2019

VP Trees

https://en.wikipedia.org/wiki/Triangle_inequality


https://en.wikipedia.org/wiki/Triangle_inequality



VP trees: A data structure for finding stuff fast

http://ceur-ws.org/Vol-256/submission_12.pdf

https://nullwords.wordpress.com/2013/03/13/the-bk-tree-a-data-structure-for-spell-checking/

http://stevehanov.ca/blog/?id=130

https://fribbels.github.io/vptree/writeup

https://towardsdatascience.com/symspell-vs-bk-tree-100x-faster-fuzzy-string-search-spell-checking-c4f10d80a078

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.36.7401&rep=rep1&type=pdf



2. Metric Spaces and Similarity Queries
queries.
In this section, we briefly give the definitions for metric distance functions and different types of similarity
A metric distance function d(x,y) for a metric space is defined as follows:
i) d(x,y) = d(y,x)ii) 0 < d(x,y) < ∞, x≠ yiii) d(x,x) = 0iv) d(x,y) ≤ d(x,z) + d(z,y) (triangle inequality)
The above conditions are the only ones we can assume when designing an index structure based on distances between objects in a metric space. Note that, for a metric space, no geometric information can be utilized unlike the case for a Euclidean space. Thus, we only have a set of objects from a metric space, and a distance function d() that can be used to compute the distance between any two objects.
Similarity based queries can be posed in a number of ways. The most common one asks for all data objects that are within some specified distance from a given query object. These queries require retrieval of near neighborsof the query object. The formal definition for this type of queries is as follows:
Near Neighbor Query: From a given set of data objects X = {X1, X2, ..., Xn} from a metric space with a metric distance function d(), retrieve all data objects that are within distance r of a given query point Y. The resulting set will be { Xi | Xi ∈ X and d(Xi,Y)≤ r }. Here, r is generally referred to as the similarity measure, or the tolerance factor.
Some variations of the near neighbor query are also possible. The nearest neighbor query asks for the closest object to a given query object. Similarly, k closest objects may be requested as well.

http://blog.notdot.net/2007/4/Damn-Cool-Algorithms-Part-1-BK-Trees

https://karczmarczuk.users.greyc.fr/TEACH/TAL/Doc/BK_search/shasha_best.pdf

Burkhard and Keller in 1973, in their paper "Some approaches to best match file searching" pdf.



Wednesday, March 27, 2019

How to install OpenCV 3.4.0 on Ubuntu 16.04

How to install OpenCV 3.4.0 on Ubuntu 16.04

Install OpenCV 3.4.0 on Ubuntu 16.04 for all versions of python (2.7, 3.5 and 3.6)

OpenCV is a most popular free and open-source computer vision library among students, researchers, and developers alike. It has  C, C++, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS, and Android. At the time of writing of this blog, the latest version of OpenCV is 3.4.0. This tutorial is designed to help you install OpenCV 3.4.0 on Ubuntu 16.04. This tutorial works for versions 2.7, 3.5 and 3.6 of python. If you want to know how to install python 3.6 on Ubuntu, check out our other tutorial Install Python 3.6 on Ubuntu.
You can install opencv by using official prebuilt pip package or build from source.

To install from official pip package:

Use following commands in a new active empty virtual environment.
To install Opencv Only:
pip install opencv-python
To add contrib package in opencv:
pip install opencv-contrib-python

To install opencv by building from source:

OpenCV can be used in python as C++ python binding. I am going to explain how to build OpenCV from source and generate python binding.
The steps needed to be taken in order to install OpenCV 3.4.0 are:
  1. Update and Upgrade and Cleanup (Required for error-free installation)
  2. Install Dependencies
  3. Download and Build OpenCV

Update and Upgrade and Cleanup (Required for error-free installation)

sudo apt-get update
sudo apt-get upgrade
Now that we have the updates ready, we are ready to install dependencies.

Install Dependencies

sudo apt-get install build-essential 
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
The following command is needed to process images:
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
To process videos:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
For GUI:
sudo apt-get install libgtk-3-dev
For optimization:
sudo apt-get install libatlas-base-dev gfortran pylint
To build OpenCV binding for both python 2 and 3.
sudo apt-get install python2.7-dev python3.5-dev
We are now ready to download and build OpenCV on our Ubuntu machine.

Download and Build OpenCV

To Download OpenCV 3.4.0, go to terminal and type:
wget https://github.com/opencv/opencv/archive/3.4.0.zip -O opencv-3.4.0.zip
To Download OpenCV Contrib 3.4.0 (Contrib has very useful algorithms which is a must for anyone working on Computer Vision), go to terminal and type:
wget https://github.com/opencv/opencv_contrib/archive/3.4.0.zip -O opencv_contrib-3.4.0.zip
We need to unzip to extract the zip files. Install unzip if not installed using the command:
sudo apt-get install unzip
Now extract OpenCV and OpenCV Contrib:
unzip opencv-3.4.0.zip
unzip opencv_contrib-3.4.0.zip
Make a directory named build inside OpenCV-3.4.0:
cd  opencv-3.4.0
mkdir build
cd build
Now we are going to configure cmake:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.0/modules -DOPENCV_ENABLE_NONFREE=True ..
The command will take some time to execute. Wait for few seconds.
If the configuration is done without error, we will use make command to build.
make -j4 (where 4 is number of cores)
This command will take a few minutes to complete. On my PC, it took about 20 minutes.
Install in the location /usr/local using command
sudo make install
Reinitialize static libs using the following command
sudo ldconfig
Check if the OpenCV file exists
  • python2
“/usr/local/lib/python2.7/dist-packages/cv2.so”
  • python3.5
“/usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-x86_64-linux-gnu.so”
  • python3.6
“/usr/local/lib/python3.6/dist-packages/cv2.cpython-36m-x86_64-linux-gnu.so”
To use OpenCV 3.4.0 in virtual environment like virtualenv, conda or any other, copy related .so file in your virtual environment python directory
“lib/site-packages/”
Finally, check OpenCV version. Go to the terminal and typepython
On the python terminal, type
import cv2
cv2.__version__
If you ran into any problem while installing OpenCV or have any query related to OpenCV then feel free to comment below. I will try my best to solve it.

Thursday, February 21, 2019

git rebasing

git fetch origin
git rebase -i origin/master
git push --force-with-lease

Monday, February 18, 2019

Ubuntu tips

Hold down the control key to see the Ubuntu Unity keyboard shortcuts

Install Unity tweak tool to customize your Unity desktop env
sudo apt-get install unity-tweak-tool gnome-tweak-tool
unity-tweak-tool

Set the location and visibility of the dock




cslc compilation

On Ubuntu 
 1. install Boost
Download boost
https://www.boost.org/doc/libs/1_62_0/more/getting_started/unix-variants.html

https://codeyarns.com/2017/01/24/how-to-build-boost-on-linux/


 
 undefined reference to `intToString[abi:cxx11](int)'

 https://stackoverflow.com/questions/39826917/boost-build-fails-c11-feature-checks-when-using-custom-gcc-4-x-or-5-x?noredirect=1&lq=1

https://docs.computecanada.ca/wiki/GCC_C%2B%2B_Dual_ABI


https://stackoverflow.com/questions/39826917/boost-build-fails-c11-feature-checks-when-using-custom-gcc-4-x-or-5-x?noredirect=1&lq=1


$ echo "using gcc : 5.4 : /usr/bin/g++-5 : -std=c++11 ;" > ./tools/build/src/user-config.jam



Let's assume for the sake of this example that:
  • You want to build Boost with GCC 5.4
  • The g++ 5.4 binary is at /some/where/g++-5.4
  • You've downloaded the Boost sources and unpacked them into /path/to/sources/of/boost-1.62.0/
  • (Perhaps) you want to install Boost to /dest/path
  • You have N cores (so you want to parallelize the build N-ways)
Now:./b2 install --prefix=--prefix=/opt/local
  1. cd /path/to/sources/of/boost-1.62.0/
  2. Booststrap the build system by running ./bootstrap.sh
  3. echo "using gcc : 5.4 : /usr/bin/g++-5 : -std=c++11 ;" > ./tools/build/src/user-config.jam
  4. ./b2 --prefix=--prefix=/opt/local --toolset=gcc-5 -j 4 define=_GLIBCXX_USE_CXX11_ABI=0
  5. ./b2 --prefix=--prefix=/opt/local --toolset=gcc-5 -j 4 (N being the number of cores on your system)
  6. ./b2 install --prefix=/opt/local
  7.  
  8.  
  9.  ./b2 --prefix=--prefix=/opt/local --toolset=gcc-5 -j 4 define=_GLIBCXX_USE_CXX11_ABI=0

wget https://www-eu.apache.org/dist//xerces/c/KEYS
gpg --import < KEYS
wget https://www-eu.apache.org/dist//xerces/c/3/sources/xerces-c-3.2.2.tar.gz

// Compare the following sha256 to https://www-eu.apache.org/dist//xerces/c/3/sources/xerces-c-3.2.2.tar.gz

sha256sum xerces-c-3.2.2.tar.gz
dd6191f8aa256d3b4686b64b0544eea2b450d98b4254996ffdfe630e0c610413  xerces-c-3.2.2.tar.gz

cd xerces...

./configure
make
sudo make install
$ ls /usr/local/lib/
libxerces-c-3.2.so*  libxerces-c.la*  pkgconfig/  python3.5/
libxerces-c.a         libxerces-c.so@  python2.7/



ELK Stack

Tuesday, February 12, 2019

Thursday, December 13, 2018

From: https://jekyllrb.com/docs/usage/

Command Line Usage
The Jekyll gem makes a jekyll executable available to you in your terminal.
You can use this command in a number of ways:
• jekyll new - Creates a new Jekyll site with default gem-based theme
• jekyll new --blank - Creates a new blank Jekyll site scaffold
• jekyll build or jekyll b - Performs a one off build your site to ./_site (by default)
• jekyll serve or jekyll s - Builds your site any time a source file changes and serves it locally
• jekyll doctor - Outputs any deprecation or configuration issues
• jekyll new-theme - Creates a new Jekyll theme scaffold
• jekyll clean - Removes the generated site and metadata file
• jekyll help - Shows help, optionally for a given subcommand, e.g. jekyll help build
Typically you’ll use jekyll serve while developing locally and jekyll build when you need to generate the site for production.
To change Jekyll’s default build behavior have a look through the configuration options.

Configure Atom for Jekyll

https://atom.io/packages/jekyll

  • The Build Command will most likely need changing due to some weirdness with $PATH in Atom.
    • Go into the packages settings (Settings -> Packages -> Jekyll).
    • Change Build Command to /path/to/jekyll, build.
    • You can get your /path/to/jekyll by using which jekyll in your terminal.
Test on the Mac with shift-option-T
Test on a Windows machine with shift-alt-T

Wednesday, November 28, 2018

Github pages, Atom, and Jekyll

https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/

https://atom.io/packages/jekyll

https://jekyll.github.io/jekyll-seo-tag/

Start Atom

Install the necessary packages



Start and stop the server with shift-option-t on MacOSX



If you run into the above error then do the following:

https://github.com/jekyll/jekyll/issues/4268

Add this to the _config.yml




Grepping for non-ascii-chars

https://stackoverflow.com/questions/3001177/how-do-i-grep-for-all-non-ascii-characters#comment18815407_9395552

  • @BastiaanVanDeWeerd is correct, grep on OSX 10.8 no longer supports PCRE ("Perl-compatible regular expressions") as Darwin now uses BSD grep instead of GNU grep. An alternative to installing the dupeslibrary is to install pcre instead: brew install pcre... as part of this, you will get the pcregreputility, which you can use as follows: pcregrep --color='auto' -n "[\x80-\xFF]" file.xml – pvandenberk Dec 4 '12 at 11:24 

Sunday, November 25, 2018

How to upgrade OpenSSL (macOS) using HomeBrew

https://medium.com/@katopz/how-to-upgrade-openssl-8d005554401

brew remove openssl
brew install openssl
ls -l /usr/local/opt/openssl

MacOSX Ruby installation, GitHub.io and Jekyll

Under construction. Do not use.

Ruby installation on MacOSX is not clean...these are the steps I had to take to get it to work. There are all sorts of paths in packages such as Anaconda which conflict with the paths to packages installed by Brew which are required for the installation of Ruby. Thanks to the GitHub, stack overflow, and superuser posts I was able to install Ruby in the end.

$ xcode-select --install

https://github.com/rbenv/ruby-build/wiki#updating-ruby-build

Check the installation

https://github.com/rbenv/rbenv-installer#rbenv-doctor

gem pristine gem-wrappers --version 1.4.0
rbenv install 2.5.1

https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/

gem install bundler

brew install rbenv
  echo $PATH
add eval "$(rbenv init -)" to ~/.bash_profile or what ever your startup script is
  source ~/.bash_profile
  which ruby-build
 3705  ls "$(rbenv root)"/plugins
 3706  ls "$(rbenv root)"/
 3707  rbenv init
 3708  eval "$(rbenv init -)"
 3709  curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
 3710  brew upgrade rbenv ruby-build
 3711  rbenv install -l
 3712  gem pristine gem-wrappers --version 1.4.0
 3713  rbenv install 2.5.1
 3715  cd .github.io/
 3716  gem install bundler

 3719  more Gemfile
 3720  bundle install

==============================================

brew uninstall perl
brew install perl
brew link --force openssl
brew link --force gettext
brew install gpg2
$ curl -sSL https://rvm.io/mpapis.asc | gpg --import -
gpg: key 3804BB82D39DC0E3: 47 signatures not checked due to missing keys
gpg: key 3804BB82D39DC0E3: public key "Michal Papis (RVM signing) " imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg: no ultimately trusted keys found

 \curl -sSL https://get.rvm.io | bash -s stable --autolibs=enabled

eval "$(rbenv init -)

add to ~/.bash_profile 
export PATH="/usr/local/opt/openssl/bin:$PATH"
  1. brew unlink openssl
  2. brew uninstall --ignore-dependencies openssl
  3. Repeat number 2 until all deps are gone
  4. brew install openssl
  5. Follow post install instructions:
If you need to have this software first in your PATH run:
      echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc


        For compilers to find this software you may need to set:
              LDFLAGS:  -L/usr/local/opt/openssl/lib
                CPPFLAGS: -I/usr/local/opt/openssl/include
              For pkg-config to find this software you may need to set:
                    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

                $ export LDFLAGS=" -L/usr/local/opt/openssl/lib"
                $ export CPPFLAGS="-I/usr/local/opt/openssl/include"
                $ export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"


                https://www.codementor.io/akabiru/3-steps-set-up-ruby-environment-macos-6mavm7jrl

                $ brew install ruby

                brew install ruby

                $ curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
                Checking for `rbenv' in PATH: /usr/local/bin/rbenv
                Checking for rbenv shims in PATH: OK
                Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20181019)
                Counting installed Ruby versions: none
                  There aren't any Ruby versions installed under `/Users/depappas/.rbenv/versions'.
                  You can install Ruby versions like so: rbenv install 2.2.4
                Checking RubyGems settings: OK
                Auditing installed plugins: OK

                 rbenv install 2.3.1
                /usr/local/bin/ruby-build: /usr/local/bin/shasum: /usr/local/opt/perl/bin/perl: bad interpreter: No such file or directory
                ruby-build: use openssl from homebrew
                Downloading ruby-2.3.1.tar.bz2...
                -> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2
                Installing ruby-2.3.1...
                ruby-build: use readline from homebrew

                BUILD FAILED (OS X 10.13.6 using ruby-build 20181019)

                Inspect or clean up the working tree at /var/folders/wx/88s0zlc92wvd9hczwkly7qqh0000gp/T/ruby-build.20181125184727.32663
                Results logged to /var/folders/wx/88s0zlc92wvd9hczwkly7qqh0000gp/T/ruby-build.20181125184727.32663.log

                Last 10 log lines:
                checking for long long... yes
                checking for off_t... yes
                checking char bit... 8
                checking size of int... 0
                checking size of short... 0
                checking size of long... 0
                checking size of long long... configure: error: in `/var/folders/wx/88s0zlc92wvd9hczwkly7qqh0000gp/T/ruby-build.20181125184727.32663/ruby-2.3.1':
                configure: error: cannot compute sizeof (long long)
                See `config.log' for more details
                make: *** No targets specified and no makefile found.  Stop.

                https://github.com/rbenv/rbenv/issues/1059

                https://superuser.com/questions/1296016/rvm-error-running-configure

                "I faced the same issue after migrating my Mac too (both MacOS High Sierra).  After running"
                $ sudo mv /usr/local/include /usr/local/include_old
                "and then"
                $ rvm install 2.5.0 --with-openssl-dir=/usr/local/opt/openssl/bin/openssl


                More ruby build solutions:
                https://github.com/rbenv/ruby-build/wiki#updating-ruby-build


                https://medium.com/@vovakuzmenkov/get-a-website-with-github-pages-9151ed636446

                https://jekyllrb.com/docs/installation/macos/

                ================================================

                Some of the problems I ran into. Solutions above.

                https://gist.github.com/DirtyF/5d2bde5c682101b7b5d90708ad333bf3

                ==> Installing rbenv dependency: ruby-build
                Error: An exception occurred within a child process:
                  RuntimeError: /usr/local/opt/openssl not present or broken
                Please reinstall openssl. Sorry :(

                $ brew remove openssl
                $ brew install openssl
                $ ls -l /usr/local/opt/openssl

                https://gist.githubusercontent.com/DirtyF/5d2bde5c682101b7b5d90708ad333bf3/raw/fbc736fa1b50bd637929a315e6803df306c8bc8e/setup-rbenv.sh

                You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory #938

                https://github.com/rbenv/rbenv-installer#rbenv-doctor


                https://github.com/rbenv/rbenv/issues/938

                "I'm not sure I installed rbenv and a ruby version correctly"
                Yep, sure it can be tricky.
                1. sudo xcode-select --install
                2. Install rbenv with brew install rbenv
                3. Add eval "$(rbenv init -)" to the end of ~/.zshrc or ~/.bash_profile
                4. Install a ruby version rbenv install 2.3.0
                5. Select a ruby version by rbenv rbenv global 2.3.0
                6. Open a new terminal window
                7. Verify that the right gem folder is being used with gem env home (should report something in your user folder not system wide)
                "I want to use bundler and rbenv together"
                Perfect match!
                1. Make sure you installed rbenv correctly ☝️
                2. Select a ruby version locally for the folder you are located in e.g. rbenv local 2.3.0 (this creates a file called .ruby-version in the directory)
                3. Verify that the right gem folder is being used with gem env home (should report something in your user folder not system wide)
                4. Run gem install bundler
                5. Run bundle install
                6. Run on of your favorite gems defined in the Gemfile by bundle exec ... e.g. bundle exec fastlane


                set -ex
                brew update
                brew install rbenv ruby-build
                rbenv install 2.5.3
                rbenv global 2.5.3
                ruby -v
                gem install jekyll bundler
                rbenv rehash
                
                if ! type rbenv | grep function; then
                  echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
                fi
                
                set +x
                echo "Done! Close and reopen your terminal"


                https://help.github.com/articles/setting-up-your-github-pages-site-locally-with-jekyll/

                https://help.github.com/articles/using-jekyll-as-a-static-site-generator-with-github-pages/


                Wednesday, May 2, 2018

                Python dbg

                import pdb
                pdb.set_trace()

                Emacs ELPY config

                Create a virtualenv with the ELPY dependencies

                mkvirtualenv -p python3 kafka

                workon kafka pip install flask kafka opencv-python

                For an ELPY Emacs init.el see


                Start Emacs

                 M-x elpy-config

                Read the instructions in the ELPY config window about which Python packages to install using your virtualenv.

                 Install the Jedi server M-x jedi:install-server

                Updated ELPY emacs installation and general emacs config


                mkvirtualenv -p /Users//anaconda3/bin/python3 elpy pip install rope_py3k rope jedi flake8 ~/.emacs.init.el ;; global variables (setq inhibit-startup-screen t create-lockfiles nil make-backup-files nil column-number-mode t scroll-error-top-bottom t show-paren-delay 0.5 use-package-always-ensure t sentence-end-double-space nil) ;; buffer local variables (setq-default indent-tabs-mode nil tab-width 2 c-basic-offset 2) ;; modes (electric-indent-mode 0) ;; global keybindings (global-unset-key (kbd "C-z")) ;; load key bindings (load "~/.emacs.d/key-bindings.el") ;; the package manager (require 'package) (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") ("org" . "http://orgmode.org/elpa/") ;("melpa" . "http://melpa.org/packages/") ("melpa-stable" . "http://stable.melpa.org/packages/")) package-archive-priorities '(("melpa-stable" . 1))) (package-initialize) (when (not package-archive-contents) (package-refresh-contents) (package-install 'use-package)) (require 'use-package) (use-package scala-mode :interpreter ("scala" . scala-mode)) (unless (package-installed-p 'virtualenvwrapper) (package-refresh-contents) (package-install 'virtualenvwrapper)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Google Protobuf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (unless (package-installed-p 'protobuf-mode) (package-refresh-contents) (package-install 'protobuf-mode)) (use-package protobuf-mode :ensure protobuf-mode :interpreter ("protobuf" . protobuf-mode)) (defconst my-protobuf-style '((c-basic-offset . 2) (indent-tabs-mode . nil))) (add-hook 'protobuf-mode-hook (lambda () (c-add-style "my-style" my-protobuf-style t))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; For SBT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-to-list 'exec-path "/usr/local/bin") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Scala ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (unless (package-installed-p 'scala-mode) (package-refresh-contents) (package-install 'scala-mode)) (use-package scala-mode :interpreter ("scala" . scala-mode)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Ensime ;; http://ensime.github.io/editors/emacs/install/ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;(unless (package-installed-p 'ensime) ;(package-refresh-contents) (package-install 'ensime)) (use-package ensime :ensure t :pin melpa-stable) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Install Theme ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (use-package dracula-theme :ensure t :pin melpa-stable) (load-theme 'dracula t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Packages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar myPackages '(better-defaults elpy jedi flycheck material-theme py-autopep8)) ;; add the autopep8 package ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Install packages ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (mapc #'(lambda (package) (unless (package-installed-p package) (package-install package))) myPackages) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Elpy ;; https://github.com/jorgenschaefer/elpy/wiki/Configuration ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (unless (package-installed-p 'elpy) (package-refresh-contents) (package-install 'elpy)) (use-package elpy :interpreter ("elpy" . elpy)) (when (require 'elpy nil t) (elpy-enable)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Elpy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Python side ;; For syntax checking, you need the flake8 tool: ;; ;; pip install flake8 ;; For auto-completion features you need to decide on whether you want to use 'rope' or 'jedi', and install either one: ;; (installation of jedi is preferred based on this issue) ;; ;; pip install jedi ;; or if you are using Python 2.x and have reasons to prefer rope ;; ;; pip install rope ;; If you are using Python 3 and want to use Rope, install the rope_py3k package, not rope. ;; ;; pip install rope_py3k ;; ;; mkvirtualenv -p /Users//anaconda3/bin/python3 elpy ;; workon elpy ;; pip install rope_py3k rope jedi flake8 (package-initialize) (elpy-enable) (setq elpy-rpc-backend "jedi") (setq gud-pdb-command-name "python -m pdb") ;; M-x pdb ;; http://programmingmatrix.blogspot.com/2017/09/emacs-installing-jedi.html (require 'pyvenv) (pyvenv-activate "~/python_venv/elpy/") (venv-initialize-interactive-shells) ;; if you want interactive shell support (venv-initialize-eshell) ;; if you want eshell support ;; note that setting `venv-location` is not necessary if you ;; use the default location (`~/.virtualenvs`), or if the ;; the environment variable `WORKON_HOME` points to the right place (setq venv-location "~/python_venv") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; elpy Company code completion ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq company-minimum-prefix-length 1) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Python ;; minimal example to setup Jedi.el via package.el + MELPA: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Standard package.el + MELPA setup ;; (See also: https://github.com/milkypostman/melpa#usage) (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) (package-initialize) ;; Standard Jedi.el setting (add-hook 'python-mode-hook 'jedi:setup) (setq jedi:complete-on-dot t) ;; Type: ;; M-x package-install RET jedi RET ;; M-x jedi:install-server RET ;; Then open Python file. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Flycheck - Python syntax checking ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (when (require 'flycheck nil t) (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)) (add-hook 'elpy-mode-hook 'flycheck-mode)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; PEP8 - Python Lint ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'py-autopep8) (add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Python settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;(add-hook 'python-mode-hook ;; (lambda () ;; (setq-default indent-tabs-mode t) ;; (setq-default tab-width 2) ;; (setq-default py-indent-tabs-mode t) ;; (add-to-list 'write-file-functions 'delete-trailing-whitespace))) (eval-after-load "python" `(progn (add-hook 'python-mode-hook #'(lambda () (setq tab-width 2) (setq python-indent-offset 2) (setq python-indent-guess-indent-offset nil))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (require 'command-log-mode) ;; (add-hook 'LaTeX-mode-hook 'command-log-mode) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ctags ;; Run "M-x create-tags" to create the TAGS file ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq path-to-ctags "/usr/bin/ctags") (setq tags-table-list '("")) (defun create-tags (dir-name) "Create tags file." (interactive "DDirectory: ") (shell-command (format "%s -f TAGS -e -R %s" path-to-ctags (directory-file-name dir-name))) ) ;;(setq tags-file-name "") (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Custom ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages (quote (exec-path-from-shell exec-path-from-shell-initialize virtualenvwrapper command-log-mode jedi-direx protobuf-mode ensime scala-mode use-package)))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) (put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; exec-path-from-shell-initialize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (use-package exec-path-from-shell :ensure t :pin melpa-stable) ;; https://github.com/purcell/exec-path-from-shell (when (memq window-system '(mac ns x)) (exec-path-from-shell-initialize))

                Mac OSX virtualenv instructions

                http://roundhere.net/journal/virtualenv-ubuntu-12-10/ Install pip sudo apt-get install python-pip Install virtualenv sudo pip install virtualenv Create a dir to store your virtualenvs (I use ~/.virtualenvs) mkdir ~/.virtualenvs At this point you are all set to use virtualenv with the standard commands. However, I prefer to use the extra commands included in virtualenvwrapper. Lets set that up. Install virtualenvwrapper sudo pip install virtualenvwrapper Set WORKON_HOME to your virtualenv dir export WORKON_HOME=~/.virtualenvs Add virtualenvwrapper.sh to .bashrc ○ → which virtualenvwrapper.sh /Users//anaconda3/bin/virtualenvwrapper.sh Add this line to the end of ~/.bashrc so that the virtualenvwrapper commands are loaded. . /Users//anaconda3/bin/virtualenvwrapper.sh Exit and re-open your shell, or reload .bashrc with the command . .bashrc and you’re ready to go. Create a new virtualenv mkvirtualenv myawesomeproject to exit your new virtualenv, use deactivate. Switch between enviornments with workon To load or switch between virtualenvs, use the workon command: workon myawesomeproject You can read more about virtualenv here and virtualenvwrapper here. You might also want to look at this very similar (and probably better) python guide post.