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:
#
# $ ./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=($SERVER1, $SERVER2, $SERVER3 "anotheruser@$SERVER3")
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