Octopress — adding category tags to the blog RSS feed

Right from the beginning, I’ve assigned broad categories to every post I’ve written here. (For example, this is my—very lacking—Health Monitoring series of posts.) However, Octopress does not include these category tags by default into the RSS feed. So if a reader is using an RSS feed-reader app or website, they cannot make use of the assigned categories even if the app or website was capable of doing so.

I’ve now added some code necessary to add the categories to the RSS feed, and this is what I did.

cellArray = {'Alpha','Beta','Gamma','Delta','GammaSquared'};
refString = 'Gamma';

At the outset, here is the code that I added:

{% for post in site.posts limit: 20 %}
<entry>
<!-- Other items that are included in the feed -->

{% capture catnum %}{{ post.categories | category_links | size }}{% endcapture %}
{% unless catnum == '0' %}
    <categories>
    {% for cct in post.categories %}
        {% assign idx=forloop.index0 %}<category>{{ post.categories[idx] }}</category>
    {% endfor %}
    </categories>
{% endunless %}

<!-- Other items that are included in the feed -->
<content type="html"><![CDATA[{{ post.content | expand_urls: site.url | cdata_escape }}]]></content>
</entry>

{% endfor %}

This code works great, but allow me to confess that I am not sure that this is the optimum implementation. To me this seems inelegant, but until I have a better solution, this performs the function appropriately and perfectly adequately.

I’ve only included the relevant portion and the context in which it must be inserted. (See the comment tags <!-- Other items that are included in the feed -->.)

The meat of the algorithm is from lines 7 through 11.

  • A <categories> tag is defined, and a for loop is executed over post.categories, which contains the list of categories for the post.
  • Within the for loop, each post category is enclosed in a <category></category> tag.

Now I had initially thought that the loop variable (cct here) would inherit sequentially the value of each category in post.categories, but apparently that does not work properly. Therefore, the workaround is to

  • identify the loop index (assign idx=forloop.index0) and
  • use individual values of the categories (post.categories[idx]).

We must use forloop.index0 and NOT forloop.index (both are valid commands; the index key starts numbering from 1) because the array numbering starts from 0, not 1.

OK, now that the meat of the algorithm is done, we must put in some code to handle the “unusual” cases—what happens if a post does not have any categories assigned? Such a scenario is handled by the capture command (line 5) and the unless segment that encloses our actual algorithm. The capture command simply captures a value, in our case the number of categories that exist. We only want to include the categories when they exist, therefore our algorithm is run only unless catnum=='0' i.e. when the number of categories is not 0.

Well, that’s it! I have added the code segment before the actual content of each post, but I don’t think it makes any difference if the segment appears after the <content> tag. It should work fine anywhere within the <entry> environment.


☛ Creating “Linked-List” type posts

One of my long-time to-do’s for this blog was to be able to create “linked-list” type posts, where the main heading points, not to a single webpage for the dedicated blog post, but to an external website of interest. (This type of post has been made famous by John Gruber, who is, incidentally, also the creator of the Markdown syntax.)

Well, now I know how to do this (evidence—this post! Ta-da! The title for this post points to The Candler Blog). It turns out it’s not too difficult, but even so, I had help all the way, from The Candler Blog. He has this same implementation, and it turns out, he also has a blog post dedicated to discussing how he did it!

Okay, so, “Daring Fireball-style Linked List posts,” for the uninitiated, refers to the publishing style of John Gruber’s Daring Fireball. For the most thorough explanation of how this works, see Shawn Blanc’s excellent 2009 article, “The Link Post” […]

But how is it done in Octopress? It’s actually very simple. I got a great deal of help, when I was first setting up the site, from Connor Montgomery, who posted his own link post tutorial a few weeks ago. I have since refined the code on my site beyond what we worked out together.

(The Candler Blog website seems otherwise very interesting as well. Go check it out!)


Of Cricket, Mankad-ing, and the Spirit of the Game

The Under-19 cricket world cup is on, and there has been a lot of controversy about a West Indies bowler running a Zimbabwean batsman out as he came in to bowl. Colloquially, this is called ‘Mankad’-ing, and some people view this form of dismissal as “not quite done”. As it happens every time, lots of people are talking about “spirit of the game” and “no warnings issued to the batsman”.

I think those people are in the wrong.

(Here’s the video.)

What would these same people say when a bowler gets a wicket, but his heel is found to be where the bat is spotted in our case? “Spirit of the game”, and give the batsman out? “Give a warning to the bowler”, and give the batsman out? No, of course not, because the rulebook says some part of the bowler’s foot must stay behind the line. The bowler made a mistake, and is penalized for it.

Well, guess what the rulebook says in this case.

Also, to be clear, backing up itself is not illegal; backing up too early is. ICC playing conditions says that the bowler may attempt this dismissal only if he has not completed his delivery swing. So, in effect, once the bowler is in the middle of rolling his bowling arm over to bowl, the bowler can no longer run the batsman out, and the batsman is free to start backing up.

In my opinion, “spirit of the game” issues should only come up when a) the fielding side resorts to subterfuge, or b) it is “obvious” that the batsman is not attempting to take an advantage, and is behaving as if the play is dead. For examples of this second case, see:

  • http://youtu.be/6zgvjC9WUCs (bad spirit of the game),
  • https://youtu.be/AsznuSW-1Ug (good spirit of the game) and
  • http://youtu.be/9vYPWYAoJhM (good spirit of the game, even though it was a close rescue).

In our present case, the batsman was definitely attempting to take advantage, and his opponent ran him out perfectly legally. The batsman made a mistake, and was penalized for it. What’s wrong with that, and what’s all this about giving the batsman a second chance?!

Play on, I say! (Or in this case, game over!)


On Failure in Metallic Materials

As a continuation of my series on composite materials and health monitoring, I wanted to talk about failure in composites. In writing it, I decided that first I needed to talk about failure in metallic materials. In writing that, it turned out that it was long enough to be a separate post by itself. So here it is, a small primer on failure, especially in metallic materials.

We’ll talk about composites next time.

What exactly is "failure"?

A component is said to have failed when it can no longer perform the task that it was designed for. Failure does not necessarily mean breaking, although sometimes it might. Failure in an engineering sense has as much to do with “what the designer intended” as with “the physical structure itself”.

For example, a bridge may be getting old and developing some cracks here and there. At what point do you say that the bridge is “unsafe for use”? The design and engineering teams set up some criteria to evaluate the structure. For example, they might say that “any cracks detected must not be greater than so-and-so length”. This does not mean that the bridge is going to break apart when a crack of that so-and-so length appears. It just means that the engineers are no longer satisfied with how the bridge may hold up in the future. Hence, the bridge component that developed the big-enough crack will be said to have failed.

Tacoma Narrows Bridge

Tacoma Narrows Bridge. (Source)

If the above paragraph seems to convey unnecessary caution on the part of the engineer (why call the bridge unsafe if it isn’t breaking up?), consider that a bunch of reasons go into making such decisions. As an example, the engineers may consider their ability to detect every crack. The engineering team may consider the possibility that they could not detect some defects. What is the probability of a serious defect not being detected?

And there’s good reason to be cautious – if they get it wrong, bridges do collapse.

How do metallic materials fail?

In the previous section, we have been talking about cracks. Here’s why they form in the first place. Cracks form when the load on a given region of a component (i.e. stress, = force per unit area) becomes higher than what the material can handle. This may be because an unexpected amount of load was put on the structure that it was never designed for. It may also be that the capacity of the structure to withstand stresses has diminished over time as the component has aged. In any case, when the stress is too much for the component to bear, the component fractures and develops a crack. The particular mechanics of the fracture itself is a vast area of study in itself, and is way beyond the scope of this piece. Suffice to say, that crack formation weakens the component, and the larger the crack gets, the worse in condition the component becomes. Ultimately, the crack will grow large enough that the component will break into two, and will be unable to take any load at all.

Crack propagation under fatigue loading

Crack propagation under certain conditions. (Source)

For metallic components, since the material itself is nominally homogenous (nominally, because nothing can be perfectly homogenous, but for all intents homogeneity may be assumed), the crack that ultimately causes the material to fail usually occurs where the stress happens to be the greatest. Further, as I mentioned above, the formation of a crack weakens the material, and so once a crack does form, any further worsening in that region accumulates around the same crack (weak zone) instead of creating new cracks all the time. “Where the stress is greatest” usually depends on the geometry of the component, on how the loads are distributed, and, indeed, on tiny variations in the homogeneity of the material itself.

Crack propagation in glass shot at extremely high frame rate. (Source)

For metals, therefore, the mantra for evaluating the component may be condensed as: “follow the cracks”. Wherever a crack seems to be worsening, is where final failure will most likely occur.

That’s it for today’s discussion on crack propagation; next time we’ll get to what I had actually set out to discuss – failure in composites.


On India’s World Cup performance (they lost today)

It’s always gutting to see your team lose, isn’t it. Gutting, and infuriating. “They should have won! If only they’d played better!”

Let’s think back though, to the beginning of the World Cup, before a ball had been bowled. Remember those days, just after the triseries with Australia and England? What if someone had said then that India would reach the semifinal? We’d have smirked. “With this team? This bowling attack?” Winning 7 games on the trot? Smirk. 70 wickets in 7 games? Best economy rate as a bowling unit? Cohesive batting performance from the entire unit? Fast bowlers bowling with pace and discipline? Smirk; smirk; smirk.

India have done well to reach the semifinals. They’ve been an excellent team. Their flaw today was that they were not a great team. But that’s okay, being excellent isn’t half bad.

Yes, they had a collective off-day. The bowlers sprayed it around a bit, uncharacteristically. The batters got out in inopportune moments, uncharacteristically. Dhawan usually scores big once he gets a start (and gets a catch dropped). Kohli usually gets himself in and ups his scoring rate, and doesn’t get out at all. There’s usually always Rahane, and even Raina has scored a hundred this world cup. Usually; just not today.

They came across a genuinely better team today, and lost. No shame in that; that takes nothing away from their excellence. Then too, they actually brought Australia back from what looked to be a certain 360+ score. That’s something in itself, no?

Also, a thought: how many teams have defended their world cup titles successfully? West Indies in the 1970s, and Australia in the 1990s and 2000s. It needs a great team, not merely an excellent one, to be able to defend trophies across four year periods and in different conditions. Would we call this Indian team “great”, comparable to the West Indian and Australian teams of before? Definitely not, right? Not yet. Maybe with time and more experience, and maybe a couple of different players, but certainly not yet.

So they came across a better team. They lost. So what? They played well until they lost; they played with pride and with skill and with passion and with excellence.

They kept the Tricolor flying high. Let’s be proud of that.