If it won't be simple, it simply won't be. [Hire me, source code] by Miki Tebeka, CEO, 353Solutions

Tuesday, March 29, 2016

Slap a --help on it

Sometimes we write "one off" scripts to deal with certain task. However most often than not these scripts live more than just the one time. This is very common in ops related code that for some reason people don't apply the regular coding standards to.

It really upsets me when I try to see what a script is doing, run it with --help flag and it happily deletes the database while I wait :) It's so easy to add help support in the command line. In Python we do it with argparse, and we role our own in bash. Both cases it's extra 3 lines of code.

from argparse import ArgumentParser
parser = ArgumentParser(description='Does something')
parser.parse_args()
view raw script.py hosted with ❤ by GitHub
case $1 in
-h | --help ) printf "usage: %s\n\nDoes something" $(basename $0);;
esac
view raw script.sh hosted with ❤ by GitHub
Please be kind to future self and add --help support to your scripts.

Friday, March 11, 2016

vfetch - Fetch Go Vendor Depedencies

Go 1.6 now supports vendoring. I found myself cloning dependencies to "vendor" directory, then cloning their dependencies ... This got old really fast so vfetch was born. It's a quick and dirty solution, uses "go get" with a temporary GOPATH to get the package and its dependencies, then uses rsync to copy them to the vendor directory.

Installing is the usual "go get github.com/tebeka/vfetch" then you can use "vfetch github.com/gorilla/mux".

Comment, ideas and pull requests are more than welcomed.

Tuesday, March 08, 2016

Super Simple nvim UI

I've been playing with neovim lately, enjoying it and a leaner RC file. nvim comes currently only in terminal mode and I wanted a way to spin a new window for it. Here's a super simple script (I call it e) to start a new xfce4-terminal window with nvim.
#!/usr/bin/env python
"""Run nvim in new terminal window"""
from subprocess import Popen
from sys import argv
cmd = [
'xfce4-terminal',
'-T', 'nvim',
'-e', ' '.join(['nvim'] + argv[1:])
]
Popen(cmd)
view raw e.py hosted with ❤ by GitHub

Blog Archive