tmux: synchronize in all windows (not really)

A neat feature in tmux(1) is the :setw synchronize-panes option, which causes tmux to repeat in all panes the keys typed in the window. But if you’re not using panes and have a bunch of windows which you want to send the same keystrokes to you’re out of luck. Fortunately it’s easy to simulate a synchronize-windows option:


Quick’n’dirty ELB healthcheck

Sometimes you have a service you are running on multiple instances in an AWS autoscaling group, and you want to monitor the application health with ELB so that if an instance become unhealthy your autoscaling group will launch a new instance. But if the service doesn’t expose any ports, such as a web server would, ELB health-checks cannot work because they rely on connecting via TCP or HTTP to monitor the health of it’s instances. So? If you can check the health of your service with some local command or script then all you need is the files in this gist and you’re off!

The idea is to use (or abuse) systemd‘s socket activation feature to run a script whenever ELB asks for a certain URL on a certain port. Ideally this port should not be accessible from the public internet or really anywhere else than where ELB will be connecting from. But this is outside the scope of this document (you are running your instances in a VPC right?).

So, assuming /path/to/somecommand is a an executable that will succeed or fail depending on the health of your service, you need the following script to respond to ELB health checks:

Then you configure the status.socket and status@.service unit files (usually in /usr/lib/systemd/system/). And then prof.. ehm test it first!.

This is perhaps just a hack, but it works OK in many cases.

keeping your shell connected to an agent

One of the most annoying things about using an ssh-agent type process is making sure that the environment in your shell (either from an xterm, from an ssh session or embedded in another application) is always properly setup to connect to that process. Since I use gnupg’s gpg-agent, I wrote the following shell script (sourced in my ~/.shrc) to try and always do the right thing™:

send Graphite output to Slack

Just a quick recipe to send rendered graphs from Graphite to Slack, using your crontab(5) and Incoming Webhooks:

0  5  *  *  * /path/to/ >/dev/null

This will send a message to your webhook’s default channel every day at 5am, and Slack show you a preview of the graph in the channel. For completeness’ sake (!) here’s the contents of `/path/to/`:

PAYLOAD="payload={\"text\": \"<$GRAPH|daily metric graph>\"}"
curl -s --dump-header - -X POST --data-urlencode "$PAYLOAD" \

UPDATE: the initial version had a bug with single quotes which ought to have been double quotes. Thanks to GregTheRules for catching that.

vertical preview pane in gmail

I’m trying out this lab, perhaps late to the party but anyway. I kind of like it, especially the vertical split.

My 2 issues: I use the keyboard shortcuts j,k to view or select the next or previous message respectively. This works fine, although I would prefer that the cursor moved without actually opening the next or previous message. I could use the ‘o’ keyboard shortcut to actually view the message. The actual problem I have is that when the cursor goes below the end of the viewport the list of messages doesn’t scroll. Any one have any idea about a workaround?

(using google chrome)

Simple autoreload for wsgi python apps running in uWSGI

While developing, it’s usefull to have uwsgi autoreload your application. In my case I rsync changed files to the server running uWSGI. But uWSGI only monitors the app configuration file, which generally doesn’t change. In order to have your app auto-reload (like django does) you can switch to your app’s base directory and execute:

while true ; do
  find . -name \*.py                  \ # for python
         -newer /path/app.ini         \ # if changed
         -exec touch /path/app.ini \; \ # reload
         -print                         # print
  sleep 2

Everytime you rsync or scp some python file to the server the -newer predicate will turn true for this file and find will touch the configuration file (thereby making it newer than all the source files).

Spell check XML files without VIM syntax problems

I’ve been using XMLMind’s XML Editor lately to write some documentation in the Docbook XML format. The editor has very good support and I’m very glad to be using it. There’s one catch though, and it’s to do with the spell check support. XMLMind have implemented their own system for which there are no Greek dictionaries available. Not having the time to go and create one myself I looked at other solutions.

I have the Hunspell dictionaries on my system anyway but the command line program that comes with Hunspell garbles Greek characters in the terminal. I don’t know what that’s about and Google didn’t come up with any quick solutions. So my next try was using spell check support in VIM 7 and after a bit of trial and error I’m happy with the result. So here’s what I did:

  1. Download a Myspell compatible Greek dictionary word list and affix file, either the original one by Steve Stavropoulos or the one by Dimitrios Gianitsaros which combines the Greek words and English words as well as provides for Greek fully capitalized words with no accents.
  2. :mkspell el /path/to/hunspell/dictionaries/el_GR
  3. make sure the resulting .spl file gets copied to ~/.vim/spell
  4. create the file ~/.vim/after/syntax/xml.vim as described below.
  5. Open an XML file and execute :set spell spelllang=el,en or something to that effect.

One little problem with spell checking XML files in VIM is that the syntax highlighting interferes in a sub-optimal way. For example by default the text content of elements is not spell checked. Another example is that URL’s in href and xmlns attributes are reported as mistakes. These problems can be solved by the following syntax commands:

syn match xmlHref +href="[^"]*"+ contained contains=xmlAttrib,@NoSpell
syn match xmlXmlns +xmlns\(:[a-z]*\)\?="[^"]*"+ contained contains=xmlAttrib,@NoSpell
syn cluster xmlStartTagHook add=xmlHref
syn cluster xmlStartTagHook add=xmlXmlns
syn spell toplevel

Now you should be good to go with spell checking XML in VIM. Another little detail about my work-flow is that I have configured gvim as a helper application in XMLMind XML Editor and that permits me to type “Ctrl-Shift-D” while editing an XML file and get the file opened in VIM ready to be spell checked. After my corrections the file is reloaded in the XML editor.

sed memo: output boilerplate around each line in a file

Given three files xx0{0,1,2} the following sed script will first output the contents of file xx00 and then for each line in the input it will output xx01, the line and xx02. The substition on line 5 is optional and can be expanded to include more commands or removed completely.

1 r xx00
1 !r xx02
$ !r xx01
1 d

The filenames are the default output filenames of the csplit command which could be helpful in related scenarios to the above.

Also it would be easy to add a footer to the above script, but I did not need it personally at this time.

how to insert any unicode character over VNC

Been using GRNET’s ViMA service a lot lately and sometimes it happens while using a vm’s console via VNC that I need to input a unicode character in a file. The VNC viewer applet that is provided, as well as any vncviewer I’ve tried can’t seem to manage inputing these characters directly via the keyboard. Here’s how I do it:

  1. Install Vim on the vm with apt-get, yum or whatever

  2. Localy find the unicode codepoint of the desired character:

    echo "Ψ" | iconv -f utf-8 -t iso8859-1 --unicode-subst="<U+%04X>"

    In this case it prints <U+03A8>

  3. Open the file you want to input into on the vm with vim.
  4. In input mode, type Control-V, u, and the four hexadecimal digits (i.e. 0,3,A and 8)
  5. Viola!

a way to track office-suite documents with VCS?

Nice to hear Sofia‘s happy with dropbox as a solution for finding the latest version of her dissertation. I was thinking about what she could do if she had to track older or alternative versions of her dissertation, perhaps even offline, instead of only the latest version in Dropbox. Of course I thought of Mercurial which I use for my SCM needs. The problem with Mercurial is that it is good at working with text files, not binary files like those of popular office suites. So I searched a bit and found a possible solution (although I haven’t implemented and tested it yet):

David Heffelfinger posted about Document Version Control With Mercurial in which he writes about using the flat version of the ODT format. According to him this solution is not satisfactory because even in the flat format, a single letter change will change all sorts of metadata in other parts of the file. Due to this it’s hard to distinguish between the important changes between two versions and the inconsequential. Instead of going this way he is currently using the oodiff hack from the Mercurial website.

Obviously a hack would not be an acceptable solution for Sofia to adopt, except if she desperately needed the ability to track changes and could live with using OpenOffice instead of Word (or whatever she’s using). But a comment on David’s post refers to an interesting tool called Beyond Compare which seems to be able to generate differences both for Microsoft Office XML files and OpenOffice ODT files! They claim integration with popular DVCS‘s. I wonder how easy it would be to integrate Beyond Compare into say TortoiseHG. Has anyone done this? Maybe I will try it sometime soon.

Any other suggestions for tracking office suite documents with a DVCS?