-
Writing for the sake of writing
This is my first article out of what I hope will be many. I started this blog in 2012 and Iāve never written a single biased entry: just dry technical manuals, tutorials, and guides. This has lead to a number of page views from programmers in distress, but getting a certain amount of views was never the goal of this blog. To be honest, I am not even sure if I had a goal in mind. Everyone had a blog, and I thought so should I. I was hoping it will assist me in getting a job I will enjoy by increasing my online presence (and it may have). Maybe I was out for some online reputation and (knowing myself) fame. Of course, none of this happened.
What did happen, is that I created a collection of technical notes which no one cares about until they have a problem with something they are working on. And after the issue is resolved they close the page and never open it again, as one would do with a countless number of other programming blogs and tutorial collections.
Where am I leading with this?
Lately I have been (multiple times) hit with realization that software engineering is less about writing perfect (or any, for that matter) code, and is more about management and people skills. The very people skills most software engineers lack due to choice of profession (or maybe the other way). I spent some years reading books and articles on how to optimize, refactor, and design code for which any programmer would be praised and renowned for. I have even made some progress in reaching this āmagic goalā.
Donāt get me wrong, writing readable and reusable programs is an essential part of the job, but it is only one scale on which a professional programmerās performance is measured. And itās a relatively small scale, in comparison to others.
As a professional, you have your skill of assessing priorities, productivity, time management, patience, an active learning process, and of course, the above mentioned communication skills. This post is about just that: transmitting ideas and concepts to readers.
I am not very good at human interaction. I am an introvert. Even worse, and as many of my colleagues do, I mumble something or smile awkwardly when passing someone in a hallway. What is the social protocol for such an event anyway? Whatever it is, I donāt think I am doing it right.
Itās hard to evaluate my verbal communication skills. Maybe people have hard time understanding the points I am trying to bring across in conversation. Being a foreigner, some people probably find it challenging to understand every word I say. In addition, with my tendency to slur words when I am tired or excited - itās probably annoying to talk to me sometimes.
I can say with confidence that my writing skills suck. I spend by far more time than I should composing emails. I write a paragraph and then I delete it. Writing is a big challenge for me. I am quite sure this article is very hard to read. And I have a very strong feeling no one will read this article. Except for maybe, my wife - who is a fantastic writer and will point out every mistake Iāve made. This text will have to be revised many times before it becomes even slightly readable.
I started looking around for ways to improve the way I communicate my thoughts. I found a large number of articles, rules, and techniques which supposedly should instantly make you a better writer. This of course might be true if you are a professional writer or a student majoring in literature. I am neither. I stumbled upon a great article by Jeff Atwood: āHow to write without writingā. Reading it gave me the push I needed to get over the embarrassment of the inevitable failure from writing poorly. And I know I am writing poorly, Iāve read the stuff I wrote.
You donāt expect yourself to wake up one day and write awesome code, do you? No, you wake up, go to work, fail, and maybe after months and years of practice you become better at putting together pieces of code. The same rule applies to writing. Write a lot and often, and read what smart people write. Try to be even better than them. Fail. Repeat.
This is why I am starting to write less technical entries. Abstract topics will let me hone my writing skills. All I have to do is just stick to some sort of a writing schedule. Iāll come up with things to write about, I am a pretty loud person.
P.S: My recently acquired touch typing skills have come in handy in composing this. I would have previously never had the patience to finish the wall of text I am looking at right now. Go learn to type faster.
-
Python: "ignored" context manager
There was a recent fantastic addition to Python 3.4 by Raymond Hettinger:
contextlib.ignored. Itās a context manager which lets you shorten the following often-occurring pattern:try: os.remove('i_probably_do_not_exist.txt') except OSError: passAnd turn it into this:
with ignored(OSError): os.remove('i_probably_do_not_exist')Much shorted and prettier. But, as probably most of engineers, you have to use older version of python in production. Thatās where this little chunk of code comes in. Create a little
compat(as in ācompatibilityā) library and add following function:import contextlib @contextlib.contextmanager def ignored(*exceptions): try: yield except exceptions: passBeautiful!
UPDATE: As Andy pointed out in comments, this context manager has been renamed to
contextlib.suppress(https://bugs.python.org/issue19266). -
Elegant Mutt setup for use with Gmail
I have been using Mutt for a while now. Wouldnāt say that it saves my time, but nor does it extend the amount of time I spend reading email. For me, the best part about Mutt is that it lets me use text editor of my choice - Vim. Everything else - keyboard shortcuts, minimalist design, and simplicity - already exists in Gmail.
I found configuration below to work really well for my needs: all of the important for me Gmail features are translated. Hereās my
.muttrcfile:bind editor <space> noop set alias_file = '~/.mutt/aliases.txt' set copy = no set display_filter = '$HOME/.mutt/aliases.sh' set edit_headers set editor = "vim +/^$ ++1" set folder = "imaps://imap.gmail.com/" set hostname = "gmail.com" set imap_check_subscribed set imap_pass = "$PASSWORD" set imap_user = "$USERNAME" set mail_check = 5 set move = no set postponed = "+[Gmail]/Drafts" set spoolfile = "+INBOX" set text_flowed = yes unset imap_passive unset record # Gmail-style keyboard shortcuts macro index ga "<change-folder>=[Gmail]/All Mail<enter>" "Go to all mail" macro index gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts" macro index gi "<change-folder>=INBOX<enter>" "Go to inbox" macro index gs "<change-folder>=[Gmail]/Starred<enter>" "Go to starred messages" macro index gt "<change-folder>=[Gmail]/Trash<enter>" "Go to trash" macro index,pager d "<save-message>=[Gmail]/Trash<enter><enter>" "Trash" macro index,pager y "<save-message>=[Gmail]/All Mail<enter><enter>" "Archive" source $alias_fileIt is quite self-explanatory, and includes such nice features as:
- Automatically adding addresses from read emails to address book (see below).
- Using vim as a text editor, with an ability to edit message headers/recipients from within vim.
- Ability to access all the default Gmail folders: All mail, Drafts, Inbox, Starred, Trash.
- Key bindings to delete and archive messages bound to
dandyrespectfully (I am a huge fun of a zero-mail inbox).
You might also want to have your password encrypted by GPG as opposed to leaving it in plain text in your
.muttrcfile. You can read how to do this here: Using Mutt with GPG.As you may have noticed,
.muttrcabove setsdisplay_filterto$HOME/.mutt/aliases.sh. This script is being executed every time you read an email, and it collects email address to$HOME/.mutt/aliases.txt. Contents of thealiases.share below:#!/bin/sh MESSAGE=$(cat) NEWALIAS=$(echo "${MESSAGE}" | grep ^"From: " | sed s/[\,\"\']//g | awk '{$1=""; if (NF == 3) {print "alias" $0;} else if (NF == 2) {print "alias" $0 $0;} else if (NF > 3) {print "alias", tolower($(NF-1))"-"tolower($2) $0;}}') if grep -Fxq "$NEWALIAS" $HOME/.mutt/aliases.txt; then : else echo "$NEWALIAS" >> $HOME/.mutt/aliases.txt fi echo "${MESSAGE}"Source: W. Caleb McDaniel.
This script will create
aliases.txtfile containing email addresses for search and auto completion of email-addresses. -
Using Mutt with GPG
Mutt is a great command line email client, but it does not offer a built-in way to store passwords. But thatās where GPG comes in. A while back I wrote an article on how to use GPG to store your passwords: GPG Usage, this is a more practical note about using GPG to store your passwords for mutt. This note implies that you already have installed and configured GPG (which you can learn how to do in above linked article).
First you will have to record a password to a GPG file. Replace
$PASSWORDwith your password and$ACCOUNTwith a desired account alias. You probably want to prefix this command with a space, to avoid writing your password to a history file.echo '$PASSWORD' | gpg --use-agent -e > ~/.passwd/$ACCOUNT.gpgNext, open your
~/.muttrcfile and add following line:set imap_pass = "`gpg --use-agent --quiet --batch -d ~/.passwd/$ACCOUNT.gpg`"Again, replace
$ACCOUNTwith the same account alias you specified earlier. Now you donāt have to re-enter your password every time you start Mutt. -
Navigate files easily with ctrlp.vim
Few years ago I used a lightweight IDE called āSublime Text 2ā. And one of the most compelling features of it was an ability to switch between files by hitting
Ctrl+Pand typing in a part of the file name.This is exactly what
ctrlp.vimimplements in vim. Usage is extremely simple: install the plugin, hitCtrl+P, type a part of the file name, select a desired file and hitEnter. You can use arrow keys orCtrl+JandCtrlKto navigate between suggested file list.
Source: https://github.com/kien/ctrlp.vim.