del.icio.us/dossy links since June 19, 2006 at 09:00 AM

del.icio.us/dossy (RSS) links since June 19, 2006 at 09:00 AM:

Normalize ISO-8859-1 to ASCII in Tcl

A co-worker, John, asked me, “How do I normalize ISO-8859-1 encoded text to ASCII in Tcl?” From the command line, you might use GNU recode like this:

$ echo "Mötley Crüe" | recode -f L1..BS | sed -e 's/.\x08//g'
Motley Crue

Fortunately, recode supports dumping a conversion table, but it currently only knows C and Perl. After a little post-processing of the output, I generated this:

set ::ISO_8859_1_to_ASCII [list \
    "" "\001" "\002" "\003" "\004" "\005" "\006" "\007" "\010" "\011" \
    "\012" "\013" "\014" "\015" "\016" "\017" "\020" "\021" "\022" "\023" \
    "\024" "\025" "\026" "\027" "\030" "\031" "\032" "\033" "\034" "\035" \
    "\036" "\037" " " "!" "\"" "#" "\$" "%" "&" "'" "(" ")" "*" "+" "," \
    "-" "." "/" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" ":" ";" "<" "=" \
    ">" "?" "@" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" \
    "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "\[" "\\" "]" "^" "_" \
    "`" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" \
    "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "{" "|" "}" "~" "\177" "" \
    "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" \
    "" "" "" "" "" "" "" "" " " "" "" "" "" "" "" "" "" "" "" "\"" "" "" \
    "" "" "" "" "" "" "" "" "" "" "" "" "" "\"" "" "" "" "" "A" "A" "A" \
    "A" "A" "" "" "C" "E" "E" "E" "E" "I" "I" "I" "I" "" "N" "O" "O" "O" \
    "O" "O" "" "O" "U" "U" "U" "U" "Y" "" "s" "a" "a" "a" "a" "a" "" "" \
    "c" "e" "e" "e" "e" "i" "i" "i" "i" "" "n" "o" "o" "o" "o" "o" "" "o" \
    "u" "u" "u" "u" "y" "" "y" \
]

proc ISO_8859_1_to_ASCII {in} {
    global ISO_8859_1_to_ASCII
    set out {}
    foreach c [split $in ""] {
        append out [lindex $ISO_8859_1_to_ASCII [scan $c "%c"]]
    }
    return $out
}

With this code, you can use it like this, from within your Tcl script where you’ve sourced this code in:

% ISO_8859_1_to_ASCII "Mötley Crüe"
Motley Crue

I hope this helps others, too.

Tags:
,
,
,
,

del.icio.us/dossy links since June 12, 2006 at 09:00 AM

del.icio.us/dossy (RSS) links since June 12, 2006 at 09:00 AM:

del.icio.us/dossy links since June 5, 2006 at 09:00 AM

del.icio.us/dossy (RSS) links since June 5, 2006 at 09:00 AM:

Is there any hope for a Silicon Alley?

A couple of months ago, Holly and I were talking about Silicon Valley and wondering if the same phenomenon could be reproduced elsewhere–specifically, in New York, because I really don’t want to leave New Jersey. I really didn’t have many good answers, but a few days ago, Guy Kawasaki gave an excellent answer: How to Kick Silicon Valley’s Butt.

The entire entry is worth reading, but I just wanted to take a quote completely out of context because I still can’t stop smiling when I read it:

“[…] if you want to cover your ass, you need to open your kimono […]”

The depressing part of reading Guy’s blog entry is, if he’s right and I suspect he is, it’s not very likely that there’ll be another “Silicon Valley” elsewhere because the preconditions just aren’t there. Yet.

Tags:
,
,

Stephen Colbert and more great commencement speeches of 2006

It’s June again, which means graduation time, which means commencement speeches! This year, Stephen Colbert gave a great commencement speech at Knox College on June 3, 2006 (via John Scalzi). The money shot of his speech is about learning to say “yes-and” instead of “no-but”. This is incredibly valuable advice.

In case you’re asking “who’s Stephen Colbert,” he’s most recently generated buzz around his 2006 White House Correspondents Dinner speech (Transcript, Google Video).

If you want to see more, here are some great commencement speeches from 2005.

Tags:
,
,

How to parse “show flow monitor-map” output with Tcl

I’m the organizer of a few Meetups, most successful so far is the MySQL Meetup. However, I also started a Tcl Meetup and today, a new member, Maryam (or “Moryam”) joined and sent me a message asking a Tcl question. I decided to answer it on my blog, so others could see the answer.

Her question is: How can I parse the output of “show flow monitor-map” from Cisco IOS into a “keyed list” (or Tcl array)?

Here is what she sent me as sample input and desired sample output:

RP/0/RP1/CPU0:irace-netflow-r1#show flow monitor-map

Flow Monitor Map : fmm1
-------------------------------------------------
Id: 1
RecordMapName: ipv4-raw
ExportMapName: fem1
CacheAgingMode: Normal
CacheMaxEntries: 65535
CacheActiveTout: 1800 seconds
CacheInactiveTout: 15 seconds
CacheUpdateTout: N/A

flowMonitorMap {
    {identifier fmm1}
    {id 1}
    {recordMapName ipv4-raw}
    {exportMapName fem1}
    {cacheAgingMode Normal}
    { cacheMaxEntries 65535}
    {cacheActiveTout 1800}
    { cacheActiveToutUnit Seconds}
    {cacheInactiveTout 15}
    {cacheInactiveToutUnit Seconds}
    {cacheUpdateTout N/A}
}

I’m going to assume that all the network I/O required (probably using something like Expect to automate that task) has already been implemented. For the sake of the code example, I’m putting the output of the “show flow monitor-map” into the variable $input. The result of the parsing will go into a Tcl array, which is an unordered set of key-value pairs. Here is the code:

##
## Set input data.
##

set input {Flow Monitor Map : fmm1
-------------------------------------------------
Id: 1
RecordMapName: ipv4-raw
ExportMapName: fem1
CacheAgingMode: Normal
CacheMaxEntries: 65535
CacheActiveTout: 1800 seconds
CacheInactiveTout: 15 seconds
CacheUpdateTout: N/A}

##
## Initialize output array
##

array unset output
array set output {}

##
## Parse input data, populate output array.
##

foreach line [split $input "\n"] {
    if {[regexp {^([^:]+?)\s*:\s*(\S+)\s*(\S+)?$} $line -> key value units]} {
        if {$key eq "Flow Monitor Map"} {
            set key "identifier"
        }
        set key [string tolower $key 0 0]
        set output($key) $value
        if {[string length $units]} {
            set output(${key}Unit) $units
        }
    }
}

##
## Optional: Display the output.
##

foreach {key value} [array get output] {
    puts [list $key $value]
}

Running this Tcl script produces this output:

cacheActiveToutUnit seconds
cacheActiveTout 1800
cacheMaxEntries 65535
exportMapName fem1
id 1
recordMapName ipv4-raw
cacheUpdateTout N/A
cacheInactiveToutUnit seconds
cacheInactiveTout 15
cacheAgingMode Normal
identifier fmm1

Remember, Tcl arrays are unordered lists, which is why the key-value pairs printed come back in a different order than they were put in. If you need them ordered, you’ll have to specify the ordering, perhaps like this:

foreach key {identifier id recordMapName exportMapName cacheAgingMode
        cacheMaxEntries cacheActiveTout cacheActiveToutUnit
        cacheInactiveTout cacheInactiveToutUnit
        cacheUpdateTout cacheUpdateToutUnit} {
    if {[info exists output($key)]} {
        puts [list $key $output($key)]
    }
}

This will produce the following output:

identifier fmm1
id 1
recordMapName ipv4-raw
exportMapName fem1
cacheAgingMode Normal
cacheMaxEntries 65535
cacheActiveTout 1800
cacheActiveToutUnit seconds
cacheInactiveTout 15
cacheInactiveToutUnit seconds
cacheUpdateTout N/A

Maryam, I hope this helps answer your question, as well as anyone else who’s looking to accomplish a similar task. Have questions or comments about the code? Leave them in the comments section below!

Tags:
,
,
,
,
,
,

del.icio.us/dossy links since May 29, 2006 at 09:00 AM

del.icio.us/dossy (RSS) links since May 29, 2006 at 09:00 AM:

Dossy’s hCard, if you care about microformats

Since Tantek Çelik announced in his blog, Technorati now has a Microformats Search in their Kitchen (beta). Just in case this actually takes off, I figured I’d throw my publically available contact information out in hCard microformat. Here it is:

Nothing really exciting (that’s almost the point) but it’ll be interesting to see where this information will surface, now that it’s more easily machine-readable.

It’ll also be fun exercise to create a web spam bot that creates a bunch of seemingly real but completly fabricated microcontent out there. Without the necessary licensing, Technorati can’t use Google’s patented PageRank process to use links-to-microcontent to determine authoritativeness or relevancy, can it? Just look at the spam blogs now and how it’s ruining blog searches. Spam microcontent won’t be far behind, if microcontent search becomes a reality.

Tags:
(),
,
,
,

Pragmatic Party and Scott Adams in 2008

I’ve said it before that I think Scott Adams should run for President in 2008, but today he cemented it. He blogged about his Pragmatic Party fantasy, imagining and describing his campaign platform, his Presidential approach and other goodness.

You need one Big Idea when you run for President. I would explain that our current system of government was conceived prior to the Internet, electronic mass media, and sophisticated polling methods. 200 years ago the only practical form of government involved voting for a small group of individuals that would pretend to represent you. Now we have better tools and we should use them. […]

I’m eligible to, but have never voted in any US government election. But, I might seriously consider Scott Adams and the Pragmatic Party as a write-in for 2008.

Exactly what does it take to get officially listed on the ballot? How much funds need to be raised? What’s the process involved? This is serious. If Ronald Reagan could see two full terms as President and Arnold Schwarzenegger can be Governor of California, then Scott Adams can certainly be President for a term.

Lets make this happen, people!

Tags: , , ,