snippets / dgn110 / 

All dgn110's snippets (2)

  1. breadth first tree search

    Scans the test report repository for test report subfolders returning the full path to each subfolder.

     1 # performs breadth first search of test report repository
    2 # collects all subdirectories that match the test report naming pattern
    3 REPORT_REPOSITORY = '//Amco-design/Design2/Root/Reports_Test'
    4
    5 # setup initial search parameters
    6 queue = [REPORT_REPOSITORY]
    7 found = []
    8
    9 # BFS tree parsing algorithm
    10 while queue.length > 0 do
    11 directory = queue.pop
    12
    13 # need to change working directory for File.directory?() to work correctly
    14 Dir.chdir(directory)
    15
    16 cache = Dir.entries(directory).select do |subdirectory|
    17 case subdirectory
    18 when '.' then false
    19 when '..' then false
    20 else File.directory?(subdirectory)
    21 end
    22 end
    23
    24 cache.each do |subdirectory|
    25 case subdirectory
    26 when /^TR-\d\d\d\d-\d\d/
    27 found << File.join(directory,subdirectory)
    28 when /^TRS-\d\d\d\d-\d\d/
    29 found << File.join(directory,subdirectory)
    30 when /^ER-\d\d\d\d-\d\d/
    31 found << File.join(directory,subdirectory)
    32 else
    33 queue << File.join(directory,subdirectory)
    34 end
    35 end
    36 end
    37
    38 # XXX debug code
    39 found.each {|entry| puts entry}
    first posted by dgn110 to ruby work algorithm ... saved by 1 person ... 0 comments ... 1 year
  2. xhtml strict erb template

    simple xhtml template for erb

     1 template = [
    2 '<!DOCTYPE html',
    3 'PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN"',
    4 'http://www.w3.org/TRxhtml1/DTD/xhtml1-strict.dtd">',
    5 '<html>',
    6 "<head>",
    7 "<title><%= html_title %></title>",
    8 "</head>",
    9 "<body>",
    10 "<%= html_body %>",
    11 "</body>",
    12 "</html>"
    13 ]
    14
    15 template = ERB.new( template.join("\n") )
    first posted by dgn110 to ruby ruby xhtml ... saved by 1 person ... 0 comments ... 1 year
showing 10, 25, 50 items per pages

Pages : 1