Posts tagged "emacs":

21 May 2019

TLDR org mode + graphviz

Org mode is pretty cool. Directed graphs are pretty cool. Let's see how they go together.

Org mode

After installing the graphviz package, you will have the dot command. If you use it in with an org mode source block like so:

#+BEGIN_SRC dot :file ./dot-example.png  :cmdline -Kdot -Tpng
digraph {
    a -> b
}
#+END_SRC

You can eval the block with C-c C-c and then view it inline in emacs by using org-toggle-inline-images.

These blocks also export! Just like in this page itself!

dot-example.png

The Dot language

The dot language spec can be found here. I don't find that too helpful on it's own, so here are some notes:

Primitives that matter:

  • a node is a bubble/self contained item that will be connected.
  • an edge is the line that connect nodes.
  • a graph is a the relation as a whole.

A list of attributes that can be applied to these can be found here: https://www.graphviz.org/doc/info/attrs.html

Some nice node options can be seen here: https://www.graphviz.org/doc/info/shapes.html#polygon

Here is an example that shows how attributes are set and some defaults I like:

#+BEGIN_SRC dot :file ./dot-example.png  :cmdline -Kdot -Tpng
digraph {
    // config:
    // TBLR, top bottom left right, the direction of the graph.
    graph [rankdir=TB];
    // you can have multiple attrs per statement
    graph [dpi=150 splines=ortho];
    edge[decorate=true];
    node [shape=box];

    // definitions:
    // nb: setting definitions on their own is useful in larger graphs
    computer [label=computer];
    // quotes are optional, I'm using them when there are spaces
    phone [label="android phone"];
    router [label=router];

    // record syntax: | for horizontal, {|} for vert
    internet [shape=record label="{internet|cat pictures}"]

    // relations:
    computer -> router;
    phone -> router [label="wifi"];
    router -> internet [dir=both];
}
#+END_SRC
dot-internet.png
Tags: emacs
04 Apr 2018

restclient.el + elasticsearch

todo: and a screenshot of it in action

restclient.el is an emacs plugin that transforms a buffer into a repl-like curl-backed experience (similar to kibana). It has support for variables set with arbitrary elisp, turning it into a viable postman replacement (with plain text! and versioning!). I find this to be a very nice way to store and execute elasticsearch queries, but unfortunately you lose autocomplete of ES specific items. Alternatively, es-mode exists, which is more ES specific but much more featureful.

Here is a starter point showing some of restclients capabilities and how one might use it with elasticsearch:

;; -*- mode: restclient -*-

# local
:target = http://localhost:9200
:cloud-auth = ""
# Basic http auth example:
cloud-auth := (concat "Basic " (base64-encode-string "username:password"))
:prefix = some_prefix

# multiline variable
:headers = <<
content-type: application/json
Authorization: :cloud-auth
#

# note: there must be a comment to separate request definitions.

# list indices
GET :target/_cat/indices
:headers

# logs sorted by a field
GET :target/:prefix_log/_search
:headers
{
  "sort": [
    {
      "timestamp": {
	"order": "desc"
      }
    }
  ]
}
Tags: emacs
Other posts