Easy-Peasy Link Generator

[Update 2020-07-16: added some new logic to allow link target text to be provided on standard input. Prettified (slightly) the site-string chopping regex.]

First, a bit of background on my environment:

  • I use Google Chrome for my browser in Linux.

  • I use plain old vim in a terminal window to compose HTML for this blog.

  • And what I want to do all the time when composing HTML is to generate a link to the page displayed in the active tab in Chrome's current window.

For example, if I'm looking at this page in Chrome, I might say "Ooh, cool!" and want to insert the following into my HTML:

<a href="https://science.slashdot.org/story/20/07/01/1816253/a-massive-star-has-seemingly-vanished-from-space-with-no-explanation">A Massive Star Has Seemingly Vanished from Space With No Explanation</a>

That's not hard to do by hand: copy the link from Chrome into the terminal window, add in the surrounding code for the a tag, add the target text, don't forget the end tag (</a>), and we're done!

Yeah, it's not hard, but it can be tedious.

I'm sure people—much smarter people—have come up with good solutions for this. But I'm a DIY kind of guy. So eventually (it only took years), I wrote this small (43 68-line) Perl script to do that for me. For historical reasons (by which I mean: arbitrary and silly reasons), I named it ttb. Which stands for "Thing To Blog", and it's installed in my $HOME/bin directory.

My usual use is in vim command mode, bang-bang-ttb:

!!ttb

… which will replace the current line with the HTML link:

<a href="URL">target</a>

where URL is (duh) the URL of the active tab of Chrome's current window.

The target link text is determined by the following logic:

  • If the current line contains any (non-whitespace) text, use that for the target text. (After trimming any leading or trailing whitespace.)
  • Otherwise, if any command-line arguments are specified, join them together with spaces, using the result as the target text.
  • Otherwise, use the HTML title of the displayed page as the target text.

That might look a bit convoluted, but… well, it is. But it works OK for me.

Notes:

  • The script assumes you have installed the chromix-too Chrome extension package. Which is easy enough to get. In Fedora, I install the npm package first:

    # dnf install npm

    or equivalent sudo if you prefer that. Then:

    # npm install -g chromix-too

    This package contains a client-server pair: chromix-too and chromix-too-server. The server can be run after Chrome itself starts up. (I run both Chrome and chromix-too-server as startup commands.)

  • The script executes the client via the shell command:

    $ chromix-too raw chrome.tabs.query '{ "active":true, "currentWindow":true }'

    which produces JSON output about the active tab in the current window. The JSON perl module (I think it's installed by default in Fedora) is required to decode that into a Perl structure. The decode function returns an "array of hash", but I think the array should always have just one element, so we just pop that.

  • Ugly things probably happen if you run this without the browser or the chromix server running. I should probably provide a clean exit in that case.

  • I noticed a lot of sites (mostly blogs) have HTML page titles that append a uniform site string. There's an ugly ad hoc regex in the code to chop those off. (Or should that be ad hack?)

That's a dreadful lot of verbiage about such a short script. As usual, this is not earth-shattering code, but I hope someone finds it useful, if only for tutorial purposes.

And if you know of a better way to do this… don't tell me, OK?

The source may be found at GitHub.


Last Modified 2020-07-16 6:02 AM EDT

URLs du Jour

2020-07-01

[Amazon Link]
(paid link)

  • Our Amazon Product du Jour is yet another book pushed by the Church of Holy Wokeness. (The University Near Here, for example, plugs it here and here.) A New Yorker review by Kelefa Sanneh attempts to make sense out of it (and also White Fragility, which we looked at a couple days ago): The Fight to Redefine Racism.

    Sixteen years ago, in 2003, the student newspaper at Florida Agricultural and Mechanical University, a historically black institution in Tallahassee, published a lively column about white people. “I don’t hate whites,” the author, a senior named Ibram Rogers, wrote. “How can you hate a group of people for being who they are?” He explained that “Europeans” had been “socialized to be aggressive people,” and “raised to be racist.” His theory was that white people were fending off racial extinction, using “psychological brainwashing” and “the AIDS virus.” Perhaps the most incendiary line appeared at the end, after the author’s byline and e-mail address: “Ibram Rogers’ column will appear every Wednesday.”

    Well, that didn't work out. Later, after a name change from "Rogers" to "Kendi":

    In the thirteen years since his abortive college-newspaper column, Kendi had become ever more convinced that racism, not race, was the central force in American history, and so he reached back to 1635 to show how malleable racism could be. The preachers who justified slavery used racist arguments, he wrote, but so did many of the abolitionists—the ubiquity of racism meant that no one was immune to its seductive power, including black people. In his view, the pioneering black sociologist W. E. B. Du Bois was propping up racist ideas in 1897, when he condemned “the immorality, crime, and laziness among the Negroes.” So, too, was Barack Obama, when, as a Presidential candidate in 2008, he decried “the erosion of black families.” Although Obama noted that this erosion was partly due to “a lack of economic opportunity,” he also made an appeal to black self-reliance, saying that members of the African-American community needed to face “our own complicity in our condition.” Kendi saw statements like these as reflections of a persistent but delusional idea that something is wrong with black people. The only thing wrong, he maintained, was racism, and the country’s failure to confront and defeat it.

    If Du Bois and Obama are considered racists, then we got a problem.

    The problem with "redefining racism" is (at least) twofold:

    1. It's not as if the term hadn't been already been pounded into vague meaninglessness. People wanted to maintain its (deserved) opprobrium while (um) broadening to encompass … well, whatever was found problematic. To the point it became what Orwell said about the term "fascism": it "has now no meaning except in so far as it signifies ‘something not desirable’."
    2. And if you "redefine racism", we're gonna need a new word for "invidious stereotyping based on skin color".

    So I can't recommend that you buy Kendi's book, but if you do, I'd be happy if you used the link.


  • P. J. O'Rourke writes at American Consequences: Killing time, part II. What's Peej been up to?

    So I still have a lot of time on my hands. One thing I’ve been doing is reading books, in particular books about people who had it worse than we’re having it… (spoiler alert!)

    • Edgar Allan Poe’s The Masque of the Red Death – Everybody dies at the end.
    • Nevil Shute’s On the Beach – Everybody dies at the end.
    • Kurt Vonnegut’s Cat’s Cradle – Everybody dies at the end.
    • The Book of Revelation in the Bible – Everybody dies in the end unless they’ve been very, very good. And we haven’t.

    I’ve let my wife cajole me into doing yoga. To make this less embarrassing – and because my “Mountain Pose” was more like a “Molehill Pose” – I’ve been renaming the yoga poses. So far, I’ve changed “Cobra Pose” to “Run Over by a Car Pose,” “Child’s Pose” to “Peevish Brat Pose,” “Warrior Pose” to “Teargassed Fleeing Protestor Pose,” “Corpse Pose” to “Snoring on the Yoga Mat Pose,” and let’s not even go there with “Downward Doggy-Style Pose.”

    You'll also want to check his suggestions for moderating one's alcohol consumption: "gag-a-cat cocktails".


  • [Amazon Link]
    (paid link)
    Quillette is still a free-speech zone, so Michael Shellenberger found an outlet for his mea culpa: On Behalf Of Environmentalists, I Apologize For The Climate Scare. Let's skip down to his list of "facts few people know":

    • Humans are not causing a “sixth mass extinction”

    • The Amazon is not “the lungs of the world”

    • Climate change is not making natural disasters worse

    • Fires have declined 25 percent around the world since 2003

    • The amount of land we use for meat—humankind’s biggest use of land—has declined by an area nearly as large as Alaska

    • The build-up of wood fuel and more houses near forests, not climate change, explain why there are more, and more dangerous, fires in Australia and California

    • Carbon emissions are declining in most rich nations and have been declining in Britain, Germany, and France since the mid-1970s

    • The Netherlands became rich, not poor while adapting to life below sea level

    • We produce 25 percent more food than we need and food surpluses will continue to rise as the world gets hotter

    • Habitat loss and the direct killing of wild animals are bigger threats to species than climate change

    • Wood fuel is far worse for people and wildlife than fossil fuels

    • Preventing future pandemics requires more not less “industrial” agriculture

    Interesting note: Forbes apparently published Shellenberger's article on their website, then yanked it. Et tu, Forbes?

    Shellenberger has a book out, Amazon link up there on the right, it's on my get-at-library list.


  • A bold suggestion from David Harsanyi at National Review (NRPLUS, sorry): Honor Warren G. Harding over Woodrow Wilson

    Princeton University has announced that it plans to remove the name of former president Woodrow Wilson from its public policy school because of his segregationist views. Other institutions with Wilson’s name will likely be pressured to follow suit.

    Good riddance, Woodrow. Wilson was one of the most despicable characters in 20th-century American politics: a national embarrassment. The Virginian didn’t merely hold racist “views;” he re-segregated the federal civil service. He didn’t merely involve the United States in a disastrous war in Europe after promising not to do so; he threw political opponents and anti-war activists into prison. Wilson, the first president to show open contempt for the Constitution and the Founding, was a vainglorious man unworthy of honor.

    Fortunately, we have the perfect replacement for Wilson: Warren Harding, the most underappreciated president in American history, a joyful champion of civil rights and republicanism. Harding deserves to be reinserted into the nation’s consciousness on the merits of his presidency alone. But considering that he also negated much of Wilson’s calamitous legacy, we have an even better reason to honor him.

    Harding was imperfect, but does not deserve the bad rap he received from history.


  • And our Google LFOD alert, rang for a recent op-ed from Rabbi Brad Bloom of Hilton Head Island, published in the Island Packet: Beaufort County leaders have moral, faith-based duty to protect public today. He relates a traumatic experience:

    I recently saw a car from New Hampshire with the state’s motto “Live Free or Die.” Frankly I took a step back for a second and felt a chill down my back just gazing at that plate.

    Unfortunately, the chill Rabbi Bloom felt was not a favorable reaction to a saying in favor of sweet freedom, but instead the dread worry that people deluded by such libertarian slogans might not adequately mask up.

    Hilton Head is in South Carolina, whose motto is "Dum Spero Spiro", meaning 'While I breathe, I hope'. ("And when I don't breathe, it's probably because I died from Covid-19, thanks to some unmasked LFOD guy.")

    On June 29, South Carolina reported 1324 new cases of Covid-19.

    In comparison, New Hampshire—which is full of LFOD plates, Rabbi—reported 13 new cases.


Last Modified 2024-06-03 6:36 AM EDT

Confessions of an Innocent Man

[Amazon Link]
(paid link)

This is another book off WSJ reviewer Tom Nolan's Best Mystery Books of 2019 list. Six down, four to go.

Tom has a pretty broad definition of "mystery". There's a negligible amount of whodunit content here. But that's OK. It's a page-turner.

Right from page one, we learn that the first-person narrator, Rafael Zhettah, is keeping a couple of people, Sarah and Leonard, locked up. A countdown timer shows how much time is left on their "sentence" (initially 2,444 days). Rafael provides them a TV (stuck on CNN, 16 hours/day, now that's cruel and unusual punishment). And he addresses them as "your honors". Hm.

How did that happen? We find out eventually. Pre-kidnapping, Rafael was on death row, convicted of the brutal murder of his billionaire wife. He's innocent (see the title), but thanks to a lazy investigation, zealous prosecution, and a weak alibi… sorry, Rafael, get ready for your Pentobarbital injection.

Given the prologue, we know that Rafael gets out, and (somehow) decides to exact revenge on Sarah and Leonard, and the path is a twisty one.

The author, David R. Dow, is an active opponent of the death penalty, founder and director of the Texas Innocence Network. So there's some advocacy here mixed in with the plot. Depending on your own feelings about capital punishment, you can either roll your eyes or punch the air in agreement.

As said, the book's a page-turner, but strains credulity at times. The biggest disbelief-suspending hurdle for me: Rafael just happens to own a bit of Kansas property that has an unusual plot-critical feature, undisclosed until page 167. No spoilers here, but geez, I said, isn't that convenient?


Last Modified 2024-01-23 2:06 PM EDT