A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label graph. Show all posts
Showing posts with label graph. Show all posts

Easily create graphs from code

Use graphviz:

1) write graph code

digraph g{
  Opened[label="1\nOpened\nE: open door"];
  Closed[label="2\nClosed\nE: closed door"];
  node[shape=plaintext];

  Opened -> close_door[arrowhead=none];
  close_door -> Closed;
  Opened -> open_door[dir=back];
  open_door -> Closed[arrowhead=none];
}


2) generate graph

dot -Tjpg -ograph.jpg graph.dot

3) view graph


You can easily store the source code to the graph in version control.
Don't forget to also store the instructions to rebuild it.

Automatically diagram an SQL database

Use cases:
  • Designing a new schema from scratch, using a GUI
  • Automatically rendering a diagram of an existing SQL schema

2010:
  • The least worst option is MySQL Workbench. The GUI is poor: http://wb.mysql.com/
  • This one uses Javascript. No features, but it works: http://code.google.com/p/database-diagram/

Histogram with perl

perl -lane'($i) = $F[4] =~ m{(\d+)\.}; $m=100; $s=10; for ($c=0; $c<=$m; $c+=$s) { if (($i >= $c) && ($i < $c+$s)) { $h{$c}++; } };END{ for ($c=0; $c<=$m; $c+=$s) { print "$c : ".("#" x $h{$c}); }}'

$i = the value with which you want to make a histogram

$h = hashref holding the histogram data
$s = histogram step size
$m = maximum histogram value

$c = loop counter