Will Jeff ever post an entry without bold?

I got a question from a co-worker about the easiest way in PowerShell to count the number of instances of a substring in a given string.

If you read FSJ you’ve probably read about how Walt MossGoatberg is infamous for posting with a ridiculous use of first-person pronouns.  I get the feeling that there’s a similar game to be found in the amount of bold tags used by Jeff Atwood. :)  I love his blog, but there certainly is a liberal use of bold tags. :)  They’ve got that whole implication of "I’m saying something profound here and you need to pay attention, mister!"

So, to put the two together, here’s a simple script that counts the number of times a substring occurs during the posts of a given RSS feed’s items.

param (
    [uri] $rssfeeduri = 'http://feeds.feedburner.com/codinghorror',
    [string] $substringToFind = '<b>'
)

$wc = New-Object system.Net.WebClient
[xml] $feed = $wc.DownloadString($rssfeeduri)
$feed.rss.channel.item |
    ft -a title,@{
        l="number of $substringToFind found"
        e={[regex]::Matches($_.description.psbase.innertext, $substringToFind, 'ignorecase').Count}
    }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

And the output on Jeff’s feed at the moment:

# .\get-countinrss.ps1

title                                                                 number of <b> found

—–                                                                 ——————-

Don’t Go Dark                                                                           6

ASCII Pronunciation Rules for Programmers                                              55

Markov and You                                                                          6

Exploring Wide Finder                                                                   6

Finally, a Definition of Programming I Can Actually Understand                          3

The Greatest Invention in Computer Science                                              4

Please Give Us Your Email Password                                                      7

Large USB Flash Drive Performance                                                       5

Whatever Happened to UI Consistency?                                                    4

Revisiting the Black Sunday Hack                                                        2

Strong Opinions, Weakly Held                                                            7

Designing For Evil                                                                      9

It’s Clay Shirky’s Internet, We Just Live In It                                         6

OpenID: Does The World Really Need Yet Another Username and Password?                  15

PHP Sucks, But It Doesn’t Matter                                                       10

Advertisements