Search This Blog

Friday, August 31, 2018

CLI Improvements

Check this post for an improved CLI (command-line interface) experience.

Wednesday, May 2, 2018

Language precision

Just a quote I like while reading this:
... being precise about our language prevents our discourse from being ambiguous and our terms from becoming overloaded.

Wednesday, July 26, 2017

Nerdly proud

A nice-ish vimgolf solution I came up with.

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 set up 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:
# $ ./ [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=($SERVER1, $SERVER2, $SERVER3 "anotheruser@$SERVER3")
  declare -a boxes=($@)

echo $boxes

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

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

## sexyness
NC='\033[0m' # No Color

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

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

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

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

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

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


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=
(detach screen: ctrl-A ctrl-D)
on the local machine
$ autossh -M 20000 -N -L 9000:host:8000 [username@]host