Search This Blog

Loading...

Sunday, September 25, 2016

Synchronizing vim environment accros multiple machines

Although I primarily use Sublime Text, some time ago I decided to become proficient in Vim, to improve my productivity when working gon remote machines.

Over time I've customized my vim environment. Every time I use a different machine, I need to setup the environment to my liking. While not terribly hard, the problem is that as a keep working on several remote machines and customizing my vim environment, the machines environments get out of sync. I put together this little bash script to keep things in sync across all machines I regularly work with.

#!/usr/bin/env bash
# Synchronizes this computer's vim environment to remote boxes
#
# Usage:
#
# $ ./vimsync.sh [BOXES]
#
# If BOXES is not specified, the default list will be used (see
# implementation a couple of lines below)
# BOXES is a space separated list of BOXES of the form
# [user1@]BOXNAME1 [user2@]BOXNAME2 ...

## boxes to sync to
if [[ $# -eq 0 ]]; then
  declare -a boxes=($RADGPU1 $RADGPU2 $DEVG1 $DEVG3 $DEVG4 "radshazam@$MACMINI")
else
  declare -a boxes=($@)
fi

echo $boxes

## files to synchronize
declare -a files=(".vimrc" ".vim/colors/cheerfully_dark.vim" ".gitconfig")

## directories to create
declare -a directories=("~/.vim/colors")

## sexyness
BALCK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
GRAY='\033[0;37m'
NC='\033[0m' # No Color


## now loop through the above arrays
for box in "${boxes[@]}"
do

  # need -e to allow backslash escapes
  echo -e "${CYAN}[Syncing to ${box}]${NC}"

  # create required directories
  for dir in "${directories[@]}"
  do
    cmd="ssh ${box} test -d ${dir} || mkdir -p ${dir}"
    echo -e "> ${GRAY}${cmd}${NC}"
    $cmd
  done

  # clone Vundle.vim if necessary
  cmd="ssh ${box} test -d ~/.vim/bundle/Vundle.vim || git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim"
  echo -e "> ${GRAY}${cmd}${NC}"
  $cmd

  # sync files
  for file in "${files[@]}"
  do
    #cmd="scp $HOME/$file ${box}:/home/jorge.herrera/$file"
    cmd="rsync -avzhe ssh $HOME/$file ${box}:~/$file"
    echo -e "> ${GRAY}${cmd}${NC}"
    $cmd
    #echo "done"
  done

  # need -e to allow backslash escapes
  echo -e "${GREEN}[Done with ${box}]${NC}"

done

The env variables $SERVER1, $SERVER2, $SERVER3 are defined elsewhere (e.g. in my ~/.bash_profile).

Thursday, January 21, 2016

Logging in Python

All you need to know about logging in Python: HERE!

Wednesday, December 16, 2015

OS X service for sublime text

Want to open a file/folder in Sublime Text from finder (or some other app)? OS X services to the rescue. I followed the instruction in this forum post and now I can open any file/folder in Sublime with a single button click. Ok, that's cool. But you know what's cooler? Keyboard shortcuts! You can add shortcuts to any service (e.g. the one you just created) in System Preferences -> Keyboard -> Shortcuts. Look inside the Services -> Files and Folder. Just click on it and add your preferred shortcut. Neat, right?

Tuesday, April 28, 2015

iPython notebook server via SSH tunnel

On the host:
$ screen
$ cd vEnv3/
$ source bin/activate
[eEnv3]$ ipython notebook --no-browser --port=8000 --ip=0.0.0.0
(detach screen: ctrl-A ctrl-D)
on the local machine
$ autossh -M 20000 -N -L 9000:host:8000 [username@]host

Learning by playing

I randomly came across this awesome website. It looks really interesting, but I don't have the bandwidth right now to spend time plying with those ideas. In particular, this article looks pretty interesting for my super-secret font project ...

Wednesday, April 22, 2015

Python Package Development

Context

I'm developing a few Python packages, which are obviously under version control (personally hosted GIT repo in this case, but that's not relevant). Now, the package is in active development, but I usually work in different machines: my personal laptop and workstations at the lab. In the lab machines I don't have root access, so I work on a virtualenv, where I can install python packages using pip install.

How?

To facilitate the development in every machine I work on, this is the basic setup:
  1. Create a setup.py file in the repo, to use setuptools to install the package (this will also help you if you want to use PyPI later on to distribute your package)
  2. Clone the repo in every machine you will develop/use your package
  3. For every machine:
    1. activate the virtualenv
    2. cd into the cloned repo
    3. Type python setup.py develop

Wednesday, March 11, 2015