Graphviz-dot Mode

When I want to draw structural directed graphs and network diagrams my first choice is always dot from the graphviz suite. The syntax is reasonably simple and the documentation has lots of examples to serve as go-bys.

The other day, Grant Rettke, whose blog you should definitely follow, had a post on configuring cask. That’s something I’ve been meaning to investigate so I was happy to see his post. But more interesting to me was the example he gave on configuring cask for graphviz-dot-mode, a mode for editing dot files.

If you like syntax highlighting—and who doesn’t—and write dot files, this package seems like a useful addition to your Emacs resources. Once again, Emacs shows that it can adapt to whatever task is at hand. Having syntax highlighting and formatting for dot files is probably not life changing but it does reduce friction a bit in your work flow. And that’s always a win.

Posted in General | Tagged | Leave a comment

Generating Graphs from an Org Mode File

I came across this tweet from Sacha Chua

and decided to take a look. I’m glad I did. The page is a detailed list of Chua’s goals. If you’re a Chua fan like me, the existence of such a page is not a surprise but why should we care? Aside from what we might learn from the goals themselves, the generation of the page has a lot to teach us.

One of the features of the page is a graph that maps her goals and how they relate to each other. What’s nice is that the graph is generated programmatically from the text on the page. That would involve a lot of work but for the fact that the page was generated from an Org source file. There are some interesting things about that file.

First is that, in the manner of reproducible research, everything to generate the page is included in the Org file including the Elisp code that generates the graphviz dot file for the graph, and the invocation of graphviz that produces the png for the graph.

The second interesting thing is her use of org-map-entries to iterate through the goals. This eliminates at lot of the parsing that she would otherwise have to do.

Finally, Chua came up with a nice trick to wrap the labels in the graph. To see the advantage of this, she includes an old copy of the graph, without the wrapping, at the end of page. In order to keep the nodes reasonably small, she wraps the longer lines into two or more lines by inserting the label string into a buffer with the appropriate fill-column value and calling fill-region.

If you’re interested in using Babel and Org-mode in a reproducible research manner, studying Chua’s code will pay dividends.

Posted in Programming | Tagged , | Leave a comment

Emacs + Org Mode + Python

Back in July of last year I wrote about a great SciPy 2013 talk by John Kitchin on using Emacs, Org Mode, and Python for reproducible research. Today, I came across a reference to the talk, rewatched it, and enjoyed it all over again.

If you’re involved in research or produce technical documents and haven’t seen this video, I urge you to give it a watch. It’s less than 22 minutes so it doesn’t demand a huge time commitment. If you’ve already watched it, you may, like me, enjoy seeing it again. I’m mentioning this again mostly for the benefit of those who might have missed it the first time.

Posted in General | Tagged , | Leave a comment

CSS By Example

Via Jean-Philippe Paradis, I came across this CSS tutorial by Xah Lee. It’s nice because the page shows several examples of CSS effects. When you click on an effect, it takes you to a short tutorial that discusses the effect and shows the code. The tutorials also have links to other documentation.

If you’re an expert CSS user, this probably won’t be as useful to you as it is to someone like me who only rarely writes CSS. I always have to look things up and before seeing this page wouldn’t have had any idea how to produce the effects or even how to find out efficiently.

If you don’t already know this stuff and sometimes produce Web pages—even if it’s with something like Org Mode—you should take a look at the page. I’ve bookmarked it in my Docs bookmark so I can find it easily the next time I need it.

Posted in Programming | Tagged , | Leave a comment

Reformatting JSON

A long time ago, I wrote about a way to prettify JSON. It had the advantage that it didn’t require you to load a heavyweight package such as js2-mode when all you wanted was to reformat some JSON in a reasonable way. The downside was that it called a Python module, json.tool, to do the work. That’s OK unless you don’t have Python installed or don’t want to shell out to an external process.

Now Wataru Miyaguni has an Elisp solution that doesn’t require you to shell out to an external process. The json-reformat package reformats JSON into a standard format. If, like me, you don’t write in JSON enough to justify use of one of the heavyweight JSON packages but nevertheless occasionally want to reformat JSON into a publishable format, this could be just what you need.

Posted in General | Tagged | Leave a comment

Metadata and You

I know it’s preaching to the choir and even to me it seems like the gazillionith time I’ve written about it but we really must convince our friends and neighbors that metadata isn’t some harmless bit of information that’s on our phone bills anyway. After all, if metadata really were harmless and unrevealing, the NSA wouldn’t be so eager to collect it, would they? A recent article in The Guardian describes a study which shows that sensitive data about your life is easily discerned by examining metadata.

The study’s participants installed an application on their phones that recorded who they called and the duration of the call. Given that these were all volunteers, there’s some self-selection bias here but you’d think people with something to hide wouldn’t be signing up (although one participant was pretty clearly growing pot, so maybe they would). Another person was found to be almost certainly suffering from Multiple Sclerosis and a third to have just discovered that she was pregnant.

There were calls to Alcohol Anonymous, NARAL, gun shops, divorce lawyers, STD clinics, and strip clubs. Notice that with the possible exception of the pot grower, none of these activities are illegal or even particularly exceptional. They are, however, private matters that most people wouldn’t care to have made public and that’s the point. We hear over and over that “if you’re not doing anything wrong you have nothing to fear.” This study shows just how wrong that is.

The Guardian article is useful to point at when you’re trying to educate your less security-savvy friends about the dangers of metadata.

Posted in General | Tagged | Leave a comment

An Org Mode Cookbook

As you all know, I’m always talking up Org Mode and encouraging people to try it out. Org is so flexible that I spend a large percentage of my Emacs time in it. Where others might use a spreadsheet, I just use an Org table with automatic column or row calculations. Where others use Word or some like spawn of the devil, I use Org Mode and export it to whatever form I need. Where others torture themselves by writing blog posts in WordPress’s built-in editor, I use Org Mode with all the power of Emacs and then automatically post it to the Irreal site with org2blog/wp.

All that capability comes with a downside, though. It’s hard to get started and learn what you can do. Like Emacs itself, it’s easy to be overwhelmed by sheer magnitude of what’s included in the box. Until now, the most useful sources of information were the Org Manual (of course), and Bernt Hansen’s Org Mode – Organize Your Life In Plain Text. Hansen’s article is particularly useful because it’s a (constantly updated) Org file that documents how he uses Org Mode along with examples that demonstrate the various aspects of Org. The examples serve as an excellent go-by for the new user. When I was first starting with Org, I’d find an example of what I was trying to do in his document and mimic what he did. If you’re an Org Mode user (new or not) you really should take a look at it.

Now Eric Neilsen has produced a document similar but complementary to Hansen’s. His Emacs org-mode examples and cookbook is like Hansen’s Organize Your Life In Plain Text in that it serves as a cookbook with recipes for performing various tasks in Org Mode. Although there is a bit of overlap, Neilsen concentrates on producing LaTeX documents and with interacting with Python and R. While Hansen’s document is (mostly) concerned with things a consultant might want to do, Neilsen’s is more oriented to the needs of a researcher. His guide will be especially useful to someone wanting to produce publishable papers—especially for papers produced using the reproducible research model.

Neilsen’s cookbook is an excellent addition to the must-have Org documentation. I’ve added it to my Docs bookmark in my browser. Take a few minutes to look it over and I’m sure you’ll want to do the same thing.

Posted in General | Tagged , | 3 Comments

Emacs Focus Hooks

Bozhidar Batsov continues his excellent series on the upcoming Emacs 24.4 release with a post about new hooks for when frames go in or out of focus. As Batsov explains, that allows you to easily save the current file or even all files when a frame goes out of focus.

As with some of the other enhancements in 24.4, you probably won’t be using this facility every day but it does, as Batsov says, move Emacs towards the goal of making everything possible from the user level.

Posted in General | Tagged | Leave a comment

Variadic Comparisons in Emacs Lisp

One of the ways that Emacs Lisp differs from other Lisps is that it doesn’t support multiple arguments for comparisons. That is, you can’t write things like

(if (= a b c) do-this else-do-that)

or

(when (< a b c) ...)

You can still express those comparisons, of course, but you have to connect two or more two-argument comparisons with and.

Now, as Bozhidar Batsov points out, that’s about to change. Emacs 24.4 will support variadic comparisons. That’s not a huge change but it does bring Elisp in line with other Lisps and makes it easier to express complex comparisons concisely and clearly. As I wrote before, I’m really impressed with this release and looking forward to its availability.

Posted in Programming | Tagged | 1 Comment

Cory Doctorow on the Politics of Copyright

Cory Doctorow appears in an interesting video where he discusses the politics of copyright and how our current policies just don’t make any sense. He repeatedly applies those policies to other areas where everyone can see how ridiculous they are. Somehow, though, as soon as we start talking about “media” people think it all makes sense.

The video is about 17 minutes long but well worth your time. Watching it made me angry at how stupidly we’re behaving and that no one can see that the purpose of copyright as currently applied is the preservation of the business models of a few large conglomerates. It’s shameful, really.

Posted in General | Tagged | 1 Comment