Jason Meridth's Blog Learn, Converse, Share

Get Repository Root Path

I needed to find a way to get the path to the root of my Git repository. I found the answer in the following command:

git rev-parse --show-toplevel

Example:

->$ git rev-parse --show-toplevel
/Users/jmeridth/dev/jmeridth.github.io

Vim Tagbar Plugin

I found the tagbar Vim plugin last night and finally tried it out this morning. I like it. I mapped ,tb to showing it in my .vimrc.

One of the requirements is Exuberant Ctags. Since I’m on OSX I installed it with Homebrew:

brew install ctags

In a Python file it will group/fold all of your imports, classes, methods, etc in one view. It is very nice and when you press enter on one of them it takes you to that item in the current buffer.

Here are the screenshots from the github repo screenshots (C++ files):

screenshot 1

screenshot 2

I’m really liking it so far.

Information Shown After Logging Into Ubuntu

Afer you log into an ubuntu instance you’ll usually see something like this:

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-88-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Jul  1 21:17:15 UTC 2016

  System load:  0.0               Processes:           100
  Usage of /:   20.1% of 7.74GB   Users logged in:     0
  Memory usage: 28%               IP address for eth0: 172.30.0.115
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

7 packages can be updated.
7 updates are security updates.


Last login: Fri Jul  1 21:17:15 2016 from 1.2.3.4

I have logged into many ubuntu servers in my time and today I finally looked up how the information that displays gets generated and displayed. I’ve used /etc/motd aka message of the day many times before but I noticed tha file doesn’t exist in a vanilla Ubuntu install. There are two main commands that are populating the information shown at login.

For system information:

landscape-sysinfo

example output:

->$ landscape-sysinfo
  System load:  0.0               Processes:           99
  Usage of /:   20.1% of 7.74GB   Users logged in:     1
  Memory usage: 28%               IP address for eth0: 10.10.10.10
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

For packages status:

/usr/lib/update-notifier/update-motd-updates-available

example output:

->$ /usr/lib/update-notifier/update-motd-updates-available

7 packages can be updated.
7 updates are security updates.

Other People's Code

TL;DR We are all continually improving. Don’t forget that.

Recently I’ve been hearing more and more developers say stuff like “Wow, what was this person thinking when they wrote this?” or “Really? Sigh…..”. Don’t get me wrong. I’ve been guilty of this also. I am writing this post to remind myself and other developers that if you could, you would say those things to yourself of six months ago or even yesterday. We are all continually improving and we started writing bad, inexperienced code just like some of the code your reading now. I also saw someone say “Bad code doesn’t immediately become bad; it happens over time, gradually.” (thanks Sharon) That is true.

I like the quote:

    Write code as if the person who will maintain
    it is a psychopath and he/she knows where you live

I’ve also told developers recently that I read more code than I write. Yeah, maybe some of you just churn it out like you exhale but that isn’t me. That doesn’t mean I don’t produce, but I actually read code for fun. I am always reviewing code for work and side jobs, but I’m also reading open source library code for projects that I use or plan to use so that I can understand how they work and also to learn. Some people read books or newspaper articles. I read source code.

I am absolutely not passing judgment on anyone. There is a fine line between ignorance and lack of intelligence. Ignorance means the person is unaware/hasn’t been taught/etc. Lack of intelligence means that no matter how many times that person is taught they will never grasp the subject. This includes multiple ways of teaching the same subject matter. When you read those developer’s code, you will sigh. But…you should still add comments to their code and end it with something like “wdyt?” (wdyt == what do you think?). You present them with your perspective but aren’t forcing it on them. Maybe someday it will click. Maybe not. That’s not up to you. If they are destructive to the code, then that is a subject for another post. :)

How I Setup My Local Python Environment

I’ve had a few people ask me lately how I setup my local python environment.

I am using iterm2 (v3.0.0) on OSX. That means I am using homebrew and I installed wget and curl via brew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install wget
brew install curl

Install the python package manager pip

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

Install the virtualenvwrapper package. It lets you manage python virtual environments easier than just using virtualenv

sudo pip install virtualenvwrapper

Create working directory and project directory

export WORKSPACE=~/dev
export PROJ=$WORKSPACE/testproj1
mkdir-p $PROJ

cd $PROJ

Make virtual environment (aka isolated dependencies)

->$ mkvirtualenv testproj1

->$ pip install requests
Collecting requests
  Using cached requests-2.10.0-py2.py3-none-any.whl
  Installing collected packages: requests
  Successfully installed requests-2.10.0

Create file to test with:

vim test.py

inside test.py:

import requests

r = requests.get('https://jasonmeridth.com')
print r.status_code

get out of the file by pressing Esc on your keyboard then typing :wq

continuing:

python test.py

output should be:

200

Voila!!