No dots in cron scripts?

I added a little script to /etc/cron.daily, sayhello.sh, while I sorted out how to integrate my backup script (tresync) into the list of cron jobs run daily.

The odd thing is, the script never ran. I could run it as “sudo /etc/cron.daily/sayhello.sh“, but it didn’t run with the rest of the cron jobs.

Lo and behold, I found the answer, which is actually on the man page for run-parts:

If neither the –lsbsysinit option nor the –regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.

Which means: you cannot have a dot in the file name.

That seems quite counterintuitive, but perhaps there is a reason that I just don’t understand.

Printing the middle N lines of a file in Linux

While working on my “e” alias in my aforalias project, I want the show only the entries of zip files, that is, without the header and footer sections. The “e” alias also shows the entries sorted by name, unlike the behavior of “unzip -l“, which displays:

Archive:  gradle-1.12-all.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
<entries>
---------                     -------
102761855                     9503 files

Thus I wanted to print lines[3 .. lines.length – 3].

Lo and behold, there’s a way to do that with “head” and “tail”, as follows:

unzip -l $1 | tail -n +4 | head --lines=-2

tail -n +X” means “start printing at line X”, where 1 is the first line of the file (not 0).

And “head --lines=-X” means “print all but the last X lines”.

Not the most intuitive pair of commands in this context, but they can be quite helpful.

A for Alias

In Zsh (and other shells), aliases may be the most important feature for increased productivity.

A simple rule is this: the more often you run a command, the shorter it should be. I’ve written about this before, in Efficient Way to Improve Console Productivity.

I have a number of one-character aliases:

G='| glark'
H='| head'
L='| less'
M='| more'
S='| sort'
T='| tail'
a=alias
c=clear
h='history -5000'
l='ls -CF'
t=cat

I’ll write later about those nifty uppercase ones (and yes, there is the alias “a” for “alias”, but for now, I’ll just show them with examples:

alias G -g '^.='

That was the command that I ran to generate the list above. It expands to “alias | glark -g ‘^.='”.

find src -type d S

That finds all directories and pipes them to sort.

There are three “families” of commands that I run the most often:

  • diff – diff files
  • eye – look at/in files on the command line
  • find – list all files/directories matching a pattern
  • open – open files in editor, browser
  • search – look in files

So I have been writing one-character scripts/functions (in Bash) for each of the above, where the script understands context as well as the targets.

For example, “s pluralize” run from a directory that contains a “Rakefile” will expand to search (using glark) only for Ruby files.

e program.tar.gz” is the equivalent of “tar ztvf program.tar.gz“, and “e program.zip” lists the zip file, with entries sorted by name.

d dir1 dir2” runs a recursive diff on the directories, and “d path/to/file ../dir2” will diff “path/to/file” against “../dir2/path/to/file”, if the latter file exists. I do this to avoid the tedious repetition of comparing one code base to another (such as two branches, when merging them): “diff path/to/file1 ../dir2/path/to/file1“, “diff path/to/file2 ../dir2/path/to/file2“, etc.

Although this project is in its early stage, and the output is still rough (i.e., containing debugging output), it already has been quite useful, so I thought I would share.

The project is at Github here.

Life Organization: Recording

The eight categories can be great for organizing one’s life, and just as good for keeping a record and keeping one’s life in balance.

To review, the categories:

  • Physical
  • Professional
  • Social
  • Solitary (or Recreational, Hobbies)
  • Maintenance
  • Mental
  • Emotional
  • Financial

Keeping a daily record (journal, diary) can be an excellent feedback loop.

To do so, write out each of the categories and add to each section a description of the related activities for each. It can also be beneficial to simply record one’s overall self-assessment, as a number, thus quantifying the process.

The scale can be like that of the (US) school system, A, B, C, D, F, or a number from 1 to 3, or 1 to 5.

My preference is to use a modified 1 through 10 scale, where the lowest rating is actually a 6, meaning essentially no activity, and 10 is an absolutely perfect episode, perhaps when reaching a long-term goal. For some reason, it feels less “negative” to give something a rating of, say, 2, whereas 6 doesn’t seem so self-critical.

For example, a day of no exercise, bad diet, and poor sleep would be a 6 in the physical category. A day (night) of good sleep and a decent diet would be a 7 (or average). A moderate amount of exercise could bring that to an 8, and reaching a monthly goal (such as running a 10K) would be a 9. A life goal, such as running a marathon, would be a 10.

Similarly for the professional category: a complete day off, a 6. A moderate amount of work, a 7. A productive day: 8. Very productive day: 9. Starting one’s own company or being promoted: 10.

I actually have rated a category a 5 at times, for what is a counter-productive day, such as overeating with no positive physical efforts. But that is rare.

I prefer to write these in the morning, after my coffee and reading time, and before starting any other activities for the day. That is the time where I find that my mind is shifting from reflecting on the day before to gearing me up for the day ahead.

One of the best effects of this system is that knowing that the feedback loop exist can make a person “tip” from bad to good decisions. For example, if a day is winding down and the current level of their physical category is a 7, that person might decide to go for a walk or to forgo that second helping at dinner, in order to bring them up to an 8.

It comes down to the maxim: What gets measured gets managed.

Life Organization: The Eight Categories

This is a a system for organizing and assessing one’s life, that of eight categories. Since some people have asked me about them, I thought I would enumerate them here.

These categories can be used these to plan — days, weeks, months, and years — as well as to self-assess (“journal”) every day, keeping a record. The journaling/recording process will be described in a separate post.

Physical: sleep, diet, body data (weight, fat percentage, resting heart rate), medical and dental procedures, and of course, exercise.

Professional: formal work (9 to 5) and corollary activities, such as job- and career-related reading, blogs, pod casts, and tutorials.

Social: family and friends, including time spent face-to-face, phone calls, messaging, and email.

Solitary: activities and time not for social or professional reasons, done purely for oneself.

Maintenance: work on physical surroundings, such as home and car. This also includes organization of files and records, both physical and electronic.

Mental: reading and brain-developing exercises.

Emotional: activities (and lack thereof) to regain emotional balance, such as meditating, yoga, prayer and even music.

Financial: money, including tracking spending, paying bills and investing.

The categories are not intended to be unique. In fact, if activity can fall into multiple categories it can be considered to be efficient in terms of maximizing results for the effort (although it might also be diluting the results as well). The categories that overlap most often for me are solitary and mental. For example, since I am an avid Scrabble player I could classify that in either category, but I put it as solitary, generally keeping the mental category limited to reading. Likewise yoga could be either physical or emotional.

One of the main motivators for developing the categories was when I was concerned that my life was getting out of balance, leaning heavily toward professional, and this helps to keep a broader perspective.

The above categories can also be used for organizing in other aspects. For example, electronic documents could go into different directories (or folders), named for the above. So college transcripts would go into the professional directory, medical records in physical, appliance manuals in maintenance, tax documents in financial and e-books in mental.

Cost of Meet(ing)

I’ve long been frustrated that meetings are not quantified, where the cost of the meeting is calculated based on the wages of those in the meeting. With that data, it would be more obvious to determine that cost/benefit of the meeting.

Some back-of-the-envelope calculations here. For four people making an average salary of $100,000 (I’m using programmer gross salaries, including benefits and vacation), a 30-minute meeting would run $96. For twelve people for two hours: $769. Twenty people for two eight-hour days (for example, training): $15,385.

Since I’ve been trying to spin up my web skills I slapped together a site that acts a bit like a timer for a meeting. It’s built on Rails, yet uses little of the framework, other than some of the JavaScript libraries and routing.

Please check it out: costofmeet.org

Rails testing and Emacs mode line

I’ve been diving/digging into the oh-so-excellent Rails Tutorial, by Michael Hartl, and am into chapter 3, where testing begins.

Imagine my surprise — go ahead, imagine it — when my Emacs mode line changed color.

Originally:

modeline_original

And when I ran “bundle exec rake test”, it succeeded with:

modeline_success

Then changing the test code to fail, after running “bundle exec rake test” again:

modeline_failed

Tracking down this code, I found that the guard-notiffany gem was doing this behavior, sending a change to the Emacs mode line via emacsclient, with this bit of code in lib/notiffany/notifier/emacs.rb:

        def notify(color, bgcolor)
          elisp = <<-EOF.gsub(/\s+/, " ").strip
            (set-face-attribute 'mode-line nil
                 :background "#{bgcolor}"
                 :foreground "#{color}")
          EOF
          emacs_eval(elisp)
        end

The issue there was that it just changes the mode line “permanently”. I’d prefer that the mode line colors change for a moment, then time out and revert to their previous settings.

I wrote a bit of code to do this, and modified lib/notiffany/notifier/emacs.rb locally, but there is a pending pull request that has a better implementation.

However, my hack is:

        def notify(color, bgcolor)
          elisp  = "(let ((orig-bg (face-attribute 'mode-line :background))"
          elisp << "      (orig-fg (face-attribute 'mode-line :foreground)))"
          elisp << "     (set-face-attribute 'mode-line nil"
          elisp << "                         :background \"#{bgcolor}\""
          elisp << "                         :foreground \"#{color}\")"
          elisp << "     (sit-for 3)"
          elisp << "     (set-face-attribute 'mode-line nil"
          elisp << "                         :background orig-bg"
          elisp << "                         :foreground orig-fg))"
          emacs_eval(elisp)
        end

The sit-for keeps the mode line as red or green for 3 seconds or when there is Emacs input. I prefer that, to clear the mode line more quickly, since I find the bright color distracting.

RVM, Zsh and Konsole

Today I set up RVM with Zsh (Z shell) with Konsole (the KDE equivalent to gnome-terminal).

The RVM Konsole example shows it with bash, setting the “Command” field to “/bin/bash –login”. The line for Zsh is nearly the same: “/usr/bin/zsh –login”.

If you don’t have this, you’ll get the error:

% which ruby
/usr/bin/ruby
% rvm use 2.0

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.

Note that you’ll need to have RVM as the first component in the PATH (“echo $PATH”).

With the “Command” field set to “/usr/bin/zsh –login” (that’s “dash dash login”), when you start a new terminal you should get:

% which ruby
/home/jpace/.rvm/rubies/ruby-1.9.3-p551/bin/ruby
% rvm use 2.0
Using /home/jpace/.rvm/gems/ruby-2.0.0-p598
% which ruby
/home/jpace/.rvm/rubies/ruby-2.0.0-p598/bin/ruby

Silencing Konsole Notification

Applications in KDE can send notifications, which result in popups on the task bar:

popup

Highly annoying this is. The culprit is that control-shift-A is the shortcut to enabling this behavior, as is shown via “Konsole -> View -> Monitor for Activity”:

view_menu_cropped

It’s fortunate that this is easy to disable. Right click on “Monitor for Activity -> Configure Shortcut”, then click on “Ctrl+Shift+A”, which will then display “Input”. Click on the left arrow graphic:

shortcut

That should result in it showing “None”, which means that there will no longer be a shortcut. You might want to go back to “Konsole > View” and make sure that “Monitor for Activity” is not checked.

I seem to do this every time I set up KDE, so perhaps this will help others.

Adding Groovy Emacs Mode

I’ve been doing a lot of Gradle/Groovy work lately, and have been using Russel’s Groovy Emacs Mode.

That page provides the documentation for the case where you’re going to put all the *.el files into ~/.emacs.d. However, to keep things nice and organized I put third-party code into a vendor directory under ~/.emacs.d/lisp.

So for the Groovy mode, I added ~/.emacs.d/lisp/vendor/groovy-mode, extracted Russell’s tarball into that, and added these lines to my jep-groovy.el file:

;;; use groovy-mode when file ends in .groovy or has #!/bin/groovy at start
(add-to-list 'load-path "~/.emacs.d/lisp/vendor/groovy-mode")
(autoload 'groovy-mode "groovy-mode" "Major mode for editing Groovy code." t)
(add-to-list 'auto-mode-alist '("\.groovy$" . groovy-mode))
(add-to-list 'auto-mode-alist '("\.gradle$" . groovy-mode))
(add-to-list 'interpreter-mode-alist '("groovy" . groovy-mode))

;;; make Groovy mode electric by default.
(add-hook 'groovy-mode-hook
          '(lambda ()
             (require 'groovy-electric)
             (groovy-electric-mode)))