xsel and you

As a technology worker, I live in  web-based ticketing systems. As such, you generally get some data, such as a command or list of hosts, you need to work with in a shell.

For may years my work flow was:

  1. highlight whatever it is in the ticket
  2. Crtl-C
  3. switch over to my terminal
  4. open a txt file
  5. Shft-Ctrl-V
  6. save file
  7. parse file.

This is where xsel shines.  xsel is a wonderful tool for storing and retrieving data on the command line.

For example:

# xsel -b

is used for pasting AND copying to the system clipboard. This allows you to things like

# xsel -b | awk '{print $1}' |xsel -b

on a column of hostnames and, say, their description you Ctrl-C from a ticket.

Cooler still, in Ubuntu, you can eliminate the Crtl-C part and just manipulate what you’ve highlighting with bare ‘xsel’.

There are a few tools for manipulating clipboards for different OSes. xsel and xclip and prominent in the Linux space. I believe pbcopy/pbpaste are for OSX.

 

Sleep data graphs

I’ve been using the Sleep as Android app to track my sleep for a little while now.  The application allows exporting to CSV files. I thought, “GREAT! I can bash in some, well, BASH and put this in Graphite“. You know to look at it in relation to other things I’m tracking and wastes of time like that.

I cracked open the CSV and immediately noticed it was REALLY whacky. Okay, well, not whacky, just not what I expected. I was expecting a row of data descriptions with a day’s values per row. This was going to take more work than I anticipated.

I took a spin around the Googles to see if I could borrow someone else’s work. I found this gentleman had done the parsing of the CSV file already. Unfortunately for me, it was in Ruby, which I don’t know. (LIES!)

I hacked together some Python and, after some playing around with the data (and reading the above website), I found it was was three rows per day. The first row has some static data and variables which are the descriptions for the next two rows of data. The variables in the first row are the times it captures data points at. The second row had the data I wanted which was a value low (deep sleep) to high (light sleep).

A little more Python hackery and I produced Graphite friendly output.  The python script is available over here.

I was thinking of adding in the ability to put this directly into Graphite, but my mind was starting to wander at this point. Perhaps another day.