|   | 1 | = Miscellaneous scripts. = | 
          
          
            |   | 2 | Here you can find various hacky scripts made for various purposes, that may or may not be useful.  | 
          
          
            |   | 3 |  | 
          
          
            |   | 4 | === gridmap === | 
          
          
            |   | 5 | A collection of functions that can be clobbered together into a mapping script. For example: | 
          
          
            |   | 6 | {{{ | 
          
          
            |   | 7 |     require "gridmap.rb" | 
          
          
            |   | 8 |  | 
          
          
            |   | 9 |     puts "enter node ID as \"x1,y1; x2,y2;...\"\n" | 
          
          
            |   | 10 |     puts "enter \"quit\" to exit\n" | 
          
          
            |   | 11 |  | 
          
          
            |   | 12 |     g = Grid.new | 
          
          
            |   | 13 |     nodes = nil | 
          
          
            |   | 14 |  | 
          
          
            |   | 15 |     while | 
          
          
            |   | 16 |         nodes = gets.chomp.split(';') | 
          
          
            |   | 17 |         break if nodes.first == "quit" | 
          
          
            |   | 18 |         nodes.each do |el| | 
          
          
            |   | 19 |             r,c = *(el.split(',')) | 
          
          
            |   | 20 |             p g.switch_of(r.to_i,c.to_i) | 
          
          
            |   | 21 |         end | 
          
          
            |   | 22 |     end | 
          
          
            |   | 23 | }}} | 
          
          
            |   | 24 | Returns a [switch, switchport] mapping for a node [x,y], or list of nodes x1,y1;x2,y2...: | 
          
          
            |   | 25 | {{{ | 
          
          
            |   | 26 | # ruby sample.rb  | 
          
          
            |   | 27 | enter node ID as "x1,y1; x2,y2;..." | 
          
          
            |   | 28 | enter "quit" to exit | 
          
          
            |   | 29 | 1,1 | 
          
          
            |   | 30 | [253, 32] | 
          
          
            |   | 31 | 1,2 | 
          
          
            |   | 32 | [8, 39] | 
          
          
            |   | 33 | 20,20;19,19 | 
          
          
            |   | 34 | [1, 2] | 
          
          
            |   | 35 | [1, 44] | 
          
          
            |   | 36 | quit | 
          
          
            |   | 37 | }}} | 
          
          
            |   | 38 | This functions assume underlying wires are there correctly, so it is not 100% accurate.  |