Typically, you would use mysql client cli as follows, You could also create a ~/.my.cnf file to set default properties, including connection info, You could even store a password but I wouldn’t recommend storing it in the clear. Also, the above approach is not useful when you have more than one MySQL database across multiple hosts, […]

Using getattr in Python

I would like to execute a named function on a python object by variable name. For example, let’s say I’m reading in input that looks something like this: enqueue 1 enqueue 12 enqueue 5 enqueue 9 sort reverse dequeue print Afterwards, we should see: [9,5,1] Let’s say we need to implement a data structure that […]

bash histogram

I would like to generate a streamable histgram that runs in bash. Given an input stream of integers (from stdin or a file), I would like to transform each integer to that respective number of “#” up to the length of the terminal window; in other words, 5 would become “#####”, and so on. You […]

VLC remote control

Recently I was using VLC to listen to music, as I often do, and I wanted to pause without getting out of bed. Lazy? Yes! I learned that VLC includes a slew of remote control interfaces, including a built-in web interface as well as a raw socket interface. In VLC Advanced Preferences, go to “Interface”, […]

datsize, simple command line row and column count

Lately I’ve been working with lots of data files with fixed rows and columns, and have been finding myself doing the following a lot: Getting the row count of a file, twarnock@laptop:/var/data/ctm :) wc -l lda_out/final.gamma 3183 lda_out/final.gamma twarnock@laptop:/var/data/ctm :) wc -l lda_out/final.beta 200 lda_out/final.beta And getting the column count of the same files, twarnock@laptop:/var/data/ctm […]

Getting the most out of your ssh config

I typically find myself with voluminous bashrc files filled with aliases and functions for connecting to specific hosts via ssh. I would like an easier way to manage the various ssh hosts, ports, and keys. I typically maintain an ssh-agent across multiple hosts, as well as various tunnels; reverse tunnels, and chained tunnels — but […]

git, obliterate specific commits

I would like to obliterate a series of git commits between two points, we’ll call these the START and END commits. First, determine the SHA1 for the two commits, we’ll be forcefully deleting everything in between and preserving the END exactly as it is. Detach Head Detach head and move to END commit, git checkout […]

vim: Visual mode

I have been using vim for years and am consistently surprised at the amazing things it can do. Vim has been around longer than I have been writing code, and its predecessor (Vi) is as old as I am. Somehow through the years this editor has gained and continues to gain popularity. Originally, my interest […]

vim: tags and tabs

Previously, I discussed using vim and screen with automagic titles. The great part about working with vim and screen is that I can work from anywhere with minimal setup, and when working remotely I can pick up the cursor exactly where I left it — I never have to worry about a remote terminal disconnecting. […]

vim and screen, automagic titles

Previously, I discussed using multiuser screen so that I could concurrently access a shared screen session across multiple remote hosts (from work, from home, from my phone, etc). I would like to augment screen such that the titles would always tell me what directory I’m currently in, as well as what program is running (if […]

multiuser screen

Previously, I discussed using GNU screen as a window manager. I would like to access my screen session concurrently from multiple hosts (say, at work, at home, and even remotely on my phone). I would also like to define default screens specific to one host. Default screens can be configured easily in the .screenrc in […]

scripting Photoshop for stop motion

I would like a simple and quick way to save a copy of an image in Photoshop, with an auto-incrementing filename. Ideally, a single button to capture a frame in a stop motion animation. In other words, I would like to save a copy of the working image as a JPEG without any interactive prompts […]

locking and concurrency in python, part 2

Previously, I created a “MultiLock” class for managing locks and lockgroups across a shared file system. Now I want to create a simple command-line utility that uses this functionality. To start, we can create a simple runone() function that leverages MutliLock, e.g., def _runone(func, lockname, lockgroup, basedir, *args, **kwargs): ”’ run one, AND ONLY ONE, […]

zip archive in python

I would like to create zip archives within a python batch script. I would like to compress individual files or entire directories of files. You can use the built-in zipfile module, and create a ZipFile as you would a normal File object, e.g., >>> >>> foo = zipfile.ZipFile(‘’, mode=’w’) >>> foo.write(‘foo.txt’) >>> Unfortunately, by default […]

chaining ssh tunnels

Imagine you’re working within a private home network and need to connect to an Oracle database within a corporate network accessible only through a bastion host hidden within the corporate network. Odd as that sounds, it’s a typical network configuration, as follows: The layout is very simple, when you’re within the corporate network you must […]